// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * * Copyright (C) 1997-2011, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * * File CSTRING.C * * @author Helena Shih * * Modification History: * * Date Name Description * 6/18/98 hshih Created * 09/08/98 stephen Added include for ctype, for Mac Port * 11/15/99 helena Integrated S/390 IEEE changes. ****************************************************************************** */ #include <stdlib.h> #include <stdio.h> #include "unicode/utypes.h" #include "cmemory.h" #include "cstring.h" #include "uassert.h" /* * We hardcode case conversion for invariant characters to match our expectation * and the compiler execution charset. * This prevents problems on systems * - with non-default casing behavior, like Turkish system locales where * tolower('I') maps to dotless i and toupper('i') maps to dotted I * - where there are no lowercase Latin characters at all, or using different * codes (some old EBCDIC codepages) * * This works because the compiler usually runs on a platform where the execution * charset includes all of the invariant characters at their expected * code positions, so that the char * string literals in ICU code match * the char literals here. * * Note that the set of lowercase Latin letters is discontiguous in EBCDIC * and the set of uppercase Latin letters is discontiguous as well. */ U_CAPI UBool U_EXPORT2 uprv_isASCIILetter(char c) { … } U_CAPI char U_EXPORT2 uprv_toupper(char c) { … } #if 0 /* * Commented out because cstring.h defines uprv_tolower() to be * the same as either uprv_asciitolower() or uprv_ebcdictolower() * to reduce the amount of code to cover with tests. * * Note that this uprv_tolower() definition is likely to work for most * charset families, not just ASCII and EBCDIC, because its #else branch * is written generically. */ U_CAPI char U_EXPORT2 uprv_tolower(char c) { #if U_CHARSET_FAMILY==U_EBCDIC_FAMILY if(('A'<=c && c<='I') || ('J'<=c && c<='R') || ('S'<=c && c<='Z')) { c=(char)(c+('a'-'A')); } #else if('A'<=c && c<='Z') { c=(char)(c+('a'-'A')); } #endif return c; } #endif U_CAPI char U_EXPORT2 uprv_asciitolower(char c) { … } U_CAPI char U_EXPORT2 uprv_ebcdictolower(char c) { … } U_CAPI char* U_EXPORT2 T_CString_toLowerCase(char* str) { … } U_CAPI char* U_EXPORT2 T_CString_toUpperCase(char* str) { … } /* * Takes a int32_t and fills in a char* string with that number "radix"-based. * Does not handle negative values (makes an empty string for them). * Writes at most 12 chars ("-2147483647" plus NUL). * Returns the length of the string (not including the NUL). */ U_CAPI int32_t U_EXPORT2 T_CString_integerToString(char* buffer, int32_t v, int32_t radix) { … } /* * Takes a int64_t and fills in a char* string with that number "radix"-based. * Writes at most 21: chars ("-9223372036854775807" plus NUL). * Returns the length of the string, not including the terminating NUL. */ U_CAPI int32_t U_EXPORT2 T_CString_int64ToString(char* buffer, int64_t v, uint32_t radix) { … } U_CAPI int32_t U_EXPORT2 T_CString_stringToInteger(const char *integerString, int32_t radix) { … } U_CAPI int U_EXPORT2 uprv_stricmp(const char *str1, const char *str2) { … } U_CAPI int U_EXPORT2 uprv_strnicmp(const char *str1, const char *str2, uint32_t n) { … } U_CAPI char* U_EXPORT2 uprv_strdup(const char *src) { … } U_CAPI char* U_EXPORT2 uprv_strndup(const char *src, int32_t n) { … }