I agree that it is not doable with macros, however, I found a trick using compiler optimizations.
The result is that the expression JL_SvnRevToInt("$Revision: 12345 $") is reduced to a single unsigned integer: 12345
inline unsigned int JL_SvnRevToInt(const char *r) {
if ( r == NULL || r[0] == '\0' || r[10] == '\0' || r[11] == '\0' || r[12] == '\0' || r[13] == '\0' )
return 0;
const unsigned int count =
r[11] == ' ' ? 1
: r[12] == ' ' ? 10
: r[13] == ' ' ? 100
: r[14] == ' ' ? 1000
: r[15] == ' ' ? 10000
: r[16] == ' ' ? 100000
: r[17] == ' ' ? 1000000
: r[18] == ' ' ? 10000000
: r[19] == ' ' ? 100000000
: 0;
return
(r[11] == ' ' ? 0 : (r[11]-'0') * (count/10) +
(r[12] == ' ' ? 0 : (r[12]-'0') * (count/100) +
(r[13] == ' ' ? 0 : (r[13]-'0') * (count/1000) +
(r[14] == ' ' ? 0 : (r[14]-'0') * (count/10000) +
(r[15] == ' ' ? 0 : (r[15]-'0') * (count/100000) +
(r[16] == ' ' ? 0 : (r[16]-'0') * (count/1000000) +
(r[17] == ' ' ? 0 : (r[17]-'0') * (count/10000000) +
(r[18] == ' ' ? 0 : (r[18]-'0') * (count/100000000) +
(r[19] == ' ' ? 0 : (r[19]-'0') * (count/1000000000) +
0)))))))));
}
It supports9 digits revision number, NULL and empty and "$Revision$" strings.