Hi, I am currently writing a library for dynamic use, and in it I have some string functions.
This particular one returns a substring of a given string from the rightmost, determined by a given count.
I just get the feeling that I'm missing some error checking and would like to hear any comments or tips if you have the time.
unsigned int __stdcall sRightmost(char * source, unsigned int len, unsigned int count, char * buffer){
//convert to string
std::string String(source);
//check input is not empty
if (String == "") {
return 0;
}
//get length once only
unsigned int slen = String.length();
//check count is < len
if (count > slen) {
return 0;
}
//get required substring
std::string right = String.substr(slen - count);
//copy substring to buffer
strcpy_s(buffer, len, right.c_str());
return slen;
}