diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-29 13:19:10 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-29 13:19:10 +0300 |
commit | ba1e7ab66563efb5b597a418e2e9fb4a01998d03 (patch) | |
tree | a9cf2a74f9fd34725a507a3b9cef8bd1566a1664 /awklib/eg/lib/strtonum.awk | |
parent | 5a05ddf24b9f5ebc81a1b295ba7a6fbc7348776b (diff) | |
parent | 6c541fd0f75cd328dd80afec757ecccc833719af (diff) | |
download | egawk-ba1e7ab66563efb5b597a418e2e9fb4a01998d03.tar.gz egawk-ba1e7ab66563efb5b597a418e2e9fb4a01998d03.tar.bz2 egawk-ba1e7ab66563efb5b597a418e2e9fb4a01998d03.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'awklib/eg/lib/strtonum.awk')
-rw-r--r-- | awklib/eg/lib/strtonum.awk | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/awklib/eg/lib/strtonum.awk b/awklib/eg/lib/strtonum.awk index 9342e789..5e20626b 100644 --- a/awklib/eg/lib/strtonum.awk +++ b/awklib/eg/lib/strtonum.awk @@ -13,8 +13,9 @@ function mystrtonum(str, ret, n, i, k, c) ret = 0 for (i = 1; i <= n; i++) { c = substr(str, i, 1) - if ((k = index("01234567", c)) > 0) - k-- # adjust for 1-basing in awk + # index() returns 0 if c not in string, + # includes c == "0" + k = index("1234567", c) ret = ret * 8 + k } @@ -26,6 +27,8 @@ function mystrtonum(str, ret, n, i, k, c) for (i = 1; i <= n; i++) { c = substr(str, i, 1) c = tolower(c) + # index() returns 0 if c not in string, + # includes c == "0" k = index("123456789abcdef", c) ret = ret * 16 + k |