icuicu4c

ICU4C austrdup function


I'm trying to run the code demo for ICU4C bellow, and getting

warning: implicit declaration of function 'austrdup'

which subsequently generate an error. I understand that this is due to the missing imported library that contains 'austrdup' function, and have been looking at the source code to guess which one it is, but no luck. Does anyone have any idea which one should be imported?

#include <unicode/umsg.h>
#include <unicode/ustring.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char const *argv[])
{
    UChar* str;
    UErrorCode status = U_ZERO_ERROR;
    UChar *result = NULL;
    UChar pattern[100];

    int32_t resultlength, resultLengthOut, i;
    double testArgs[] = { 100.0, 1.0, 0.0};
    str=(UChar*)malloc(sizeof(UChar) * 10);
    u_uastrcpy(str, "MyDisk");
    u_uastrcpy(pattern, "The disk {1} contains {0,choice,0#no files|1#one file|1<{0,number,integer} files}");

    for(i=0; i<3; i++){
        resultlength=0; 
        resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, testArgs[i], str); 
        if(status==U_BUFFER_OVERFLOW_ERROR){ //check if output truncated
            status=U_ZERO_ERROR;
            resultlength=resultLengthOut+1;
            result=(UChar*)malloc(sizeof(UChar) * resultlength);
            u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, testArgs[i], str);
        }
        printf("%s\n", austrdup(result) );  //austrdup( a function used to convert UChar* to char*)
        free(result);
    }
    return 0;
}

Solution

  • austrdup is not an official ICU method. It's only used by tests in ICU and defined in icu4c/source/test/cintltst/cintltst.h and implemented in icu4c/source/test/cintltst/cintltst.c. It is bascially just a wrapper around u_austrcpy.