diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-06 22:29:58 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-06 22:29:58 -0400 |
commit | eb261daff5e9a96f294cd806d1fd3e68f06fdbaa (patch) | |
tree | 5f4d05861ac492c52a9f6a0781c69e90be73b60c /awk.h | |
parent | ce342a04922797cb53557178c54d32c4efafda16 (diff) | |
download | egawk-eb261daff5e9a96f294cd806d1fd3e68f06fdbaa.tar.gz egawk-eb261daff5e9a96f294cd806d1fd3e68f06fdbaa.tar.bz2 egawk-eb261daff5e9a96f294cd806d1fd3e68f06fdbaa.zip |
Modify MAYBE_NUM usage and typeof function to return "strnum" only for actual numeric strings.
Diffstat (limited to 'awk.h')
-rw-r--r-- | awk.h | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -406,14 +406,16 @@ typedef struct exp_node { * b = a + 0 # Adds NUMCUR to a, since numeric value * # is now available. But the type hasn't changed! * - * MAYBE_NUM is the joker. It means "this is string data, but - * the user may have really wanted it to be a number. If we have - * to guess, like in a comparison, turn it into a number if the string - * is indeed numeric." + * MAYBE_NUM is the joker. When STRING|MAYBE_NUM is set, it means + * "this is string data, but the user may have really wanted it to be a + * number. If we have to guess, like in a comparison, turn it into a + * number if the string is indeed numeric." * For example, gawk -v a=42 .... * Here, `a' gets STRING|STRCUR|MAYBE_NUM and then when used where * a number is needed, it gets turned into a NUMBER and STRING - * is cleared. + * is cleared. In that case, we leave the MAYBE_NUM in place, so + * the combination NUMBER|MAYBE_NUM means it is a strnum a.k.a. a + * "numeric string". * * WSTRCUR is for efficiency. If in a multibyte locale, and we * need to do something character based (substr, length, etc.) @@ -1865,7 +1867,7 @@ fixtype(NODE *n) { assert(n->type == Node_val || n->type == Node_typedregex); if (n->type == Node_val) { - if ((n->flags & MAYBE_NUM) != 0) + if ((n->flags & (NUMCUR|MAYBE_NUM)) == MAYBE_NUM) return force_number(n); if ((n->flags & INTIND) != 0) return force_string(n); |