]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/testutil.cpp
ICU-511.34.tar.gz
[apple/icu.git] / icuSources / test / intltest / testutil.cpp
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
729e4ab9 3* Copyright (C) 2001-2009, International Business Machines
b75a7d8f
A
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
14static const UChar HEX[16]={48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70};
15
729e4ab9
A
16UnicodeString &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 }
b75a7d8f
A
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
729e4ab9
A
30UnicodeString TestUtility::hex(UChar32 ch) {
31 UnicodeString buf;
32 appendHex(buf, ch);
33 return buf;
34}
35
b75a7d8f
A
36UnicodeString TestUtility::hex(const UnicodeString& s) {
37 return hex(s, 44 /*,*/);
38}
39
40UnicodeString TestUtility::hex(const UnicodeString& s, UChar sep) {
729e4ab9
A
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);
b75a7d8f
A
50 }
51 return result;
52}
729e4ab9
A
53
54UnicodeString 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}