From 0b834daa26d5a866a9385f4f357547c82709e37f Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 19 May 2015 12:19:28 -0700 Subject: [PATCH] Simplify logic for ensuring minimum hex length in rctocpp Simplified the logic for ensuring that a hex string has 8 characters after the '0x' prefix. Also clarified a comment about potential loss of numeric precision when using numbers as indices in awk arrays. --- src/dlls/mscorrc/rctocpp.awk | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/dlls/mscorrc/rctocpp.awk b/src/dlls/mscorrc/rctocpp.awk index c547bf7..84b4b90 100644 --- a/src/dlls/mscorrc/rctocpp.awk +++ b/src/dlls/mscorrc/rctocpp.awk @@ -15,19 +15,13 @@ function numberToHexString(number) quotient = number; hexString = ""; - while (quotient > 0) + for (digitCount = 0; digitCount < 8; digitCount++) { remainder = quotient % 16; quotient = int(quotient / 16); hexString = sprintf("%x"hexString, remainder); } - lengthOfHexString = length(hexString); - if (lengthOfHexString < 8) - { - hexString = substr("00000000", 1, 8 - lengthOfHexString) hexString; - } - hexString = "0x" hexString; return hexString; } @@ -56,8 +50,9 @@ function writestringentry(id, str) numEntries++; # Use the string representation of the ID as the array index - # because the precision of numeric indices can be lost when - # iterating over the array in our for-in loop. + # because the precision of numeric indices can be lost during + # the number -> string -> number conversions that would occur + # if numeric indices are used. resourceArray[numberToHexString(id)] = str; } -- 2.7.4