From 6082f8c569cd3df0ebdcec61a223027868207473 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 15 Aug 2013 07:27:19 +0000 Subject: bin2hex/bin2hexW = eliminates many places with printf("%02x") git-svn-id: http://svn.miranda-ng.org/main/trunk@5698 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/mir_core.def | 2 ++ src/mir_core/utils.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src') 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; +} -- cgit v1.2.3