0022797: Returning type Handle(Standard_Type)& should be changed to const Handle...
[occt.git] / src / Standard / Standard_Character.hxx
1 //============================================================================
2 //==== Titre: Standard_Character.hxx
3 //==== Role : The header file of primitve type "Character" from package 
4 //====        "Standard"
5 //==== 
6 //==== Implementation:  This is a primitive type implemented as typedef
7 //====        typedef char Standard_Character
8 //============================================================================
9
10 #ifndef _Standard_Character_HeaderFile
11 #define _Standard_Character_HeaderFile
12
13 #ifndef _Standard_ctype_HeaderFile
14 #include <Standard_ctype.hxx>
15 #endif
16
17 #include <string.h>
18
19 #ifndef _Standard_TypeDef_HeaderFile
20 #include <Standard_TypeDef.hxx>
21 #endif
22
23 class Handle_Standard_Type;
24
25 __Standard_API const Handle_Standard_Type& Standard_Character_Type_();
26
27 //class Standard_OStream;
28 //void ShallowDump (const Standard_Character, Standard_OStream& );
29 // =====================================
30 // Method implemented in Standard_Character.cxx
31 // =====================================
32 __Standard_API Standard_Integer   HashCode(const Standard_Character, const Standard_Integer);
33
34 // ===============================================
35 // Methods from Standard_Entity class which are redefined:  
36 //    - Hascode
37 //    - IsEqual
38 //    - IsSimilar
39 //    - Shallowcopy
40 //    - ShallowDump
41 // ===============================================
42
43 // ===============
44 // inline methods 
45 // ===============
46
47 // ------------------------------------------------------------------
48 // IsEqual : Returns Standard_True if two characters have the same value
49 // ------------------------------------------------------------------
50 inline Standard_Boolean IsEqual(const Standard_Character One,
51                                 const Standard_Character Two)
52 { return One == Two; }
53
54 // ------------------------------------------------------------------
55 // IsSimilar : Returns Standard_True if two characters have the same value
56 // ------------------------------------------------------------------
57 inline Standard_Boolean IsSimilar(const Standard_Character One, 
58                                   const Standard_Character Two)
59 { return One == Two; }
60
61 // ===============================================
62 // Character classification functions
63 //
64 // NOTE: Character classification routines in C standard library 
65 // (isdigit(), isalpha() etc.) have integer argument instead of char. 
66 // Therefore if character from extended Ascii part of char table
67 // (i.e. above 128) is passed into such functions it is converted 
68 // to int giving negative value (if characters are signed that
69 // is default for most compilers). 
70 // It can be dangerous since implementation of these C functions
71 // may use argument as index in the array without any checks 
72 // (for instance, in Microsoft VC++ -- see MSDN)
73 // To avoid this, we cast char to unsigned char when passing to these functions.
74 // ===============================================
75   
76 // ==================================================================
77 // IsAlphabetic : Returns Standard_True if a character is alphabetic
78 // ==================================================================
79 inline Standard_Boolean IsAlphabetic(const Standard_Character me) 
80 { return isalpha((unsigned char)me); }
81
82 // ==================================================================
83 // IsDigit : Returns Standard_True if a character is a digit
84 // ==================================================================
85 inline Standard_Boolean IsDigit(const Standard_Character me) 
86 { return isdigit((unsigned char)me); }
87
88 // ==================================================================
89 // IsXDigit : Returns Standard_True if a character is a digit
90 // ==================================================================
91 inline Standard_Boolean IsXDigit(const Standard_Character me) 
92 { return isxdigit((unsigned char)me); }
93
94 // ==================================================================
95 // IsAlphanumeric : Returns Standard_True if a character is alphanumeric
96 // ==================================================================
97 inline Standard_Boolean IsAlphanumeric(const Standard_Character me) 
98 { return (IsAlphabetic(me) || IsDigit(me)) ; }
99
100 // ==================================================================
101 // IsControl : Returns Standard_True if a character  is a control character
102 // ==================================================================
103 inline Standard_Boolean IsControl(const Standard_Character me) 
104 { return iscntrl((unsigned char)me); }
105
106
107 // ==================================================================
108 // IsGraphic : Returns Standard_True if a character is graphic
109 // ==================================================================
110 inline Standard_Boolean IsGraphic(const Standard_Character me) 
111 { return isgraph((unsigned char)me); }
112
113 // ==================================================================
114 // IsLowerCase : Returns Standard_True if a character is lowercase
115 // ==================================================================
116 inline Standard_Boolean IsLowerCase(const Standard_Character me) 
117 { return islower((unsigned char)me); }
118
119 // ==================================================================
120 // IsPrintable : Returns Standard_True if a character is printable
121 // ==================================================================
122 inline Standard_Boolean IsPrintable(const Standard_Character me) 
123 { return isprint((unsigned char)me); }
124
125 // ==================================================================
126 // IsPunctuation : Returns Standard_True if a character is a graphic and 
127 //                 not a alphanumeric character
128 // ==================================================================
129 inline Standard_Boolean IsPunctuation(const Standard_Character me) 
130 { return ( IsGraphic(me) && !IsAlphanumeric(me)); }
131
132 // ==================================================================
133 // IsSpace : Returns Standard_True if a character is a space
134 // ==================================================================
135 inline Standard_Boolean IsSpace(const Standard_Character me) 
136 { return isspace((unsigned char)me); }
137
138 // ==================================================================
139 // IsUppercase : Returns Standard_True if a character is uppercase
140 // ==================================================================
141 inline Standard_Boolean IsUpperCase(const Standard_Character me) 
142 { return isupper((unsigned char)me); }
143
144 // ==================================================================
145 // LowerCase : Returns a lowercase character
146 // ==================================================================
147 inline Standard_Character LowerCase(const Standard_Character me) 
148 { return (Standard_Character)(unsigned char)tolower(me); }
149
150 // ==================================================================
151 // UpperCase : Returns a uppercase character
152 // ==================================================================
153 inline Standard_Character UpperCase(const Standard_Character me) 
154 { return (Standard_Character)(unsigned char)toupper(me); }
155
156 // ------------------------------------------------------------------
157 // ShallowCopy : Make a copy of one Character
158 // ------------------------------------------------------------------
159 inline Standard_Character ShallowCopy (const Standard_Character me) 
160 { return me; }
161
162 #endif
163
164
165
166
167
168
169
170
171
172
173
174
175
176