Not sure if you are joking, or looking for a serious answer. The code you posted makes WAY too many passes through the source string. If you're looking for maximum performance, you can get this down to just a single pass thusly:
LPSTR* nxt = wName;
// find 1st non-whitespace char
while(*nxt && isspace(*nxt))
nxt++;
// if nothing but whitespace
if (!*np) {
wName = '\0';
return wName;
}
// save position of 1st non-whitespace
LPSTR* start = nxt;
// now find last non-whitespace character
// before end of line
LPSTR* last_no_ws = nxt;
while(*nxt) {
if (!isspace(*nxt))
last_no_ws = nxt;
nxt++;
}
// how long is our non-whitespace string?
int len = (last_no_ws - start) + 1;
// move the string to beginning of wName
memmove(wName, start, len);
wName[len] = '\0';
return wName;
You could even save the 'memove' at the end by just modifying the wName string in place (add null after last_no_ws), then return the reference to 'start'. :)