PCL
CharTraits.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/CharTraits.h - Released 2024-01-13T15:47:58Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_CharTraits_h
53 #define __PCL_CharTraits_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/Utility.h>
61 
62 #include <ctype.h>
63 #include <memory.h>
64 #include <string.h>
65 
66 #ifdef __PCL_WINDOWS
67 # include <windows.h>
68 #else // POSIX
69 # include <wchar.h>
70 # include <wctype.h>
71 #endif // !__PCL_WINDOWS
72 
73 namespace pcl
74 {
75 
76 // ----------------------------------------------------------------------------
77 
78 char16_type PCL_FUNC PCL_ToCaseFolded( char16_type );
79 char16_type PCL_FUNC PCL_ToLowercase( char16_type );
80 char16_type PCL_FUNC PCL_ToUppercase( char16_type );
81 
82 extern const uint8* PCL_DATA PCL_toLowercaseLatin1;
83 extern const uint8* PCL_DATA PCL_toUppercaseLatin1;
84 
85 // ----------------------------------------------------------------------------
86 
98 // ----------------------------------------------------------------------------
99 
100 #define PCL_COMPARE_CODE_POINTS() \
101  PCL_PRECONDITION( n1 == 0 || n2 == 0 || s1 != nullptr && s2 != nullptr ) \
102  if ( caseSensitive ) \
103  { \
104  for ( size_type n = pcl::Min( n1, n2 ); n > 0; --n, ++s1, ++s2 ) \
105  if ( *s1 != *s2 ) \
106  return (*s1 < *s2) ? -1 : +1; \
107  } \
108  else \
109  { \
110  for ( size_type n = pcl::Min( n1, n2 ); n > 0; --n, ++s1, ++s2 ) \
111  { \
112  char_type c1 = ToCaseFolded( *s1 ), c2 = ToCaseFolded( *s2 ); \
113  if ( c1 != c2 ) \
114  return (c1 < c2) ? -1 : +1; \
115  } \
116  } \
117  return (n1 == n2) ? 0 : ((n1 < n2) ? -1 : +1)
118 
119 // ----------------------------------------------------------------------------
120 
121 /*
122  * Wildcard string matching algorithm adapted from:
123  *
124  * Kirk J. Krauss (2014): Matching Wildcards: An Empirical Way to Tame an
125  * Algorithm, Dr. Dobb's Magazine, October 7, 2014.
126  *
127  * http://www.drdobbs.com/architecture-and-design/matching-wildcards-an-empirical-way-to-t/240169123
128  */
129 
130 template <typename Tt, typename Tp> inline
131 bool WildMatch( const Tt* t, size_type nt, const Tp* p, size_type np )
132 {
133  PCL_PRECONDITION( nt == 0 || np == 0 || t != nullptr && p != nullptr )
134 
135  if ( nt == 0 || np == 0 )
136  return false;
137 
138  const Tt* et = t + nt;
139  const Tp* ep = p + np;
140  const Tt* bt = nullptr;
141  const Tp* bp = nullptr;
142 
143  for ( ;; )
144  {
145  Tp c = *p;
146 
147  if ( c == Tp( '*' ) )
148  {
149  do
150  if ( ++p == ep )
151  return true;
152  while ( (c = *p) == Tp( '*' ) );
153 
154  if ( c != Tp( '?' ) )
155  while ( Tt( c ) != *t )
156  if ( ++t == et )
157  return false;
158 
159  bp = p;
160  bt = t;
161  }
162  else if ( Tt( c ) != *t && c != Tp( '?' ) )
163  {
164  if ( bp != nullptr )
165  {
166  if ( p != bp )
167  {
168  p = bp;
169 
170  if ( Tt( *p ) != *t )
171  {
172  t = ++bt;
173  continue;
174  }
175 
176  ++p;
177  }
178 
179  if ( t < et )
180  {
181  ++t;
182  continue;
183  }
184  }
185 
186  return false;
187  }
188 
189  ++t;
190  ++p;
191 
192  if ( t == et )
193  {
194  if ( p == ep )
195  return true;
196 
197  while ( *p == Tp( '*' ) )
198  if ( ++p == ep )
199  return true;
200 
201  return false;
202  }
203  }
204 }
205 
206 template <typename Tt, typename Tp, class Ut, class Up> inline
207 bool WildMatchIC( const Tt* t, size_type nt, const Tp* p, size_type np, Ut ut, Up up )
208 {
209  PCL_PRECONDITION( nt == 0 || np == 0 || t != nullptr && p != nullptr && ut != nullptr && up != nullptr )
210 
211  if ( nt == 0 || np == 0 )
212  return false;
213 
214  const Tt* et = t + nt;
215  const Tp* ep = p + np;
216  const Tt* bt = nullptr;
217  const Tp* bp = nullptr;
218 
219  for ( ;; )
220  {
221  Tp c = *p;
222 
223  if ( c == Tp( '*' ) )
224  {
225  do
226  if ( ++p == ep )
227  return true;
228  while ( (c = *p) == Tp( '*' ) );
229 
230  if ( c != Tp( '?' ) )
231  {
232  c = up( c );
233  while ( Tt( c ) != ut( *t ) )
234  if ( ++t == et )
235  return false;
236  }
237 
238  bp = p;
239  bt = t;
240  }
241  else if ( c != Tp( '?' ) )
242  {
243  Tt ft = ut( *t );
244 
245  if ( Tt( up( c ) ) != ft )
246  {
247  if ( bp != nullptr )
248  {
249  if ( p != bp )
250  {
251  p = bp;
252 
253  if ( Tt( up( *p ) ) != ft )
254  {
255  t = ++bt;
256  continue;
257  }
258 
259  ++p;
260  }
261 
262  if ( t < et )
263  {
264  ++t;
265  continue;
266  }
267  }
268 
269  return false;
270  }
271  }
272 
273  ++t;
274  ++p;
275 
276  if ( t == et )
277  {
278  if ( p == ep )
279  return true;
280 
281  while ( *p == Tp( '*' ) )
282  if ( ++p == ep )
283  return true;
284 
285  return false;
286  }
287  }
288 }
289 
290 // ----------------------------------------------------------------------------
291 
314 template <typename T>
315 class PCL_CLASS GenericCharTraits
316 {
317 public:
318 
322  using char_type = T;
323 
327  static constexpr size_type BytesPerChar() noexcept
328  {
329  return sizeof( char_type );
330  }
331 
339  static size_type Length( const char_type* s ) noexcept
340  {
341  const char_type* __restrict__ t = s;
342  if ( s != nullptr )
343  for ( ; *t != Null(); ++t ) {}
344  return size_type( t - s );
345  }
346 
354  static void Fill( char_type* __restrict__ s, char_type c, size_type n ) noexcept
355  {
356  PCL_PRECONDITION( n == 0 || s != nullptr )
357  for ( ; n > 0; --n )
358  *s++ = c;
359  }
360 
372  static void Copy( char_type* __restrict__ dst, const char_type* __restrict__ src, size_type n ) noexcept
373  {
374  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
375  ::memcpy( dst, src, n*sizeof( char_type ) );
376  }
377 
386  static void CopyOverlapped( char_type* dst, const char_type* src, size_type n ) noexcept
387  {
388  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
389  ::memmove( dst, src, n*sizeof( char_type ) );
390  }
391 
418  static int CompareCodePoints( const char_type* __restrict__ s1, size_type n1,
419  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true ) noexcept
420  {
421  PCL_COMPARE_CODE_POINTS();
422  }
423 
456  static int Compare( const char_type* __restrict__ s1, size_type n1,
457  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true, bool localeAware = true ) noexcept
458  {
459  return CompareCodePoints( s1, n1, s2, n2, caseSensitive );
460  }
461 
484  static bool WildMatch( const char_type* __restrict__ t, size_type nt,
485  const char_type* __restrict__ p, size_type np, bool caseSensitive = true ) noexcept
486  {
487  if ( caseSensitive )
488  return pcl::WildMatch( t, nt, p, np );
489  return pcl::WildMatchIC( t, nt, p, np, ToCaseFolded, ToCaseFolded );
490  }
491 
503  static char_type ToCaseFolded( char_type c ) noexcept
504  {
505  return ToLowercase( c );
506  }
507 
515  static constexpr char_type ToLowercase( char_type c ) noexcept
516  {
517  return (c >= char_type( 65 ) && c <= char_type( 90 )
518  || c >= char_type( 192 ) && c <= char_type( 214 )
519  || c >= char_type( 216 ) && c <= char_type( 222 )) ? c + 32 : c;
520  }
521 
529  static constexpr char_type ToUppercase( char_type c ) noexcept
530  {
531  return (c >= char_type( 97 ) && c <= char_type( 122 )
532  || c >= char_type( 224 ) && c <= char_type( 246 )
533  || c >= char_type( 248 ) && c <= char_type( 254 )) ? c - 32 : c;
534  }
535 
543  static void ToLowercase( char_type* __restrict__ s, size_type n ) noexcept
544  {
545  PCL_PRECONDITION( n == 0 || s != nullptr )
546  for ( ; n > 0; --n, ++s )
547  *s = ToLowercase( *s );
548  }
549 
557  static void ToUppercase( char_type* __restrict__ s, size_type n ) noexcept
558  {
559  PCL_PRECONDITION( n == 0 || s != nullptr )
560  for ( ; n > 0; --n, ++s )
561  *s = ToUppercase( *s );
562  }
563 
567  static constexpr char_type Null() noexcept
568  {
569  return char_type( 0 );
570  }
571 
575  static constexpr char_type Blank() noexcept
576  {
577  return char_type( ' ' );
578  }
579 
583  static constexpr char_type Tab() noexcept
584  {
585  return char_type( '\t' );
586  }
587 
591  static constexpr char_type CR() noexcept
592  {
593  return char_type( '\r' );
594  }
595 
599  static constexpr char_type LF() noexcept
600  {
601  return char_type( '\n' );
602  }
603 
607  static constexpr char_type Comma() noexcept
608  {
609  return char_type( ',' );
610  }
611 
615  static constexpr char_type Colon() noexcept
616  {
617  return char_type( ':' );
618  }
619 
623  static constexpr char_type Semicolon() noexcept
624  {
625  return char_type( ';' );
626  }
627 
631  static constexpr char_type Hyphen() noexcept
632  {
633  return char_type( '-' );
634  }
635 
639  static constexpr char_type PlusSign() noexcept
640  {
641  return char_type( '+' );
642  }
643 
647  static constexpr char_type MinusSign() noexcept
648  {
649  return char_type( '-' );
650  }
651 
655  static constexpr char_type DecimalSeparator() noexcept
656  {
657  return char_type( '.' );
658  }
659 
663  static constexpr char_type ExponentDelimiter() noexcept
664  {
665  return char_type( 'e' );
666  }
667 
671  static constexpr char_type Underscore() noexcept
672  {
673  return char_type( '_' );
674  }
675 
679  static constexpr char_type SingleQuote() noexcept
680  {
681  return char_type( '\'' );
682  }
683 
687  static constexpr char_type DoubleQuote() noexcept
688  {
689  return char_type( '\"' );
690  }
691 
695  static constexpr bool IsNull( char_type c ) noexcept
696  {
697  return c == Null();
698  }
699 
703  static constexpr bool IsSpace( char_type c ) noexcept
704  {
705  return c == Blank() || c == Tab() || c == CR() || c == LF();
706  }
707 
712  static constexpr bool IsTrimable( char_type c ) noexcept
713  {
714  return IsSpace( c );
715  }
716 
721  static constexpr bool IsDigit( char_type c ) noexcept
722  {
723  return c >= char_type( '0' ) && c <= char_type( '9' );
724  }
725 
730  static constexpr bool IsHexDigit( char_type c ) noexcept
731  {
732  return IsDigit( c ) || c >= char_type( 'A' ) && c <= char_type( 'F' ) ||
733  c >= char_type( 'a' ) && c <= char_type( 'f' );
734  }
735 
739  static constexpr bool IsAlpha( char_type c ) noexcept
740  {
741  return IsLowercaseAlpha( c ) || IsUppercaseAlpha( c );
742  }
743 
747  static constexpr bool IsLowercaseAlpha( char_type c ) noexcept
748  {
749  return c >= char_type( 'a' ) && c <= char_type( 'z' );
750  }
751 
755  static constexpr bool IsUppercaseAlpha( char_type c ) noexcept
756  {
757  return c >= char_type( 'A' ) && c <= char_type( 'Z' );
758  }
759 
763  static constexpr bool IsUnderscore( char_type c ) noexcept
764  {
765  return c == Underscore();
766  }
767 
772  static constexpr bool IsSymbolDigit( char_type c ) noexcept
773  {
774  return IsAlpha( c ) || IsDigit( c ) || IsUnderscore( c );
775  }
776 
781  static constexpr bool IsStartingSymbolDigit( char_type c ) noexcept
782  {
783  return IsAlpha( c ) || IsUnderscore( c );
784  }
785 
789  static constexpr bool IsSign( char_type c ) noexcept
790  {
791  return c == MinusSign() || c == PlusSign();
792  }
793 
797  static constexpr bool IsDecimalSeparator( char_type c ) noexcept
798  {
799  return c == DecimalSeparator();
800  }
801 
807  static constexpr bool IsExponentDelimiter( char_type c ) noexcept
808  {
809  return c == char_type( 'e' ) || c == char_type( 'E' ) || c == char_type( 'd' ) || c == char_type( 'D' );
810  }
811 
816  static constexpr bool IsWildcard( char_type c ) noexcept
817  {
818  return c == char_type( '*' ) || c == char_type( '?' );
819  }
820 
825  template <typename Ptr1, typename Ptr2>
826  static Ptr1 SearchTrimLeft( Ptr1 i, Ptr2 j ) noexcept
827  {
828  for ( ; i < j && IsTrimable( *i ); ++i ) {}
829  return i;
830  }
831 
840  template <typename Ptr1, typename Ptr2>
841  static Ptr2 SearchTrimRight( Ptr1 i, Ptr2 j ) noexcept
842  {
843  for ( ; i < j && IsTrimable( *(j-1) ); --j ) {}
844  return j;
845  }
846 };
847 
848 // ----------------------------------------------------------------------------
849 
858 class PCL_CLASS IsoCharTraits : public GenericCharTraits<char>
859 {
860 public:
861 
866 
871 
879  static constexpr size_type Length( const char_type* __restrict__ s ) noexcept
880  {
881  return (s != nullptr) ? ::strlen( s ) : 0;
882  }
883 
891  static void Fill( char_type* __restrict__ s, char_type c, size_type n ) noexcept
892  {
893  PCL_PRECONDITION( n == 0 || s != nullptr )
894  ::memset( s, c, n );
895  }
896 
908  static void Copy( char_type* __restrict__ dst, const char_type* __restrict__ src, size_type n ) noexcept
909  {
910  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
911  ::memcpy( dst, src, n );
912  }
913 
922  static void CopyOverlapped( char_type* dst, const char_type* src, size_type n ) noexcept
923  {
924  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
925  ::memmove( dst, src, n );
926  }
927 
948  static int CompareCodePoints( const char_type* __restrict__ s1, size_type n1,
949  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true ) noexcept
950  {
951  PCL_COMPARE_CODE_POINTS();
952  }
953 
1009  static int Compare( const char_type* __restrict__ s1, size_type n1,
1010  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true, bool localeAware = true ) noexcept;
1011 
1034  static bool WildMatch( const char_type* __restrict__ t, size_type nt,
1035  const char_type* __restrict__ p, size_type np, bool caseSensitive = true ) noexcept
1036  {
1037  if ( caseSensitive )
1038  return pcl::WildMatch( t, nt, p, np );
1039  return pcl::WildMatchIC( t, nt, p, np,
1040  []( char_type c ) { return ToCaseFolded( c ); },
1041  []( char_type c ) { return ToCaseFolded( c ); } );
1042  }
1043 
1054  static char_type ToCaseFolded( char_type c ) noexcept
1055  {
1056  return ToLowercase( c );
1057  }
1058 
1063  static char_type ToLowercase( char_type c ) noexcept
1064  {
1065  return char_type( PCL_toLowercaseLatin1[uint8( c )] );
1066  }
1067 
1072  static char_type ToUppercase( char_type c ) noexcept
1073  {
1074  return char_type( PCL_toUppercaseLatin1[uint8( c )] );
1075  }
1076 
1080  static void ToCaseFolded( char_type* s, size_type n ) noexcept
1081  {
1082  PCL_PRECONDITION( n == 0 || s != nullptr )
1083  for ( ; n > 0; --n, ++s )
1084  *s = ToCaseFolded( *s );
1085  }
1086 
1090  static void ToLowercase( char_type* s, size_type n ) noexcept
1091  {
1092  PCL_PRECONDITION( n == 0 || s != nullptr )
1093  for ( ; n > 0; --n, ++s )
1094  *s = ToLowercase( *s );
1095  }
1096 
1100  static void ToUppercase( char_type* s, size_type n ) noexcept
1101  {
1102  PCL_PRECONDITION( n == 0 || s != nullptr )
1103  for ( ; n > 0; --n, ++s )
1104  *s = ToUppercase( *s );
1105  }
1106 };
1107 
1108 // ----------------------------------------------------------------------------
1109 
1118 class PCL_CLASS CharTraits : public GenericCharTraits<char16_type>
1119 {
1120 public:
1121 
1126 
1131 
1139  static size_type Length( const char_type* __restrict__ s ) noexcept
1140  {
1141 #ifdef __PCL_WINDOWS
1142  return (s != nullptr) ? ::wcslen( reinterpret_cast<const wchar_t*>( s ) ) : 0u;
1143 #else
1144  return traits_base::Length( s );
1145 #endif
1146  }
1147 
1159  static void Copy( char_type* __restrict__ dst, const char_type* __restrict__ src, size_type n ) noexcept
1160  {
1161  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
1162  ::memcpy( dst, src, n << 1 );
1163  }
1164 
1173  static void CopyOverlapped( char_type* dst, const char_type* src, size_type n ) noexcept
1174  {
1175  PCL_PRECONDITION( n == 0 || dst != nullptr && src != nullptr )
1176  ::memmove( dst, src, n << 1 );
1177  }
1178 
1199  static int CompareCodePoints( const char_type* __restrict__ s1, size_type n1,
1200  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true ) noexcept
1201  {
1202  PCL_COMPARE_CODE_POINTS();
1203  }
1204 
1260  static int Compare( const char_type* __restrict__ s1, size_type n1,
1261  const char_type* __restrict__ s2, size_type n2, bool caseSensitive = true, bool localeAware = true ) noexcept;
1262 
1285  static bool WildMatch( const char_type* __restrict__ t, size_type nt,
1286  const char_type* __restrict__ p, size_type np, bool caseSensitive = true ) noexcept
1287  {
1288  if ( caseSensitive )
1289  return pcl::WildMatch( t, nt, p, np );
1290  return pcl::WildMatchIC( t, nt, p, np,
1291  []( char_type c ) { return ToCaseFolded( c ); },
1292  []( char_type c ) { return ToCaseFolded( c ); } );
1293  }
1294 
1299  static bool WildMatch( const char_type* __restrict__ t, size_type nt,
1300  const char* __restrict__ p, size_type np, bool caseSensitive = true ) noexcept
1301  {
1302  if ( caseSensitive )
1303  return pcl::WildMatch( t, nt, p, np );
1304  return pcl::WildMatchIC( t, nt, p, np,
1305  []( char_type c ) { return ToCaseFolded( c ); },
1306  []( char c ) { return IsoCharTraits::ToCaseFolded( c ); } );
1307  }
1308 
1320  static char_type ToCaseFolded( char_type c ) noexcept
1321  {
1322  if ( c < 256 )
1323  {
1324  if ( c >= 65 && c <= 90 || c >= 192 && c <= 214 || c >= 216 && c <= 222 )
1325  return c + 32;
1326  return c;
1327  }
1328  return PCL_ToCaseFolded( c );
1329  }
1330 
1335  static char_type ToLowercase( char_type c ) noexcept
1336  {
1337  if ( c < 256 )
1338  {
1339  if ( c >= 65 && c <= 90 || c >= 192 && c <= 214 || c >= 216 && c <= 222 )
1340  return c + 32;
1341  return c;
1342  }
1343  return PCL_ToLowercase( c );
1344  }
1345 
1350  static char_type ToUppercase( char_type c ) noexcept
1351  {
1352  if ( c < 256 )
1353  {
1354  if ( c >= 97 && c <= 122 || c >= 224 && c <= 246 || c >= 248 && c <= 254 )
1355  return c - 32;
1356  return c;
1357  }
1358  return PCL_ToUppercase( c );
1359  }
1360 
1364  static void ToCaseFolded( char_type* s, size_type n ) noexcept
1365  {
1366  PCL_PRECONDITION( n == 0 || s != nullptr )
1367  for ( ; n > 0; --n, ++s )
1368  *s = ToCaseFolded( *s );
1369  }
1370 
1374  static void ToLowercase( char_type* s, size_type n ) noexcept
1375  {
1376  PCL_PRECONDITION( n == 0 || s != nullptr )
1377  for ( ; n > 0; --n, ++s )
1378  *s = ToLowercase( *s );
1379  }
1380 
1384  static void ToUppercase( char_type* s, size_type n ) noexcept
1385  {
1386  PCL_PRECONDITION( n == 0 || s != nullptr )
1387  for ( ; n > 0; --n, ++s )
1388  *s = ToUppercase( *s );
1389  }
1390 
1397  static constexpr bool IsHighSurrogate( char_type c16 ) noexcept
1398  {
1399  return (c16 & 0xFC00) == 0xD800;
1400  }
1401 
1408  static constexpr char_type HighSurrogate( char32_type c32 ) noexcept
1409  {
1410  return char_type( (c32 >> 10) + 0xD7C0 );
1411  }
1412 
1419  static constexpr bool IsLowSurrogate( char_type c16 ) noexcept
1420  {
1421  return (c16 & 0xFC00) == 0xDC00;
1422  }
1423 
1430  static constexpr char_type LowSurrogate( char32_type c32 ) noexcept
1431  {
1432  return char_type( (c32%0x400) + 0xDC00 );
1433  }
1434 
1440  static constexpr char32_type SurrogatePairToUTF32( char_type high, char_type low ) noexcept
1441  {
1442  return (char32_type( high ) << 10) + low - 0x035FDC00;
1443  }
1444 };
1445 
1446 // ----------------------------------------------------------------------------
1447 
1448 } // pcl
1449 
1450 #endif // __PCL_CharTraits_h
1451 
1452 // ----------------------------------------------------------------------------
1453 // EOF pcl/CharTraits.h - Released 2024-01-13T15:47:58Z
pcl::GenericCharTraits::IsSign
static constexpr bool IsSign(char_type c) noexcept
Definition: CharTraits.h:789
pcl::IsoCharTraits::ToCaseFolded
static void ToCaseFolded(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1080
pcl::GenericCharTraits::Semicolon
static constexpr char_type Semicolon() noexcept
Definition: CharTraits.h:623
pcl::CharTraits::IsLowSurrogate
static constexpr bool IsLowSurrogate(char_type c16) noexcept
Definition: CharTraits.h:1419
pcl::GenericCharTraits::ToLowercase
static constexpr char_type ToLowercase(char_type c) noexcept
Definition: CharTraits.h:515
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::GenericCharTraits::Comma
static constexpr char_type Comma() noexcept
Definition: CharTraits.h:607
pcl::GenericCharTraits::SearchTrimRight
static Ptr2 SearchTrimRight(Ptr1 i, Ptr2 j) noexcept
Definition: CharTraits.h:841
pcl::GenericCharTraits::IsTrimable
static constexpr bool IsTrimable(char_type c) noexcept
Definition: CharTraits.h:712
pcl::GenericCharTraits::Tab
static constexpr char_type Tab() noexcept
Definition: CharTraits.h:583
pcl::CharTraits::Copy
static void Copy(char_type *__restrict__ dst, const char_type *__restrict__ src, size_type n) noexcept
Definition: CharTraits.h:1159
pcl::IsoCharTraits::Length
static constexpr size_type Length(const char_type *__restrict__ s) noexcept
Definition: CharTraits.h:879
pcl::GenericCharTraits::IsExponentDelimiter
static constexpr bool IsExponentDelimiter(char_type c) noexcept
Definition: CharTraits.h:807
pcl::GenericCharTraits::ToLowercase
static void ToLowercase(char_type *__restrict__ s, size_type n) noexcept
Definition: CharTraits.h:543
pcl::GenericCharTraits::ToUppercase
static void ToUppercase(char_type *__restrict__ s, size_type n) noexcept
Definition: CharTraits.h:557
pcl::IsoCharTraits::Fill
static void Fill(char_type *__restrict__ s, char_type c, size_type n) noexcept
Definition: CharTraits.h:891
pcl::CharTraits::ToCaseFolded
static char_type ToCaseFolded(char_type c) noexcept
Definition: CharTraits.h:1320
pcl::GenericCharTraits::IsDigit
static constexpr bool IsDigit(char_type c) noexcept
Definition: CharTraits.h:721
pcl::char32_type
uint32 char32_type
Definition: Defs.h:1150
pcl::CharTraits::LowSurrogate
static constexpr char_type LowSurrogate(char32_type c32) noexcept
Definition: CharTraits.h:1430
Utility.h
pcl::CharTraits::SurrogatePairToUTF32
static constexpr char32_type SurrogatePairToUTF32(char_type high, char_type low) noexcept
Definition: CharTraits.h:1440
pcl::IsoCharTraits::ToUppercase
static void ToUppercase(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1100
pcl::GenericCharTraits::IsNull
static constexpr bool IsNull(char_type c) noexcept
Definition: CharTraits.h:695
pcl::GenericCharTraits::DecimalSeparator
static constexpr char_type DecimalSeparator() noexcept
Definition: CharTraits.h:655
pcl::GenericCharTraits::PlusSign
static constexpr char_type PlusSign() noexcept
Definition: CharTraits.h:639
pcl::GenericCharTraits::IsDecimalSeparator
static constexpr bool IsDecimalSeparator(char_type c) noexcept
Definition: CharTraits.h:797
pcl::GenericCharTraits::Compare
static int Compare(const char_type *__restrict__ s1, size_type n1, const char_type *__restrict__ s2, size_type n2, bool caseSensitive=true, bool localeAware=true) noexcept
Definition: CharTraits.h:456
pcl::GenericCharTraits::IsSpace
static constexpr bool IsSpace(char_type c) noexcept
Definition: CharTraits.h:703
pcl::IsoCharTraits::char_type
traits_base::char_type char_type
Definition: CharTraits.h:870
pcl::GenericCharTraits::SearchTrimLeft
static Ptr1 SearchTrimLeft(Ptr1 i, Ptr2 j) noexcept
Definition: CharTraits.h:826
pcl::GenericCharTraits::DoubleQuote
static constexpr char_type DoubleQuote() noexcept
Definition: CharTraits.h:687
pcl::GenericCharTraits::IsUnderscore
static constexpr bool IsUnderscore(char_type c) noexcept
Definition: CharTraits.h:763
pcl::GenericCharTraits::BytesPerChar
static constexpr size_type BytesPerChar() noexcept
Definition: CharTraits.h:327
pcl::CharTraits::IsHighSurrogate
static constexpr bool IsHighSurrogate(char_type c16) noexcept
Definition: CharTraits.h:1397
pcl::IsoCharTraits::ToCaseFolded
static char_type ToCaseFolded(char_type c) noexcept
Definition: CharTraits.h:1054
pcl::CharTraits::char_type
traits_base::char_type char_type
Definition: CharTraits.h:1130
pcl::GenericCharTraits::IsWildcard
static constexpr bool IsWildcard(char_type c) noexcept
Definition: CharTraits.h:816
pcl::GenericCharTraits::IsSymbolDigit
static constexpr bool IsSymbolDigit(char_type c) noexcept
Definition: CharTraits.h:772
pcl::GenericCharTraits::IsAlpha
static constexpr bool IsAlpha(char_type c) noexcept
Definition: CharTraits.h:739
pcl::Compare
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
Definition: Utility.h:639
pcl::CharTraits::WildMatch
static bool WildMatch(const char_type *__restrict__ t, size_type nt, const char *__restrict__ p, size_type np, bool caseSensitive=true) noexcept
Definition: CharTraits.h:1299
pcl::GenericCharTraits::Colon
static constexpr char_type Colon() noexcept
Definition: CharTraits.h:615
pcl::IsoCharTraits::ToLowercase
static char_type ToLowercase(char_type c) noexcept
Definition: CharTraits.h:1063
pcl::size_type
size_t size_type
Definition: Defs.h:612
pcl::GenericCharTraits::CR
static constexpr char_type CR() noexcept
Definition: CharTraits.h:591
pcl::CharTraits::ToUppercase
static char_type ToUppercase(char_type c) noexcept
Definition: CharTraits.h:1350
pcl::CharTraits::CompareCodePoints
static int CompareCodePoints(const char_type *__restrict__ s1, size_type n1, const char_type *__restrict__ s2, size_type n2, bool caseSensitive=true) noexcept
Definition: CharTraits.h:1199
pcl::GenericCharTraits::MinusSign
static constexpr char_type MinusSign() noexcept
Definition: CharTraits.h:647
pcl::GenericCharTraits::ToCaseFolded
static char_type ToCaseFolded(char_type c) noexcept
Definition: CharTraits.h:503
pcl::uint8
unsigned char uint8
Definition: Defs.h:645
pcl::GenericCharTraits::Null
static constexpr char_type Null() noexcept
Definition: CharTraits.h:567
pcl::GenericCharTraits::IsStartingSymbolDigit
static constexpr bool IsStartingSymbolDigit(char_type c) noexcept
Definition: CharTraits.h:781
pcl::GenericCharTraits::IsLowercaseAlpha
static constexpr bool IsLowercaseAlpha(char_type c) noexcept
Definition: CharTraits.h:747
pcl::CharTraits
A template instantiation of GenericCharTraits for char16_type.
Definition: CharTraits.h:1118
pcl::IsoCharTraits::CopyOverlapped
static void CopyOverlapped(char_type *dst, const char_type *src, size_type n) noexcept
Definition: CharTraits.h:922
pcl::CharTraits::ToUppercase
static void ToUppercase(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1384
pcl::GenericCharTraits::Underscore
static constexpr char_type Underscore() noexcept
Definition: CharTraits.h:671
pcl::CharTraits::ToLowercase
static void ToLowercase(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1374
pcl::GenericCharTraits::Fill
static void Fill(char_type *__restrict__ s, char_type c, size_type n) noexcept
Definition: CharTraits.h:354
pcl::GenericCharTraits::LF
static constexpr char_type LF() noexcept
Definition: CharTraits.h:599
pcl::CharTraits::HighSurrogate
static constexpr char_type HighSurrogate(char32_type c32) noexcept
Definition: CharTraits.h:1408
pcl::GenericCharTraits::ExponentDelimiter
static constexpr char_type ExponentDelimiter() noexcept
Definition: CharTraits.h:663
pcl::IsoCharTraits::CompareCodePoints
static int CompareCodePoints(const char_type *__restrict__ s1, size_type n1, const char_type *__restrict__ s2, size_type n2, bool caseSensitive=true) noexcept
Definition: CharTraits.h:948
pcl::GenericCharTraits::SingleQuote
static constexpr char_type SingleQuote() noexcept
Definition: CharTraits.h:679
pcl::CharTraits::ToCaseFolded
static void ToCaseFolded(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1364
pcl::GenericCharTraits::Copy
static void Copy(char_type *__restrict__ dst, const char_type *__restrict__ src, size_type n) noexcept
Definition: CharTraits.h:372
pcl::IsoCharTraits::ToUppercase
static char_type ToUppercase(char_type c) noexcept
Definition: CharTraits.h:1072
pcl::GenericCharTraits::Blank
static constexpr char_type Blank() noexcept
Definition: CharTraits.h:575
pcl::GenericCharTraits::CopyOverlapped
static void CopyOverlapped(char_type *dst, const char_type *src, size_type n) noexcept
Definition: CharTraits.h:386
pcl::IsoCharTraits
A template instantiation of GenericCharTraits for the char type.
Definition: CharTraits.h:858
pcl::CharTraits::Length
static size_type Length(const char_type *__restrict__ s) noexcept
Definition: CharTraits.h:1139
pcl::GenericCharTraits::IsHexDigit
static constexpr bool IsHexDigit(char_type c) noexcept
Definition: CharTraits.h:730
pcl::GenericCharTraits::WildMatch
static bool WildMatch(const char_type *__restrict__ t, size_type nt, const char_type *__restrict__ p, size_type np, bool caseSensitive=true) noexcept
Definition: CharTraits.h:484
pcl::GenericCharTraits::CompareCodePoints
static int CompareCodePoints(const char_type *__restrict__ s1, size_type n1, const char_type *__restrict__ s2, size_type n2, bool caseSensitive=true) noexcept
Definition: CharTraits.h:418
pcl::GenericCharTraits::ToUppercase
static constexpr char_type ToUppercase(char_type c) noexcept
Definition: CharTraits.h:529
Defs.h
pcl::CharTraits::CopyOverlapped
static void CopyOverlapped(char_type *dst, const char_type *src, size_type n) noexcept
Definition: CharTraits.h:1173
pcl::IsoCharTraits::ToLowercase
static void ToLowercase(char_type *s, size_type n) noexcept
Definition: CharTraits.h:1090
pcl::GenericCharTraits< char16_type >::char_type
char16_type char_type
Definition: CharTraits.h:322
pcl::GenericCharTraits
Generic base class of character traits classes.
Definition: CharTraits.h:315
pcl::GenericCharTraits::Length
static size_type Length(const char_type *s) noexcept
Definition: CharTraits.h:339
pcl::char16_type
uint16 char16_type
Definition: Defs.h:1144
pcl::GenericCharTraits::Hyphen
static constexpr char_type Hyphen() noexcept
Definition: CharTraits.h:631
pcl::IsoCharTraits::Copy
static void Copy(char_type *__restrict__ dst, const char_type *__restrict__ src, size_type n) noexcept
Definition: CharTraits.h:908
pcl::GenericCharTraits::IsUppercaseAlpha
static constexpr bool IsUppercaseAlpha(char_type c) noexcept
Definition: CharTraits.h:755
pcl::CharTraits::ToLowercase
static char_type ToLowercase(char_type c) noexcept
Definition: CharTraits.h:1335