1
#include "unicode/unistr.h"
5
// Verify that a UErrorCode is successful; exit(1) if not
6
void check(UErrorCode& status, const char* msg) {
7
if (U_FAILURE(status)) {
8
printf("ERROR: %s (%s)\n", u_errorName(status), msg);
11
// printf("Ok: %s\n", msg);
14
// Append a hex string to the target
15
static UnicodeString& appendHex(uint32_t number,
17
UnicodeString& target) {
18
static const UnicodeString DIGIT_STRING("0123456789ABCDEF");
20
target += DIGIT_STRING[(number >> ((--digits) * 4)) & 0xF];
25
// Replace nonprintable characters with unicode escapes
26
UnicodeString escape(const UnicodeString &source) {
30
for (i=0; i<source.length(); ++i) {
32
if (ch < 0x09 || (ch > 0x0A && ch < 0x20) || ch > 0x7E) {
34
appendHex(ch, 4, target);
43
// Print the given string to stdout
44
void uprintf(const UnicodeString &str) {
46
int32_t len = str.length();
47
// int32_t bufLen = str.extract(0, len, buf); // Preflight
48
/* Preflighting seems to be broken now, so assume 1-1 conversion,
50
int32_t bufLen = len + 16;
52
buf = new char[bufLen + 1];
53
actualLen = str.extract(0, len, buf/*, bufLen*/); // Default codepage conversion