Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
char.functions.cc
Go to the documentation of this file.
1 // Character Functions
2 //
3 // Project: Objexx Fortran Compatibility Library (ObjexxFCL)
4 //
5 // Version: 3.0.0
6 //
7 // Language: C++
8 //
9 // Copyright (c) 2000-2009 Objexx Engineering, Inc. All Rights Reserved.
10 // Use of this source code or any derivative of it is restricted by license.
11 // Licensing is available from Objexx Engineering, Inc.: http://objexx.com Objexx@objexx.com
12 
13 
14 // ObjexxFCL Headers
16 
17 // C++ Headers
18 #include <cctype>
19 #include <cstddef>
20 #include <cstring>
21 #include <string>
22 
23 
24 namespace ObjexxFCL {
25 
26 
27 // Constants
28 char const SPACE( ' ' );
29 
30 
31 // Predicate
32 
33 
34 /// @brief char == char Case-Optionally?
35 bool
36 equal( char const c, char const d, bool const exact_case )
37 {
38  if ( exact_case ) {
39  return ( c == d );
40  } else {
41  return ( std::tolower( c ) == std::tolower( d ) );
42  }
43 }
44 
45 
46 /// @brief char == char Case-Insensitively
47 bool
48 equali( char const c, char const d )
49 {
50  return ( std::tolower( c ) == std::tolower( d ) );
51 }
52 
53 
54 /// @brief Character is Blank?
55 bool
56 is_blank( char const c )
57 {
58  return ( c == SPACE );
59 }
60 
61 
62 /// @brief Character is Not Blank?
63 bool
64 not_blank( char const c )
65 {
66  return ( c != SPACE );
67 }
68 
69 
70 /// @brief Character is in a string?
71 bool
72 is_any_of( char const c, std::string const & s )
73 {
74  return ( s.find( c ) != std::string::npos );
75 }
76 
77 
78 /// @brief Character is in a cstring?
79 bool
80 is_any_of( char const c, c_cstring const s )
81 {
82  for ( std::size_t i = 0, e = std::strlen( s ); i < e; ++i ) {
83  if ( c == s[ i ] ) return true;
84  }
85  return false; // No matches
86 }
87 
88 
89 // Modifier
90 
91 
92 /// @brief Lowercase a Character
93 char &
94 lowercase( char & c )
95 {
96  c = std::tolower( c );
97  return c;
98 }
99 
100 
101 /// @brief Uppercase a Character
102 char &
103 uppercase( char & c )
104 {
105  c = std::toupper( c );
106  return c;
107 }
108 
109 
110 // Generator
111 
112 
113 /// @brief Lowercased Copy of a Character
114 char
115 lowercased( char const c )
116 {
117  return std::tolower( c );
118 }
119 
120 
121 /// @brief Uppercased Copy of a Character
122 char
123 uppercased( char const c )
124 {
125  return std::toupper( c );
126 }
127 
128 
129 } // namespace ObjexxFCL
bool not_blank(char const c)
Character is Not Blank?
char lowercased(char const c)
Lowercased Copy of a Character.
bool is_blank(char const c)
Character is Blank?
char & lowercase(char &c)
Lowercase a Character.
bool is_any_of(char const c, std::string const &s)
Character is in a string?
char const * c_cstring
bool equali(char const c, char const d)
char == char Case-Insensitively
bool equal(char const c, char const d, bool const exact_case)
char == char Case-Optionally?
char const SPACE( ' ')
char uppercased(char const c)
Uppercased Copy of a Character.
char & uppercase(char &c)
Uppercase a Character.