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 #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  ::memmove(dst, src, count * sizeof(char_type));
87  return dst;
88  }
89 
90 #if __cplusplus >= 202002L
91  static constexpr char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
92 #else
93  static char_type* copy(char_type* const dst, const char_type* const src, const std::size_t count)
94 #endif
95  {
96  ::memcpy(dst, src, count * sizeof(char_type));
97  return dst;
98  }
99 
100 #if __cplusplus >= 201703L
101  static constexpr int compare(const char_type* left, const char_type* right, std::size_t count)
102 #else
103  static int compare(const char_type* left, const char_type* right, std::size_t count)
104 #endif
105  {
106  for (; count > 0; --count, ++left, ++right)
107  {
108  if (!eq(*left, *right))
109  {
110  return lt(*left, *right) ? -1 : 1;
111  }
112  }
113 
114  return 0;
115  }
116 
117 #if __cplusplus >= 201703L
118  static constexpr std::size_t length(const char_type* str)
119 #else
120  static std::size_t length(const char_type* str)
121 #endif
122  {
123  std::size_t count = 0;
124  while (*str != 0)
125  {
126  ++count;
127  ++str;
128  }
129 
130  return count;
131  }
132 
133 #if __cplusplus >= 201703L
134  static constexpr const char_type* find(const char_type* str, std::size_t count, const char_type& c)
135 #else
136  static const char_type* find(const char_type* str, std::size_t count, const char_type& c)
137 #endif
138  {
139  for (; count > 0; --count, ++str)
140  {
141  if (*str == c)
142  {
143  return str;
144  }
145  }
146 
147  return nullptr;
148  }
149 
150 #if __cplusplus >= 201103L
151  static constexpr char_type to_char_type(const int_type i) noexcept
152 #else
153  static char_type to_char_type(const int_type i)
154 #endif
155  {
156  return static_cast<char_type>(i);
157  }
158 
159 #if __cplusplus >= 201103L
160  static constexpr int_type to_int_type(const char_type c) noexcept
161 #else
162  static int_type to_int_type(const char_type c)
163 #endif
164  {
165  return static_cast<int_type>(c);
166  }
167 
168 #if __cplusplus >= 201103L
169  static constexpr bool eq_int_type(const int_type left, const int_type right) noexcept
170 #else
171  static bool eq_int_type(const int_type left, const int_type right)
172 #endif
173  {
174  return left == right;
175  }
176 
177 #if __cplusplus >= 201103L
178  static constexpr int_type eof() noexcept
179 #else
180  static int_type eof()
181 #endif
182  {
183  return static_cast<int_type>(EOF);
184  }
185 
186 #if __cplusplus >= 201103L
187  static constexpr int_type not_eof(const int_type i) noexcept
188 #else
189  static int_type not_eof(const int_type i)
190 #endif
191  {
192  return i != eof() ? i : !eof();
193  }
194 };
195 
196 } // namespace std
197 
198 #endif
199 
200 #endif // PDFTRON_H_CPPCommonCharTraits
TRN_UInt32 UInt32
Definition: BasicTypes.h:13