All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CharTraits.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 
6 #ifndef PDFTRON_H_CPPCommonCharTraits
7 #define PDFTRON_H_CPPCommonCharTraits
8 
9 #if defined(__apple_build_version__) && __apple_build_version__ >= 17000013
10 
11 #include <Common/BasicTypes.h>
12 
13 #include <string>
14 #include <cwchar>
15 #include <ios>
16 
17 namespace std
18 {
19 
20 template<>
21 struct char_traits<pdftron::UInt32>
22 {
23 #if __cplusplus >= 201103L
24  using char_type = pdftron::UInt32;
25  using int_type = unsigned int;
26  using off_type = std::streamoff;
27  using pos_type = std::fpos<std::mbstate_t>;
28  using state_type = std::mbstate_t;
29 #else
30  typedef pdftron::UInt32 char_type;
31  typedef unsigned int int_type;
32  typedef std::streamoff off_type;
33  typedef std::fpos<std::mbstate_t> pos_type;
34  typedef std::mbstate_t state_type;
35 #endif
36 
37 #if __cplusplus >= 201703L
38  static constexpr void assign(char_type& left, const char_type& right) noexcept
39 #elif __cplusplus >= 201103L
40  static void assign(char_type& left, const char_type& right) noexcept
41 #else
42  static void assign(char_type& left, const char_type& right)
43 #endif
44  {
45  left = right;
46  }
47 
48 #if __cplusplus >= 202002L
49  static constexpr char_type* assign(char_type* const first, std::size_t count, const char_type c)
50 #else
51  static char_type* assign(char_type* const first, std::size_t count, const char_type c)
52 #endif
53  {
54  for (char_type* next = first; count > 0; --count, ++next)
55  {
56  *next = c;
57  }
58 
59  return first;
60  }
61 
62 #if __cplusplus >= 201103L
63  static constexpr bool eq(const char_type left, const char_type right) noexcept
64 #else
65  static bool eq(const char_type left, const char_type right)
66 #endif
67  {
68  return left == right;
69  }
70 
71 #if __cplusplus >= 201103L
72  static constexpr bool lt(const char_type left, const char_type right) noexcept
73 #else
74  static bool lt(const char_type left, const char_type right)
75 #endif
76  {
77  return left < right;
78  }
79 
80 #if __cplusplus >= 202002L
81  static constexpr char_type* move(char_type* const dst, const char_type* const src, const std::size_t count)
82 #else
83  static char_type* move(char_type* const dst, const char_type* const src, const std::size_t count)
84 #endif
85  {
86  if(dst < src)
87  {
88  for(std::size_t i = 0; i < count; ++i)
89  {
90  dst[i] = src[i];
91  }
92  }
93  else if(dst > src)
94  {
95  for(std::size_t i = count; i-- > 0;)
96  {
97  dst[i] = src[i];
98  }
99  }
100 
101  return dst;
102  }
103 
104 #if __cplusplus >= 202002L
105  static constexpr char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
106 #else
107  static char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
108 #endif
109  {
110  for(std::size_t i = 0; i < count; ++i)
111  {
112  dst[i] = src[i];
113  }
114 
115  return dst;
116  }
117 
118 #if __cplusplus >= 201703L
119  static constexpr int compare(const char_type* left, const char_type* right, std::size_t count)
120 #else
121  static int compare(const char_type* left, const char_type* right, std::size_t count)
122 #endif
123  {
124  for (; count > 0; --count, ++left, ++right)
125  {
126  if (!eq(*left, *right))
127  {
128  return lt(*left, *right) ? -1 : 1;
129  }
130  }
131 
132  return 0;
133  }
134 
135 #if __cplusplus >= 201703L
136  static constexpr std::size_t length(const char_type* str)
137 #else
138  static std::size_t length(const char_type* str)
139 #endif
140  {
141  std::size_t count = 0;
142 
143  while (*str != 0)
144  {
145  ++count;
146  ++str;
147  }
148 
149  return count;
150  }
151 
152 #if __cplusplus >= 201703L
153  static constexpr const char_type* find(const char_type* str, std::size_t count, const char_type& c)
154 #else
155  static const char_type* find(const char_type* str, std::size_t count, const char_type& c)
156 #endif
157  {
158  for (; count > 0; --count, ++str)
159  {
160  if (*str == c)
161  {
162  return str;
163  }
164  }
165 
166  return nullptr;
167  }
168 
169 #if __cplusplus >= 201103L
170  static constexpr char_type to_char_type(const int_type i) noexcept
171 #else
172  static char_type to_char_type(const int_type i)
173 #endif
174  {
175  return static_cast<char_type>(i);
176  }
177 
178 #if __cplusplus >= 201103L
179  static constexpr int_type to_int_type(const char_type c) noexcept
180 #else
181  static int_type to_int_type(const char_type c)
182 #endif
183  {
184  return static_cast<int_type>(c);
185  }
186 
187 #if __cplusplus >= 201103L
188  static constexpr bool eq_int_type(const int_type left, const int_type right) noexcept
189 #else
190  static bool eq_int_type(const int_type left, const int_type right)
191 #endif
192  {
193  return left == right;
194  }
195 
196 #if __cplusplus >= 201103L
197  static constexpr int_type eof() noexcept
198 #else
199  static int_type eof()
200 #endif
201  {
202  return static_cast<int_type>(EOF);
203  }
204 
205 #if __cplusplus >= 201103L
206  static constexpr int_type not_eof(const int_type i) noexcept
207 #else
208  static int_type not_eof(const int_type i)
209 #endif
210  {
211  return i != eof() ? i : !eof();
212  }
213 };
214 
215 } // namespace std
216 
217 #endif
218 
219 #endif // PDFTRON_H_CPPCommonCharTraits
TRN_UInt32 UInt32
Definition: BasicTypes.h:13