/* ******************************************************************************* * * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: ustring.c * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 * * created on: 2000aug15 * created by: Markus W. Scherer * * This file contains sample code that illustrates the use of Unicode strings * with ICU. */ #include #include "unicode/utypes.h" #include "unicode/ustring.h" #include "unicode/unistr.h" // helper function --------------------------------------------------------- *** static void printUnicodeString(const UnicodeString &s) { static char out[200]; int32_t i, length; // output the string, converted to the platform encoding out[s.extract(0, 99, out)]=0; printf("%s {", out); // output the code units length=s.length(); for(i=0; i UChar * -> char * with only " "invariant characters: \"%s\"\n", cs2); // initialize a UnicodeString from a string literal that contains // escape sequences written with invariant characters // do not forget to duplicate the backslashes for ICU to see them // then, count each double backslash only once! UnicodeString german=UNICODE_STRING( "Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\n", 64). unescape(); printf("german UnicodeString from unescaping:\n "); printUnicodeString(german); /* * C: convert and unescape a char * string with only invariant * characters to fill a UChar * string */ UChar buffer[200]; int32_t length; length=u_unescape( "Sch\\u00f6nes Auto: \\u20ac 11240.\\fPrivates Zeichen: \\U00102345\\n", buffer, LENGTHOF(buffer)); printf("german C Unicode string from char * unescaping: (length %d)\n ", length); printUnicodeString(UnicodeString(buffer)); } extern int main(int argc, const char *argv[]) { demoStorage(); initString(); return 0; }