+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
-* Copyright (C) 2002-2015, International Business Machines
+* Copyright (C) 2002-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: cstrcase.c
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
#include "unicode/ucasemap.h"
#include "cmemory.h"
#include "cintltst.h"
+#include "ucasemap_imp.h"
#include "ustr_imp.h"
/* test string case mapping functions --------------------------------------- */
/* lowercase with root locale and separate buffers */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToLower(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeLower, sizeof(beforeLower)/U_SIZEOF_UCHAR,
+ length=u_strToLower(buffer, UPRV_LENGTHOF(buffer),
+ beforeLower, UPRV_LENGTHOF(beforeLower),
"",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(lowerRoot)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(lowerRoot)) ||
uprv_memcmp(lowerRoot, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* lowercase with turkish locale and in the same buffer */
uprv_memcpy(buffer, beforeLower, sizeof(beforeLower));
- buffer[sizeof(beforeLower)/U_SIZEOF_UCHAR]=0;
+ buffer[UPRV_LENGTHOF(beforeLower)]=0;
errorCode=U_ZERO_ERROR;
- length=u_strToLower(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
+ length=u_strToLower(buffer, UPRV_LENGTHOF(buffer),
buffer, -1, /* implicit srcLength */
"tr",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(lowerTurkish)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(lowerTurkish)) ||
uprv_memcmp(lowerTurkish, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
buffer[0]=buffer[2]=0xabcd;
errorCode=U_ZERO_ERROR;
length=u_strToLower(buffer, 2, /* set destCapacity=2 */
- beforeLower, sizeof(beforeLower)/U_SIZEOF_UCHAR,
+ beforeLower, UPRV_LENGTHOF(beforeLower),
"",
&errorCode);
if( errorCode!=U_BUFFER_OVERFLOW_ERROR ||
- length!=(sizeof(lowerRoot)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(lowerRoot)) ||
uprv_memcmp(lowerRoot, buffer, 2*U_SIZEOF_UCHAR)!=0 ||
buffer[2]!=0xabcd
) {
/* test error handling */
errorCode=U_ZERO_ERROR;
- length=u_strToLower(NULL, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeLower, sizeof(beforeLower)/U_SIZEOF_UCHAR,
+ length=u_strToLower(NULL, UPRV_LENGTHOF(buffer),
+ beforeLower, UPRV_LENGTHOF(beforeLower),
"",
&errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) {
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
length=u_strToLower(buffer, -1,
- beforeLower, sizeof(beforeLower)/U_SIZEOF_UCHAR,
+ beforeLower, UPRV_LENGTHOF(beforeLower),
"",
&errorCode);
if( errorCode!=U_ILLEGAL_ARGUMENT_ERROR ||
/* uppercase with root locale and in the same buffer */
uprv_memcpy(buffer, beforeUpper, sizeof(beforeUpper));
errorCode=U_ZERO_ERROR;
- length=u_strToUpper(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- buffer, sizeof(beforeUpper)/U_SIZEOF_UCHAR,
+ length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer),
+ buffer, UPRV_LENGTHOF(beforeUpper),
"",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(upperRoot)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(upperRoot)) ||
uprv_memcmp(upperRoot, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* uppercase with turkish locale and separate buffers */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToUpper(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeUpper, sizeof(beforeUpper)/U_SIZEOF_UCHAR,
+ length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer),
+ beforeUpper, UPRV_LENGTHOF(beforeUpper),
"tr",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(upperTurkish)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(upperTurkish)) ||
uprv_memcmp(upperTurkish, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* test preflighting */
errorCode=U_ZERO_ERROR;
length=u_strToUpper(NULL, 0,
- beforeUpper, sizeof(beforeUpper)/U_SIZEOF_UCHAR,
+ beforeUpper, UPRV_LENGTHOF(beforeUpper),
"tr",
&errorCode);
if( errorCode!=U_BUFFER_OVERFLOW_ERROR ||
- length!=(sizeof(upperTurkish)/U_SIZEOF_UCHAR)
+ length!=(UPRV_LENGTHOF(upperTurkish))
) {
log_err("error in u_strToUpper(turkish locale pure preflighting)=%ld error=%s\n",
length,
/* test error handling */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToUpper(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- NULL, sizeof(beforeUpper)/U_SIZEOF_UCHAR,
+ length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer),
+ NULL, UPRV_LENGTHOF(beforeUpper),
"tr",
&errorCode);
if( errorCode!=U_ILLEGAL_ARGUMENT_ERROR ||
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToUpper(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
+ length=u_strToUpper(buffer, UPRV_LENGTHOF(buffer),
beforeUpper, -2,
"tr",
&errorCode);
UErrorCode errorCode;
errorCode=U_ZERO_ERROR;
- titleIterChars=ubrk_open(UBRK_CHARACTER, "", beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR, &errorCode);
+ titleIterChars=ubrk_open(UBRK_CHARACTER, "", beforeTitle, UPRV_LENGTHOF(beforeTitle), &errorCode);
if(U_FAILURE(errorCode)) {
log_err_status(errorCode, "error: ubrk_open(UBRK_CHARACTER)->%s\n", u_errorName(errorCode));
return;
/* titlecase with standard break iterator and in the same buffer */
uprv_memcpy(buffer, beforeTitle, sizeof(beforeTitle));
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- buffer, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
+ buffer, UPRV_LENGTHOF(beforeTitle),
NULL, "",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(titleWord)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(titleWord)) ||
uprv_memcmp(titleWord, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* titlecase with UBRK_CHARACTERS and separate buffers */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
+ beforeTitle, UPRV_LENGTHOF(beforeTitle),
titleIterChars, "",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(titleChar)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(titleChar)) ||
uprv_memcmp(titleChar, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* test preflighting */
errorCode=U_ZERO_ERROR;
length=u_strToTitle(NULL, 0,
- beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ beforeTitle, UPRV_LENGTHOF(beforeTitle),
titleIterChars, "",
&errorCode);
if( errorCode!=U_BUFFER_OVERFLOW_ERROR ||
- length!=(sizeof(titleChar)/U_SIZEOF_UCHAR)
+ length!=(UPRV_LENGTHOF(titleChar))
) {
log_err("error in u_strToTitle(UBRK_CHARACTERS pure preflighting)=%ld error=%s\n",
length,
/* test error handling */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- NULL, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
+ NULL, UPRV_LENGTHOF(beforeTitle),
titleIterChars, "",
&errorCode);
if( errorCode!=U_ILLEGAL_ARGUMENT_ERROR ||
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
beforeTitle, -2,
titleIterChars, "",
&errorCode);
UErrorCode errorCode;
errorCode=U_ZERO_ERROR;
- titleIterWord=ubrk_open(UBRK_WORD, "", beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR, &errorCode);
+ titleIterWord=ubrk_open(UBRK_WORD, "", beforeTitle, UPRV_LENGTHOF(beforeTitle), &errorCode);
if(U_FAILURE(errorCode)) {
log_err_status(errorCode, "error: ubrk_open(UBRK_WORD)->%s\n", u_errorName(errorCode));
return;
/* titlecase with default locale */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
+ beforeTitle, UPRV_LENGTHOF(beforeTitle),
titleIterWord, "",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(titleRoot)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(titleRoot)) ||
uprv_memcmp(titleRoot, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* titlecase with Dutch locale */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strToTitle(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- beforeTitle, sizeof(beforeTitle)/U_SIZEOF_UCHAR,
+ length=u_strToTitle(buffer, UPRV_LENGTHOF(buffer),
+ beforeTitle, UPRV_LENGTHOF(beforeTitle),
titleIterWord, "nl",
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(titleDutch)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(titleDutch)) ||
uprv_memcmp(titleDutch, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* test full string case folding with default option and separate buffers */
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_DEFAULT,
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(foldedDefault)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(foldedDefault)) ||
uprv_memcmp(foldedDefault, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
if(isUnicode_3_1) {
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_EXCLUDE_SPECIAL_I,
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(foldedExcludeSpecialI)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(foldedExcludeSpecialI)) ||
uprv_memcmp(foldedExcludeSpecialI, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
/* test full string case folding with default option and in the same buffer */
uprv_memcpy(buffer, mixed, sizeof(mixed));
- buffer[sizeof(mixed)/U_SIZEOF_UCHAR]=0;
+ buffer[UPRV_LENGTHOF(mixed)]=0;
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
buffer, -1, /* implicit srcLength */
U_FOLD_CASE_DEFAULT,
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(foldedDefault)/U_SIZEOF_UCHAR) ||
+ length!=(UPRV_LENGTHOF(foldedDefault)) ||
uprv_memcmp(foldedDefault, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
if(isUnicode_3_1) {
uprv_memcpy(buffer, mixed, sizeof(mixed));
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- buffer, sizeof(mixed)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
+ buffer, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_EXCLUDE_SPECIAL_I,
&errorCode);
if( U_FAILURE(errorCode) ||
- length!=(sizeof(foldedExcludeSpecialI)/U_SIZEOF_UCHAR) ||
+ length!=UPRV_LENGTHOF(foldedExcludeSpecialI) ||
uprv_memcmp(foldedExcludeSpecialI, buffer, length*U_SIZEOF_UCHAR)!=0 ||
buffer[length]!=0
) {
buffer[0]=buffer[2]=0xabcd;
errorCode=U_ZERO_ERROR;
length=u_strFoldCase(buffer, 2, /* set destCapacity=2 */
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_DEFAULT,
&errorCode);
if( errorCode!=U_BUFFER_OVERFLOW_ERROR ||
- length!=(sizeof(foldedDefault)/U_SIZEOF_UCHAR) ||
+ length!=UPRV_LENGTHOF(foldedDefault) ||
uprv_memcmp(foldedDefault, buffer, 2*U_SIZEOF_UCHAR)!=0 ||
buffer[2]!=0xabcd
) {
errorCode=U_ZERO_ERROR;
length=u_strFoldCase(NULL, 0,
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_DEFAULT,
&errorCode);
if( errorCode!=U_BUFFER_OVERFLOW_ERROR ||
- length!=(sizeof(foldedDefault)/U_SIZEOF_UCHAR)
+ length!=UPRV_LENGTHOF(foldedDefault)
) {
log_err("error in u_strFoldCase(default pure preflighting)=%ld error=%s\n",
length,
/* test error handling */
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(NULL, sizeof(buffer)/U_SIZEOF_UCHAR,
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(NULL, UPRV_LENGTHOF(buffer),
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_DEFAULT,
&errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) {
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
length=u_strFoldCase(buffer, -1,
- mixed, sizeof(mixed)/U_SIZEOF_UCHAR,
+ mixed, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_DEFAULT,
&errorCode);
if( errorCode!=U_ILLEGAL_ARGUMENT_ERROR ||
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
- NULL, sizeof(mixed)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
+ NULL, UPRV_LENGTHOF(mixed),
U_FOLD_CASE_EXCLUDE_SPECIAL_I,
&errorCode);
if( errorCode!=U_ILLEGAL_ARGUMENT_ERROR ||
buffer[0]=0xabcd;
errorCode=U_ZERO_ERROR;
- length=u_strFoldCase(buffer, sizeof(buffer)/U_SIZEOF_UCHAR,
+ length=u_strFoldCase(buffer, UPRV_LENGTHOF(buffer),
mixed, -2,
U_FOLD_CASE_EXCLUDE_SPECIAL_I,
&errorCode);
if(0!=strcmp(locale, "tr")) {
log_err("ucasemap_getLocale(ucasemap_open(\"tur\"))==%s!=\"tr\"\n", locale);
}
- /* overly long locale IDs get truncated to their language code to avoid unnecessary allocation */
+ /* overly long locale IDs may get truncated to their language code to avoid unnecessary allocation */
ucasemap_setLocale(csm, "I-kLInGOn-the-quick-brown-fox-jumps-over-the-lazy-dog", &errorCode);
locale=ucasemap_getLocale(csm);
- if(0!=strcmp(locale, "i-klingon")) {
- log_err("ucasemap_getLocale(ucasemap_setLocale(\"I-kLInGOn-the-quick-br...\"))==%s!=\"i-klingon\"\n", locale);
+ // "I-kLInGOn-the-quick-brown-fox-jumps-over-the-lazy-dog" is canonicalized
+ // into "tlh-the-quick-brown-fox-jumps-over-the-lazy-dog"
+ // and "the" will be treated as an extlang which replaces "tlh".
+ if(0!=strncmp(locale, "the", 3)) {
+ log_err("ucasemap_getLocale(ucasemap_setLocale(\"I-kLInGOn-the-quick-br...\"))==%s\n"
+ " does not start with \"the\"\n", locale);
}
errorCode=U_ZERO_ERROR;