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