I'm confused about what you are disagreeing with.
Are you saying that this...
if(name == "person mcperson" || name == "Person Mcperson" || name == "Person McPerson"
|| name == "PERSON MCPERSON" || name == "person MCPERSON" || name == "PERSON mcperson" || ...etc... )
{
//...
}
...is better than this:
std::string name = "Person McPerson";
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if(name == "person mcperson")
{
//...
}
Or are you just saying to cache the lowercase name when possible, so you don't have to convert it every function call?
Neither, but it appears you're likely got things in reverse.
What I'm saying is that the whole notion of string (upprer/lower case) permutations is flat out
insane.The difference is conceptual, even before we start thinking about comparing strings, so many things have gone wrong I can hardly believe.
- there should be input sanitization forcing a coherent format... but let this pass.
- everyone thinking about storing or even computing those permutations is on the wrong track: this is clearly not the way to do things (very special bonus for elaborations about working on strings loaded from a file you know nothing about!). But what the heck, let this pass as well.
- everyone saying that toupper is to be used "to save space" is not saying it as (s)he should. What (s)he should say is "you have to use the proper function becouse everything else is flat out broken and if you have come so far you're really better take a step back and rethink everything you have done so far"!
Original OP question is: why my string comparisons do fail? Because of operator precedence and syntax rules.
But the problem he is having, behind the scenes is he does not understand the basic of string comparisons in this specific context (as much as having two variables [font=courier new,courier,monospace]varx[/font] and [font=courier new,courier,monospace]VARX [/font]might make sense, I hardly believe the difference between
Person McSurname and
Person MCSurname is meaningful in most cases).
All posts regarding permutations are
madness. And should be eradicated. Some people reading this might actually believe working with the permutation is somewhat ... maybe encouraged? Think of the children!
If a string is so important permutations have to be checked... it probably is not a string!
I don't know if I'm being able to explain myself.