aboutsummaryrefslogtreecommitdiffstats
path: root/awklib/eg/lib/strtonum.awk
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-08-29 13:11:45 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-08-29 13:11:45 +0300
commit6c541fd0f75cd328dd80afec757ecccc833719af (patch)
tree163707da9efd9c8d0c7a7e9d0ef3887222c88bf3 /awklib/eg/lib/strtonum.awk
parentff28c07f95ff2400eb0ad1becc0eae1eab9dc93d (diff)
downloadegawk-6c541fd0f75cd328dd80afec757ecccc833719af.tar.gz
egawk-6c541fd0f75cd328dd80afec757ecccc833719af.tar.bz2
egawk-6c541fd0f75cd328dd80afec757ecccc833719af.zip
More doc updates.
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