Fix T47661: cm (centimeter) unit breaks m (meter) unit in Metric.

`m` unit when used after `cm`/`mm`/etc. ones would get ignored, and the alt version of miles
would be used instead.

The root of the issue is that, in `unit_find_str`, once we get a 'hit' for a unit, we check
it's actual unit (since 'm' would also hit on 'cm', 'mm', etc.). In case that hit is not a
valid unit one, we would just return NULL, breaking the cycle of checks over that unit, and
hence missing all later usages of it.

So now, in case we have an 'invalid unit hit', we immediately retry to find it within remaining string.
This commit is contained in:
Bastien Montagne 2016-03-02 17:57:03 +01:00
parent bee0a7587b
commit 9c0de0084b

@ -460,12 +460,12 @@ BLI_INLINE bool isalpha_or_utf8(const int ch)
static const char *unit_find_str(const char *str, const char *substr)
{
const char *str_found;
if (substr && substr[0] != '\0') {
str_found = strstr(str, substr);
while (true) {
const char *str_found = strstr(str, substr);
if (str_found) {
/* previous char cannot be a letter */
/* Previous char cannot be a letter. */
if (str_found == str ||
/* weak unicode support!, so "µm" won't match up be replaced by "m"
* since non ascii utf8 values will NEVER return true */
@ -478,11 +478,15 @@ static const char *unit_find_str(const char *str, const char *substr)
return str_found;
}
}
/* If str_found is not a valid unit, we have to check further in the string... */
str = str_found + 1;
}
else {
break;
}
}
}
return NULL;
}
/* Note that numbers are added within brackets