OLD | NEW |
| (Empty) |
1 /* | |
2 ********************************************************************** | |
3 * Copyright (C) 2001-2009, International Business Machines | |
4 * Corporation and others. All Rights Reserved. | |
5 ********************************************************************** | |
6 * Date Name Description | |
7 * 05/23/00 aliu Creation. | |
8 ********************************************************************** | |
9 */ | |
10 | |
11 #include "unicode/unistr.h" | |
12 #include "testutil.h" | |
13 | |
14 static const UChar HEX[16]={48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70}; | |
15 | |
16 UnicodeString &TestUtility::appendHex(UnicodeString &buf, UChar32 ch) { | |
17 if (ch >= 0x10000) { | |
18 if (ch >= 0x100000) { | |
19 buf.append(HEX[0xF&(ch>>20)]); | |
20 } | |
21 buf.append(HEX[0xF&(ch>>16)]); | |
22 } | |
23 buf.append(HEX[0xF&(ch>>12)]); | |
24 buf.append(HEX[0xF&(ch>>8)]); | |
25 buf.append(HEX[0xF&(ch>>4)]); | |
26 buf.append(HEX[0xF&ch]); | |
27 return buf; | |
28 } | |
29 | |
30 UnicodeString TestUtility::hex(UChar32 ch) { | |
31 UnicodeString buf; | |
32 appendHex(buf, ch); | |
33 return buf; | |
34 } | |
35 | |
36 UnicodeString TestUtility::hex(const UnicodeString& s) { | |
37 return hex(s, 44 /*,*/); | |
38 } | |
39 | |
40 UnicodeString TestUtility::hex(const UnicodeString& s, UChar sep) { | |
41 UnicodeString result; | |
42 if (s.isEmpty()) return result; | |
43 UChar32 c; | |
44 for (int32_t i = 0; i < s.length(); i += U16_LENGTH(c)) { | |
45 c = s.char32At(i); | |
46 if (i > 0) { | |
47 result.append(sep); | |
48 } | |
49 appendHex(result, c); | |
50 } | |
51 return result; | |
52 } | |
53 | |
54 UnicodeString TestUtility::hex(const uint8_t* bytes, int32_t len) { | |
55 UnicodeString buf; | |
56 for (int32_t i = 0; i < len; ++i) { | |
57 buf.append(HEX[0x0F & (bytes[i] >> 4)]); | |
58 buf.append(HEX[0x0F & bytes[i]]); | |
59 } | |
60 return buf; | |
61 } | |
OLD | NEW |