0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[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 // ------------------------------------------------------------------
33 // IsEqual : Returns Standard_True if two characters have the same value
34 // ------------------------------------------------------------------
35 inline Standard_Boolean IsEqual(const Standard_Character One,
36                                 const Standard_Character Two)
37 { return One == Two; }
38
39 // ===============================================
40 // Character classification functions
41 //
42 // NOTE: Character classification routines in C standard library 
43 // (isdigit(), isalpha() etc.) have integer argument instead of char. 
44 // Therefore if character from extended Ascii part of char table
45 // (i.e. above 128) is passed into such functions it is converted 
46 // to int giving negative value (if characters are signed that
47 // is default for most compilers). 
48 // It can be dangerous since implementation of these C functions
49 // may use argument as index in the array without any checks 
50 // (for instance, in Microsoft VC++ -- see MSDN)
51 // To avoid this, we cast char to unsigned char when passing to these functions.
52 // ===============================================
53   
54 // ==================================================================
55 // IsAlphabetic : Returns Standard_True if a character is alphabetic
56 // ==================================================================
57 inline Standard_Boolean IsAlphabetic(const Standard_Character me) 
58 { return std::isalpha ((unsigned char)me) != 0; }
59
60 // ==================================================================
61 // IsDigit : Returns Standard_True if a character is a digit
62 // ==================================================================
63 inline Standard_Boolean IsDigit(const Standard_Character me) 
64 { return std::isdigit ((unsigned char)me) != 0; }
65
66 // ==================================================================
67 // IsXDigit : Returns Standard_True if a character is a digit
68 // ==================================================================
69 inline Standard_Boolean IsXDigit(const Standard_Character me) 
70 { return std::isxdigit((unsigned char)me) != 0; }
71
72 // ==================================================================
73 // IsAlphanumeric : Returns Standard_True if a character is alphanumeric
74 // ==================================================================
75 inline Standard_Boolean IsAlphanumeric(const Standard_Character me) 
76 { return (IsAlphabetic(me) || IsDigit(me)) ; }
77
78 // ==================================================================
79 // IsControl : Returns Standard_True if a character  is a control character
80 // ==================================================================
81 inline Standard_Boolean IsControl(const Standard_Character me) 
82 { return std::iscntrl((unsigned char)me) != 0; }
83
84
85 // ==================================================================
86 // IsGraphic : Returns Standard_True if a character is graphic
87 // ==================================================================
88 inline Standard_Boolean IsGraphic(const Standard_Character me) 
89 { return std::isgraph((unsigned char)me) != 0; }
90
91 // ==================================================================
92 // IsLowerCase : Returns Standard_True if a character is lowercase
93 // ==================================================================
94 inline Standard_Boolean IsLowerCase(const Standard_Character me) 
95 { return std::islower((unsigned char)me) != 0; }
96
97 // ==================================================================
98 // IsPrintable : Returns Standard_True if a character is printable
99 // ==================================================================
100 inline Standard_Boolean IsPrintable(const Standard_Character me) 
101 { return std::isprint((unsigned char)me) != 0; }
102
103 // ==================================================================
104 // IsPunctuation : Returns Standard_True if a character is a graphic and 
105 //                 not a alphanumeric character
106 // ==================================================================
107 inline Standard_Boolean IsPunctuation(const Standard_Character me) 
108 { return ( IsGraphic(me) && !IsAlphanumeric(me)); }
109
110 // ==================================================================
111 // IsSpace : Returns Standard_True if a character is a space
112 // ==================================================================
113 inline Standard_Boolean IsSpace(const Standard_Character me) 
114 { return std::isspace((unsigned char)me) != 0; }
115
116 // ==================================================================
117 // IsUppercase : Returns Standard_True if a character is uppercase
118 // ==================================================================
119 inline Standard_Boolean IsUpperCase(const Standard_Character me) 
120 { return std::isupper((unsigned char)me) != 0; }
121
122 // ==================================================================
123 // LowerCase : Returns a lowercase character
124 // ==================================================================
125 inline Standard_Character LowerCase(const Standard_Character me) 
126 { return (Standard_Character)(unsigned char)std::tolower((unsigned char)me); }
127
128 // ==================================================================
129 // UpperCase : Returns a uppercase character
130 // ==================================================================
131 inline Standard_Character UpperCase(const Standard_Character me) 
132 { return (Standard_Character)(unsigned char)std::toupper((unsigned char)me); }
133
134 #endif