aboutsummaryrefslogtreecommitdiffstats
path: root/awklib/eg/lib/strtonum.awk
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-08-29 13:19:10 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-08-29 13:19:10 +0300
commitba1e7ab66563efb5b597a418e2e9fb4a01998d03 (patch)
treea9cf2a74f9fd34725a507a3b9cef8bd1566a1664 /awklib/eg/lib/strtonum.awk
parent5a05ddf24b9f5ebc81a1b295ba7a6fbc7348776b (diff)
parent6c541fd0f75cd328dd80afec757ecccc833719af (diff)
downloadegawk-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.awk7
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