Logo Search packages:      
Sourcecode: icu version File versions  Download package

#define U_STRING_DECL ( var,
length   )     static const UChar var[(length)+1]=L ## cs

Unicode String literals in C. We need one macro to declare a variable for the string and to statically preinitialize it if possible, and a second macro to dynamically intialize such a string variable if necessary.

The macros are defined for maximum performance. They work only for strings that contain "invariant characters", i.e., only latin letters, digits, and some punctuation. See utypes.h for details.

A pair of macros for a single string must be used with the same parameters. The string parameter must be a C string literal. The length of the string, not including the terminating NUL, must be specified as a constant. The U_STRING_DECL macro should be invoked exactly once for one such string variable before it is used.


    U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11);
    U_STRING_DECL(ustringVar2, "jumps 5%", 8);
    static UBool didInit=FALSE;

    int32_t function() {
        if(!didInit) {
            U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11);
            U_STRING_INIT(ustringVar2, "jumps 5%", 8);
        return u_strcmp(ustringVar1, ustringVar2);

Note that the macros will NOT consistently work if their argument is another define. The following will not work on all platforms, don't use it.

     define GLUCK "Mr. Gluck"
     U_STRING_DECL(var, GLUCK, 9)
     U_STRING_INIT(var, GLUCK, 9)

Instead, use the string literal "Mr. Gluck" as the argument to both macro calls.

ICU 2.0

Definition at line 941 of file ustring.h.

Referenced by CharIterTest::TestConstructionAndEqualityUChariter().

Generated by  Doxygen 1.6.0   Back to index