aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/IntToString.cpp
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2018-05-02 18:54:43 -0700
committerSen Jiang <senj@google.com>2018-05-02 19:01:41 -0700
commit60f31b62204c0b25838ef36c5c2de187001efc6c (patch)
tree598a63536cfeda1e2c8d50a947bf33027be148b3 /CPP/Common/IntToString.cpp
parent9186d4157ac38b8c314ffe99ea031faff87de996 (diff)
downloadlzma-60f31b62204c0b25838ef36c5c2de187001efc6c.tar.gz
Update LZMA SDK to 18.05.
Downloaded from https://www.7-zip.org/a/lzma1805.7z Test: mma Change-Id: I95bf31512854191c040e94cc677794f9abc4c46a
Diffstat (limited to 'CPP/Common/IntToString.cpp')
-rw-r--r--CPP/Common/IntToString.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/CPP/Common/IntToString.cpp b/CPP/Common/IntToString.cpp
index d035115..da627ca 100644
--- a/CPP/Common/IntToString.cpp
+++ b/CPP/Common/IntToString.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include "../../C/CpuArch.h"
+
#include "IntToString.h"
#define CONVERT_INT_TO_STR(charType, tempSize) \
@@ -46,6 +48,12 @@ void ConvertUInt64ToOct(UInt64 val, char *s) throw()
while (i);
}
+
+#define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))))
+
+static inline char GetHexChar(unsigned t) { return GET_HEX_CHAR(t); }
+
+
void ConvertUInt32ToHex(UInt32 val, char *s) throw()
{
UInt32 v = val;
@@ -59,13 +67,14 @@ void ConvertUInt32ToHex(UInt32 val, char *s) throw()
s[i] = 0;
do
{
- unsigned t = (unsigned)((val & 0xF));
+ unsigned t = (unsigned)(val & 0xF);
val >>= 4;
- s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
+ s[--i] = GET_HEX_CHAR(t);
}
while (i);
}
+
void ConvertUInt64ToHex(UInt64 val, char *s) throw()
{
UInt64 v = val;
@@ -79,9 +88,9 @@ void ConvertUInt64ToHex(UInt64 val, char *s) throw()
s[i] = 0;
do
{
- unsigned t = (unsigned)((val & 0xF));
+ unsigned t = (unsigned)(val & 0xF);
val >>= 4;
- s[--i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
+ s[--i] = GET_HEX_CHAR(t);
}
while (i);
}
@@ -93,7 +102,7 @@ void ConvertUInt32ToHex8Digits(UInt32 val, char *s) throw()
{
unsigned t = val & 0xF;
val >>= 4;
- s[i] = (char)(((t < 10) ? ('0' + t) : ('A' + (t - 10))));
+ s[i] = GET_HEX_CHAR(t);;
}
}
@@ -144,3 +153,41 @@ void ConvertInt64ToString(Int64 val, wchar_t *s) throw()
}
ConvertUInt64ToString(val, s);
}
+
+
+static void ConvertByteToHex2Digits(unsigned v, char *s) throw()
+{
+ s[0] = GetHexChar(v >> 4);
+ s[1] = GetHexChar(v & 0xF);
+}
+
+static void ConvertUInt16ToHex4Digits(UInt32 val, char *s) throw()
+{
+ ConvertByteToHex2Digits(val >> 8, s);
+ ConvertByteToHex2Digits(val & 0xFF, s + 2);
+}
+
+char *RawLeGuidToString(const Byte *g, char *s) throw()
+{
+ ConvertUInt32ToHex8Digits(GetUi32(g ), s); s += 8; *s++ = '-';
+ ConvertUInt16ToHex4Digits(GetUi16(g + 4), s); s += 4; *s++ = '-';
+ ConvertUInt16ToHex4Digits(GetUi16(g + 6), s); s += 4; *s++ = '-';
+ for (unsigned i = 0; i < 8; i++)
+ {
+ if (i == 2)
+ *s++ = '-';
+ ConvertByteToHex2Digits(g[8 + i], s);
+ s += 2;
+ }
+ *s = 0;
+ return s;
+}
+
+char *RawLeGuidToString_Braced(const Byte *g, char *s) throw()
+{
+ *s++ = '{';
+ s = RawLeGuidToString(g, s);
+ *s++ = '}';
+ *s = 0;
+ return s;
+}