1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 //============================================================================
16 //==== Titre: Standard_Character.hxx
17 //==== Role : The header file of primitve type "Character" from package
20 //==== Implementation: This is a primitive type implemented as typedef
21 //==== typedef char Standard_Character
22 //============================================================================
24 #ifndef _Standard_Character_HeaderFile
25 #define _Standard_Character_HeaderFile
27 #include <Standard_TypeDef.hxx>
32 class Handle_Standard_Type;
34 __Standard_API const Handle_Standard_Type& Standard_Character_Type_();
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);
43 // ===============================================
44 // Methods from Standard_Entity class which are redefined:
50 // ===============================================
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; }
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; }
70 // ===============================================
71 // Character classification functions
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 // ===============================================
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); }
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); }
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); }
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)) ; }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
165 // ------------------------------------------------------------------
166 // ShallowCopy : Make a copy of one Character
167 // ------------------------------------------------------------------
168 inline Standard_Character ShallowCopy (const Standard_Character me)