/** * Convert the utf-8 input string to uppercase * Output needs to be allocated appropriately * * @param input input string * @param output output buffer */ void GNUNET_STRINGS_utf8_toupper(const char* input, char** output) { uint8_t *tmp_in; size_t len; tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input), NULL, UNINORM_NFD, NULL, &len); memcpy(*output, tmp_in, len); (*output)[len] = '\0'; free(tmp_in); }
U8_EXPORT /* u8_upcase: Arguments: a null-terminated utf-8 C string Returns: a copy of the string in uppercase */ u8_string u8_upcase (u8_string string) { const u8_byte *scan=string; struct U8_OUTPUT ss; int c; U8_INIT_STATIC_OUTPUT(ss,32); while (*scan) { if (*scan < 0x80) c=toupper(*scan++); else c=u8_toupper(u8_sgetc(&scan)); u8_putc(&ss,c);} return (u8_string)ss.u8_outbuf; }
int main (int argc, char * argv[]) { setlocale (LC_ALL, ""); if (argc == 1) { /* Display the upper case of the input string. */ char *input = read_file (stdin); int length = strlen (input); size_t output_length; uint8_t *output = u8_toupper ((uint8_t *) input, length, uc_locale_language (), NULL, NULL, &output_length); fwrite (output, 1, output_length, stdout); return 0; } else return 1; }