summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-15 07:27:19 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-15 07:27:19 +0000
commit6082f8c569cd3df0ebdcec61a223027868207473 (patch)
tree4273e813b6dfdde2819c499595f18827d5fb7ac4 /src/mir_core
parenta2c85825aaec89e4602615b30e1af45c13adc4dd (diff)
bin2hex/bin2hexW = eliminates many places with printf("%02x")
git-svn-id: http://svn.miranda-ng.org/main/trunk@5698 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/mir_core.def2
-rw-r--r--src/mir_core/utils.cpp34
2 files changed, 36 insertions, 0 deletions
diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def
index c820c2dd59..037afb2aaf 100644
--- a/src/mir_core/mir_core.def
+++ b/src/mir_core/mir_core.def
@@ -227,3 +227,5 @@ mir_writeLogA @224
mir_writeLogW @225
mir_writeLogVA @226
mir_writeLogVW @227
+bin2hex @228
+bin2hexW @229
diff --git a/src/mir_core/utils.cpp b/src/mir_core/utils.cpp
index 52eef31fc2..d357b4538f 100644
--- a/src/mir_core/utils.cpp
+++ b/src/mir_core/utils.cpp
@@ -139,6 +139,8 @@ MIR_CORE_DLL(WCHAR*) ltrimpw(WCHAR *str)
}
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
MIR_CORE_DLL(int) wildcmp(const char *name, const char *mask)
{
const char *last='\0';
@@ -212,3 +214,35 @@ MIR_CORE_DLL(int) wildcmpiw(const WCHAR *name, const WCHAR *mask)
if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last;
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static char szHexTable[] = "0123456789abcdef";
+
+MIR_CORE_DLL(char*) bin2hex(const void *pData, size_t len, char *dest)
+{
+ const BYTE *p = (const BYTE*)pData;
+ char *d = dest;
+
+ for (size_t i=0; i < len; i++, p++) {
+ *d++ = szHexTable[*p >> 4];
+ *d++ = szHexTable[*p & 0x0F];
+ }
+ *d = 0;
+
+ return dest;
+}
+
+MIR_CORE_DLL(WCHAR*) bin2hexW(const void *pData, size_t len, WCHAR *dest)
+{
+ const BYTE *p = (const BYTE*)pData;
+ WCHAR *d = dest;
+
+ for (size_t i=0; i < len; i++, p++) {
+ *d++ = szHexTable[*p >> 4];
+ *d++ = szHexTable[*p & 0x0F];
+ }
+ *d = 0;
+
+ return dest;
+}