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