Suppose I have very long strings and I want to see if a column is allLower, allUpper, or mixedCase. For example with the following column
text
"hello"
"New"
"items"
"iTem12"
"-3nXy"
The text would be mixedCase. A naive algorithm to determine this might be:
int is_mixed_case, is_all_lower, is_all_upper;
int has_lower = 0;
int has_upper = 0;
// for each row...for each column...
for (int i = 0; (c=s[i]) != '\0'; i++) {
if (c >='a' && c <= 'z') {
has_lower = 1;
if (has_upper) break;
}
else if (c >='A' && c <= 'Z') {
has_upper = 1;
if (has_lower) break;
}
}
is_all_lower = has_lower && !has_upper;
is_all_upper = has_upper && !has_lower;
is_mixed_case = has_lower && has_upper;
I'm sure there would be a more performant way to do this, however. What might be the most efficient way to do this algorithm/calculation?