]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/testutil.cpp
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / test / intltest / testutil.cpp
1 /*
2 **********************************************************************
3 * Copyright (C) 2001, 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::hex(UChar ch) {
17 UnicodeString buf;
18 buf.append(HEX[0xF&(ch>>12)]);
19 buf.append(HEX[0xF&(ch>>8)]);
20 buf.append(HEX[0xF&(ch>>4)]);
21 buf.append(HEX[0xF&ch]);
22 return buf;
23 }
24
25 UnicodeString TestUtility::hex(const UnicodeString& s) {
26 return hex(s, 44 /*,*/);
27 }
28
29 UnicodeString TestUtility::hex(const UnicodeString& s, UChar sep) {
30 if (s.length() == 0) return "";
31 UnicodeString result = hex(s.charAt(0));
32 for (int32_t i = 1; i < s.length(); ++i) {
33 result.append(sep);
34 result.append(hex(s.charAt(i)));
35 }
36 return result;
37 }