Ignoring issues of correctness and some of the other things that the other answers have gone into detail on, and instead focusing on simple program transformations (transforming the program into an equivalent program):
It is worth pointing out that whenever you have
if (c) {
return true;
} else {
return false;
}
you can just replace that with
return c;
Also, the continue;
is unnecessary since there is nothing outside of those if
s. You could make that if
body empty (if you wanted to keep that structure). This would make it (note: I would not recommend actually using code with an empty if
body, this is just a step in the larger transformation I'm suggesting):
if (inputString[i] == inputString[point_end]) {
} else {
return i == num_to_parse;
}
From there, you could just change the loop to (fixing the conditional a bit, to what I suspect your intent was)
for (int i=0; i<num_to_parse; i++) {
if (inputString[i] != inputString[point_end]) {
return i == num_to_parse;
}
}
This reveals an unnecessary computation, now the conditional in the return
can never be true
, because the loop will end before i == num_to_parse
. Now this can be changed to:
for (int i=0; i<num_to_parse; i++) {
if (inputString[i] != inputString[point_end]) {
return false;
}
}
Again, this won't fix the issues of correctness since, other than my changing the conditional, none of the transformations changed the meaning of the program (as is usually the intent of program transformation). This was, however, addressed in the other answers.
This might better illuminate problems with correctness though, now that the code is simplified.
Also, on a somewhat unrelated subject: I'm not sure that I would describe this as "close to the metal." It definitely requires an operating system and it uses high-level constructs like std::string
. This is not to say that it is bad, but I would not describe it as "close to the metal."