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-2025 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.h>
14 #include <cwchar>
15 #include <ios>
16 
17 namespace std
18 {
19 
20 template<>
21 struct char_traits<pdftron::UInt32>
22 {
23  using char_type = pdftron::UInt32;
24  using int_type = unsigned int;
25  using off_type = std::streamoff;
26  using pos_type = std::fpos<std::mbstate_t>;
27  using state_type = std::mbstate_t;
28 
29 #if __cplusplus >= 201703L
30  static constexpr void assign(char_type& left, const char_type& right) noexcept
31 #elif __cplusplus >= 201103L
32  static void assign(char_type& left, const char_type& right) noexcept
33 #else
34  static void assign(char_type& left, const char_type& right)
35 #endif
36  {
37  left = right;
38  }
39 
40 #if __cplusplus >= 202002L
41  static constexpr char_type* assign(char_type* const first, std::size_t count, const char_type c)
42 #else
43  static char_type* assign(char_type* const first, std::size_t count, const char_type c)
44 #endif
45  {
46  for (char_type* next = first; count > 0; --count, ++next)
47  {
48  *next = c;
49  }
50 
51  return first;
52  }
53 
54 #if __cplusplus >= 201103L
55  static constexpr bool eq(const char_type left, const char_type right) noexcept
56 #else
57  static bool eq(const char_type left, const char_type right)
58 #endif
59  {
60  return left == right;
61  }
62 
63 #if __cplusplus >= 201103L
64  static constexpr bool lt(const char_type left, const char_type right) noexcept
65 #else
66  static bool lt(const char_type left, const char_type right)
67 #endif
68  {
69  return left < right;
70  }
71 
72 #if __cplusplus >= 202002L
73  static constexpr char_type* move(char_type* const dst, const char_type* const src, const std::size_t count)
74 #else
75  static char_type* move(char_type* const dst, const char_type* const src, const std::size_t count)
76 #endif
77  {
78  ::memmove(dst, src, count * sizeof(char_type));
79  return dst;
80  }
81 
82 #if __cplusplus >= 202002L
83  static constexpr char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
84 #else
85  static char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
86 #endif
87  {
88  ::memcpy(dst, src, count * sizeof(char_type));
89  return dst;
90  }
91 
92 #if __cplusplus >= 201703L
93  static constexpr int compare(const char_type* left, const char_type* right, std::size_t count)
94 #else
95  static int compare(const char_type* left, const char_type* right, std::size_t count)
96 #endif
97  {
98  for (; count > 0; --count, ++left, ++right)
99  {
100  if (!eq(*left, *right))
101  {
102  return lt(*left, *right) ? -1 : 1;
103  }
104  }
105 
106  return 0;
107  }
108 
109 #if __cplusplus >= 201703L
110  static constexpr std::size_t length(const char_type* str)
111 #else
112  static std::size_t length(const char_type* str)
113 #endif
114  {
115  std::size_t count = 0;
116  while (*str != 0)
117  {
118  ++count;
119  ++str;
120  }
121 
122  return count;
123  }
124 
125 #if __cplusplus >= 201703L
126  static constexpr const char_type* find(const char_type* str, std::size_t count, const char_type& c)
127 #else
128  static const char_type* find(const char_type* str, std::size_t count, const char_type& c)
129 #endif
130  {
131  for (; count > 0; --count, ++str)
132  {
133  if (*str == c)
134  {
135  return str;
136  }
137  }
138 
139  return nullptr;
140  }
141 
142 #if __cplusplus >= 201103L
143  static constexpr char_type to_char_type(const int_type i) noexcept
144 #else
145  static char_type to_char_type(const int_type i)
146 #endif
147  {
148  return static_cast<char_type>(i);
149  }
150 
151 #if __cplusplus >= 201103L
152  static constexpr int_type to_int_type(const char_type c) noexcept
153 #else
154  static int_type to_int_type(const char_type c)
155 #endif
156  {
157  return static_cast<int_type>(c);
158  }
159 
160 #if __cplusplus >= 201103L
161  static constexpr bool eq_int_type(const int_type left, const int_type right) noexcept
162 #else
163  static bool eq_int_type(const int_type left, const int_type right)
164 #endif
165  {
166  return left == right;
167  }
168 
169 #if __cplusplus >= 201103L
170  static constexpr int_type eof() noexcept
171 #else
172  static int_type eof()
173 #endif
174  {
175  return static_cast<int_type>(EOF);
176  }
177 
178 #if __cplusplus >= 201103L
179  static constexpr int_type not_eof(const int_type i) noexcept
180 #else
181  static int_type not_eof(const int_type i)
182 #endif
183  {
184  return i != eof() ? i : !eof();
185  }
186 };
187 
188 } // namespace std
189 
190 #endif
191 
192 #endif // PDFTRON_H_CPPCommonCharTraits
TRN_UInt32 UInt32
Definition: BasicTypes.h:13