diff options
author | 2016-04-09 21:45:54 +1000 | |
---|---|---|
committer | 2016-04-09 21:52:08 +1000 | |
commit | e925c494fe30adafb615c075f5eb692dd2b2effa (patch) | |
tree | eed0b7ccadb049ed2dc8a72282c0235c4e94b6ae /3rdparty/lzma/CPP/Common/IntToString.cpp | |
parent | b13e02f9751424dfc9ce6070676e2e318087a991 (diff) |
Update LZMA SDK to 15.14
Diffstat (limited to '3rdparty/lzma/CPP/Common/IntToString.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/Common/IntToString.cpp | 149 |
1 files changed, 109 insertions, 40 deletions
diff --git a/3rdparty/lzma/CPP/Common/IntToString.cpp b/3rdparty/lzma/CPP/Common/IntToString.cpp index 013fee5277f..ed217c72c0a 100644 --- a/3rdparty/lzma/CPP/Common/IntToString.cpp +++ b/3rdparty/lzma/CPP/Common/IntToString.cpp @@ -4,74 +4,143 @@ #include "IntToString.h" -void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base) +#define CONVERT_INT_TO_STR(charType, tempSize) \ + unsigned char temp[tempSize]; unsigned i = 0; \ + while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \ + *s++ = (charType)('0' + (unsigned)val); \ + while (i != 0) { i--; *s++ = temp[i]; } \ + *s = 0; + +void ConvertUInt32ToString(UInt32 val, char *s) throw() { - if (base < 2 || base > 36) + CONVERT_INT_TO_STR(char, 16); +} + +void ConvertUInt64ToString(UInt64 val, char *s) throw() +{ + if (val <= (UInt32)0xFFFFFFFF) { - *s = '\0'; + ConvertUInt32ToString((UInt32)val, s); return; } - char temp[72]; - int pos = 0; - do + CONVERT_INT_TO_STR(char, 24); +} + +void ConvertUInt64ToOct(UInt64 val, char *s) throw() +{ + UInt64 v = val; + unsigned i; + for (i = 1;; i++) { - int delta = (int)(value % base); - temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10))); - value /= base; + v >>= 3; + if (v == 0) + break; } - while (value != 0); + s[i] = 0; do - *s++ = temp[--pos]; - while (pos > 0); - *s = '\0'; + { + unsigned t = (unsigned)(val & 0x7); + val >>= 3; + s[--i] = (char)('0' + t); + } + while (i); } -void ConvertUInt64ToString(UInt64 value, wchar_t *s) +void ConvertUInt32ToHex(UInt32 val, char *s) throw() { - wchar_t temp[32]; - int pos = 0; + UInt32 v = val; + unsigned i; + for (i = 1;; i++) + { + v >>= 4; + if (v == 0) + break; + } + s[i] = 0; do { - temp[pos++] = (wchar_t)(L'0' + (int)(value % 10)); - value /= 10; + unsigned t = (unsigned)((val & 0xF)); + val >>= 4; + s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); } - while (value != 0); + while (i); +} + +void ConvertUInt64ToHex(UInt64 val, char *s) throw() +{ + UInt64 v = val; + unsigned i; + for (i = 1;; i++) + { + v >>= 4; + if (v == 0) + break; + } + s[i] = 0; do - *s++ = temp[--pos]; - while (pos > 0); - *s = L'\0'; + { + unsigned t = (unsigned)((val & 0xF)); + val >>= 4; + s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); + } + while (i); } -void ConvertUInt32ToString(UInt32 value, char *s) { ConvertUInt64ToString(value, s); } -void ConvertUInt32ToString(UInt32 value, wchar_t *s) { ConvertUInt64ToString(value, s); } +void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw() +{ + s[8] = 0; + for (int i = 7; i >= 0; i--) + { + unsigned t = val & 0xF; + val >>= 4; + s[i] = (char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); + } +} -void ConvertInt64ToString(Int64 value, char *s) +/* +void ConvertUInt32ToHex8Digits(UInt32 val, wchar_t *s) { - if (value < 0) + s[8] = 0; + for (int i = 7; i >= 0; i--) { - *s++ = '-'; - value = -value; + unsigned t = val & 0xF; + val >>= 4; + s[i] = (wchar_t)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); + } +} +*/ + +void ConvertUInt32ToString(UInt32 val, wchar_t *s) throw() +{ + CONVERT_INT_TO_STR(wchar_t, 16); +} + +void ConvertUInt64ToString(UInt64 val, wchar_t *s) throw() +{ + if (val <= (UInt32)0xFFFFFFFF) + { + ConvertUInt32ToString((UInt32)val, s); + return; } - ConvertUInt64ToString(value, s); + CONVERT_INT_TO_STR(wchar_t, 24); } -void ConvertInt64ToString(Int64 value, wchar_t *s) +void ConvertInt64ToString(Int64 val, char *s) throw() { - if (value < 0) + if (val < 0) { - *s++ = L'-'; - value = -value; + *s++ = '-'; + val = -val; } - ConvertUInt64ToString(value, s); + ConvertUInt64ToString(val, s); } -void ConvertUInt32ToHexWithZeros(UInt32 value, char *s) +void ConvertInt64ToString(Int64 val, wchar_t *s) throw() { - for (int i = 0; i < 8; i++) + if (val < 0) { - int t = value & 0xF; - value >>= 4; - s[7 - i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); + *s++ = L'-'; + val = -val; } - s[8] = '\0'; + ConvertUInt64ToString(val, s); } |