Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-25 08:30:25

0001 // Copyright (c) 1998-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 //============================================================================
0016 //==== Title: Standard_Character.hxx
0017 //==== Role : The header file of primitive type "Character" from package "Standard"
0018 //====
0019 //==== Implementation:  This is a primitive type implemented as typedef
0020 //====        typedef char Standard_Character
0021 //============================================================================
0022 
0023 #ifndef _Standard_Character_HeaderFile
0024 #define _Standard_Character_HeaderFile
0025 
0026 #include <Standard_TypeDef.hxx>
0027 
0028 #include <cctype>
0029 
0030 // ------------------------------------------------------------------
0031 // IsEqual : Returns Standard_True if two characters have the same value
0032 // ------------------------------------------------------------------
0033 constexpr Standard_Boolean IsEqual(const Standard_Character One, const Standard_Character Two)
0034 {
0035   return One == Two;
0036 }
0037 
0038 // ===============================================
0039 // Character classification functions
0040 //
0041 // NOTE: Character classification routines in C standard library
0042 // (isdigit(), isalpha() etc.) have integer argument instead of char.
0043 // Therefore if character from extended Ascii part of char table
0044 // (i.e. above 128) is passed into such functions it is converted
0045 // to int giving negative value (if characters are signed that
0046 // is default for most compilers).
0047 // It can be dangerous since implementation of these C functions
0048 // may use argument as index in the array without any checks
0049 // (for instance, in Microsoft VC++ -- see MSDN)
0050 // To avoid this, we cast char to unsigned char when passing to these functions.
0051 // ===============================================
0052 
0053 // ==================================================================
0054 // IsAlphabetic : Returns Standard_True if a character is alphabetic
0055 // ==================================================================
0056 inline Standard_Boolean IsAlphabetic(const Standard_Character me)
0057 {
0058   return std::isalpha((unsigned char)me) != 0;
0059 }
0060 
0061 // ==================================================================
0062 // IsDigit : Returns Standard_True if a character is a digit
0063 // ==================================================================
0064 inline Standard_Boolean IsDigit(const Standard_Character me)
0065 {
0066   return std::isdigit((unsigned char)me) != 0;
0067 }
0068 
0069 // ==================================================================
0070 // IsXDigit : Returns Standard_True if a character is a digit
0071 // ==================================================================
0072 inline Standard_Boolean IsXDigit(const Standard_Character me)
0073 {
0074   return std::isxdigit((unsigned char)me) != 0;
0075 }
0076 
0077 // ==================================================================
0078 // IsAlphanumeric : Returns Standard_True if a character is alphanumeric
0079 // ==================================================================
0080 inline Standard_Boolean IsAlphanumeric(const Standard_Character me)
0081 {
0082   return (IsAlphabetic(me) || IsDigit(me));
0083 }
0084 
0085 // ==================================================================
0086 // IsControl : Returns Standard_True if a character  is a control character
0087 // ==================================================================
0088 inline Standard_Boolean IsControl(const Standard_Character me)
0089 {
0090   return std::iscntrl((unsigned char)me) != 0;
0091 }
0092 
0093 // ==================================================================
0094 // IsGraphic : Returns Standard_True if a character is graphic
0095 // ==================================================================
0096 inline Standard_Boolean IsGraphic(const Standard_Character me)
0097 {
0098   return std::isgraph((unsigned char)me) != 0;
0099 }
0100 
0101 // ==================================================================
0102 // IsLowerCase : Returns Standard_True if a character is lowercase
0103 // ==================================================================
0104 inline Standard_Boolean IsLowerCase(const Standard_Character me)
0105 {
0106   return std::islower((unsigned char)me) != 0;
0107 }
0108 
0109 // ==================================================================
0110 // IsPrintable : Returns Standard_True if a character is printable
0111 // ==================================================================
0112 inline Standard_Boolean IsPrintable(const Standard_Character me)
0113 {
0114   return std::isprint((unsigned char)me) != 0;
0115 }
0116 
0117 // ==================================================================
0118 // IsPunctuation : Returns Standard_True if a character is a graphic and
0119 //                 not a alphanumeric character
0120 // ==================================================================
0121 inline Standard_Boolean IsPunctuation(const Standard_Character me)
0122 {
0123   return (IsGraphic(me) && !IsAlphanumeric(me));
0124 }
0125 
0126 // ==================================================================
0127 // IsSpace : Returns Standard_True if a character is a space
0128 // ==================================================================
0129 inline Standard_Boolean IsSpace(const Standard_Character me)
0130 {
0131   return std::isspace((unsigned char)me) != 0;
0132 }
0133 
0134 // ==================================================================
0135 // IsUppercase : Returns Standard_True if a character is uppercase
0136 // ==================================================================
0137 inline Standard_Boolean IsUpperCase(const Standard_Character me)
0138 {
0139   return std::isupper((unsigned char)me) != 0;
0140 }
0141 
0142 // ==================================================================
0143 // LowerCase : Returns a lowercase character
0144 // ==================================================================
0145 inline Standard_Character LowerCase(const Standard_Character me)
0146 {
0147   return (Standard_Character)(unsigned char)std::tolower((unsigned char)me);
0148 }
0149 
0150 // ==================================================================
0151 // UpperCase : Returns a uppercase character
0152 // ==================================================================
0153 inline Standard_Character UpperCase(const Standard_Character me)
0154 {
0155   return (Standard_Character)(unsigned char)std::toupper((unsigned char)me);
0156 }
0157 
0158 #endif