summaryrefslogtreecommitdiff
path: root/integer.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-09-19 05:06:11 -0400
committerJeffrey Walton <noloader@gmail.com>2021-09-19 05:06:11 -0400
commite154280d310c137148d321828a2b98c0c1e4158f (patch)
tree06a4f8e43c72f8fd5c2f2cf69463e86833060434 /integer.cpp
parent3accc3d0839242468e9b536aa0fa2244985127c5 (diff)
downloadcryptopp-git-e154280d310c137148d321828a2b98c0c1e4158f.tar.gz
Add octal and decimal literal prefix to Integer class
Diffstat (limited to 'integer.cpp')
-rw-r--r--integer.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/integer.cpp b/integer.cpp
index 9ab70e17..dac3ef7c 100644
--- a/integer.cpp
+++ b/integer.cpp
@@ -3199,6 +3199,7 @@ static Integer StringToInteger(const T *str, ByteOrder order)
if (length == 0)
return Integer::Zero();
+ // 'str' is of length 1 or more
switch (str[length-1])
{
case 'h':
@@ -3224,10 +3225,25 @@ static Integer StringToInteger(const T *str, ByteOrder order)
str += 1, length -= 1;
}
- if (length > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
+ // Recognize common prefixes for hexadecimal, octal and decimal.
+ // Microsoft's MASM also recognizes 0t for octal, but not here.
+ if (length > 2 && str[0] == '0')
{
- radix = 16;
- str += 2, length -= 2;
+ if (str[1] == 'x' || str[1] == 'X')
+ {
+ radix = 16;
+ str += 2, length -= 2;
+ }
+ else if (str[1] == 'n' || str[1] == 'N')
+ {
+ radix = 10;
+ str += 2, length -= 2;
+ }
+ else if (str[1] == 'o' || str[1] == 'O')
+ {
+ radix = 8;
+ str += 2, length -= 2;
+ }
}
if (order == BIG_ENDIAN_ORDER)