1 /* 2 ******************************************************************************* 3 * 4 * Copyright (C) 1999-2015, International Business Machines 5 * Corporation and others. All Rights Reserved. 6 * 7 ******************************************************************************* 8 * file name: uinvchar.h 9 * encoding: US-ASCII 10 * tab size: 8 (not used) 11 * indentation:2 12 * 13 * created on: 2004sep14 14 * created by: Markus W. Scherer 15 * 16 * Definitions for handling invariant characters, moved here from putil.c 17 * for better modularization. 18 */ 19 20 #ifndef __UINVCHAR_H__ 21 #define __UINVCHAR_H__ 22 23 #include "unicode/utypes.h" 24 #ifdef __cplusplus 25 #include "unicode/unistr.h" 26 #endif 27 28 /** 29 * Check if a char string only contains invariant characters. 30 * See utypes.h for details. 31 * 32 * @param s Input string pointer. 33 * @param length Length of the string, can be -1 if NUL-terminated. 34 * @return TRUE if s contains only invariant characters. 35 * 36 * @internal (ICU 2.8) 37 */ 38 U_INTERNAL UBool U_EXPORT2 39 uprv_isInvariantString(const char *s, int32_t length); 40 41 /** 42 * Check if a Unicode string only contains invariant characters. 43 * See utypes.h for details. 44 * 45 * @param s Input string pointer. 46 * @param length Length of the string, can be -1 if NUL-terminated. 47 * @return TRUE if s contains only invariant characters. 48 * 49 * @internal (ICU 2.8) 50 */ 51 U_INTERNAL UBool U_EXPORT2 52 uprv_isInvariantUString(const UChar *s, int32_t length); 53 54 #ifdef __cplusplus 55 56 /** 57 * Check if a UnicodeString only contains invariant characters. 58 * See utypes.h for details. 59 * 60 * @param s Input string. 61 * @return TRUE if s contains only invariant characters. 62 */ 63 U_INTERNAL inline UBool U_EXPORT2 64 uprv_isInvariantUnicodeString(const icu::UnicodeString &s) { 65 return uprv_isInvariantUString(s.getBuffer(), s.length()); 66 } 67 68 #endif /* __cplusplus */ 69 70 /** 71 * \def U_UPPER_ORDINAL 72 * Get the ordinal number of an uppercase invariant character 73 * @internal 74 */ 75 #if U_CHARSET_FAMILY==U_ASCII_FAMILY 76 # define U_UPPER_ORDINAL(x) ((x)-'A') 77 #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY 78 # define U_UPPER_ORDINAL(x) (((x) < 'J') ? ((x)-'A') : \ 79 (((x) < 'S') ? ((x)-'J'+9) : \ 80 ((x)-'S'+18))) 81 #else 82 # error Unknown charset family! 83 #endif 84 85 /** 86 * Compare two EBCDIC invariant-character strings in ASCII order. 87 * @internal 88 */ 89 U_INTERNAL int32_t U_EXPORT2 90 uprv_compareInvEbcdicAsAscii(const char *s1, const char *s2); 91 92 /** 93 * \def uprv_compareInvCharsAsAscii 94 * Compare two invariant-character strings in ASCII order. 95 * @internal 96 */ 97 #if U_CHARSET_FAMILY==U_ASCII_FAMILY 98 # define uprv_compareInvCharsAsAscii(s1, s2) uprv_strcmp(s1, s2) 99 #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY 100 # define uprv_compareInvCharsAsAscii(s1, s2) uprv_compareInvEbcdicAsAscii(s1, s2) 101 #else 102 # error Unknown charset family! 103 #endif 104 105 /** 106 * Converts an EBCDIC invariant character to lowercase ASCII. 107 * @internal 108 */ 109 U_INTERNAL char U_EXPORT2 110 uprv_ebcdicToLowercaseAscii(char c); 111 112 /** 113 * \def uprv_invCharToLowercaseAscii 114 * Converts an invariant character to lowercase ASCII. 115 * @internal 116 */ 117 #if U_CHARSET_FAMILY==U_ASCII_FAMILY 118 # define uprv_invCharToLowercaseAscii uprv_asciitolower 119 #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY 120 # define uprv_invCharToLowercaseAscii uprv_ebcdicToLowercaseAscii 121 #else 122 # error Unknown charset family! 123 #endif 124 125 /** 126 * Copy EBCDIC to ASCII 127 * @internal 128 * @see uprv_strncpy 129 */ 130 U_INTERNAL uint8_t* U_EXPORT2 131 uprv_aestrncpy(uint8_t *dst, const uint8_t *src, int32_t n); 132 133 134 /** 135 * Copy ASCII to EBCDIC 136 * @internal 137 * @see uprv_strncpy 138 */ 139 U_INTERNAL uint8_t* U_EXPORT2 140 uprv_eastrncpy(uint8_t *dst, const uint8_t *src, int32_t n); 141 142 143 144 #endif 145