Point Cloud Library (PCL)  1.9.1-dev
opennurbs_string.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_STRING_INC_)
18 #define ON_STRING_INC_
19 
20 #include <pcl/pcl_exports.h>
21 
22 /*
23 Description:
24  Sort an index array.
25 Parameters
26  method - [in]
27  ON::quick_sort (best in general) or ON::heap_sort.
28  Use ON::heap_sort only after doing meaningful performance
29  testing using optimized release builds that demonstrate
30  ON::heap_sort is significantly better.
31  index - [out]
32  Pass in an array of count integers. The returned
33  index[] is a permutation of (0,1,..,count-1)
34  such that compare(B[index[i]],B[index[i+1]) <= 0
35  where B[i] = base + i*sizeof_element
36  base - [in]
37  array of count elements
38  count - [in]
39  number of elements in the index[] and base[] arrays
40  sizeof_element - [in]
41  number of bytes between consecutive elements in the
42  base[] array.
43  compare - [in]
44  Comparison function a la qsort().
45 */
46 ON_DECL
47 void ON_Sort(
48  ON::sort_algorithm method,
49  int* index,
50  const void* base,
51  std::size_t count,
52  std::size_t sizeof_element,
53  int (*compare)(const void*,const void*) // int compar(const void*,const void*)
54  );
55 
56 /*
57 Description:
58  Sort an index array using a compare function
59  that takes an additional pointer that can be used to
60  pass extra informtation.
61 Parameters
62  method - [in]
63  ON::quick_sort (best in general) or ON::heap_sort.
64  Use ON::heap_sort only after doing meaningful performance
65  testing using optimized release builds that demonstrate
66  ON::heap_sort is significantly better.
67  index - [out]
68  Pass in an array of count integers. The returned
69  index[] is a permutation of (0,1,..,count-1)
70  such that compare(B[index[i]],B[index[i+1]) <= 0
71  where B[i] = base + i*sizeof_element
72  base - [in]
73  array of count elements
74  count - [in]
75  number of elements in the index[] and base[] arrays
76  sizeof_element - [in]
77  number of bytes between consecutive elements in the
78  base[] array.
79  compare - [in]
80  Comparison function a la qsort(). The context parameter
81  is pass as the third argument.
82  context - [in]
83  pointer passed as the third argument to compare().
84 */
85 ON_DECL
86 void ON_Sort(
87  ON::sort_algorithm method,
88  int* index,
89  const void* base,
90  std::size_t count,
91  std::size_t sizeof_element,
92  int (*compare)(const void*,const void*,void*), // int compar(const void* a,const void* b, void* ptr)
93  void* context
94  );
95 
96 /*
97 Description:
98  Various sorts. When in doubt, use ON_qsort().
99  ON_qsort - quick sort.
100  ON_hsort = hearp sort.
101 Parameters
102  base - [in]
103  array of count elements
104  count - [in]
105  number of elements in the index[] and base[] arrays
106  sizeof_element - [in]
107  number of bytes between consecutive elements in the
108  base[] array.
109  compare - [in]
110  Comparison function a la qsort(). The context parameter
111  is pass as the third argument.
112  context - [in]
113  pointer passed as the third argument to compare().
114 Remarks:
115  As a rule, use quick sort unless extensive tests in your case
116  prove that heap sort is faster.
117 
118  This implementation of quick sort is generally faster than
119  heap sort, even when the input arrays are nearly sorted.
120  The only common case when heap sort is faster occurs when
121  the arrays are strictly "chevron" (3,2,1,2,3) or "carat"
122  (1,2,3,2,1) ordered, and in these cases heap sort is about
123  50% faster. If the "chevron" or "caret" ordered arrays
124  have a little randomness added, the two algorithms have
125  the same speed.
126 */
127 ON_DECL
128 void ON_hsort(
129  void* base,
130  std::size_t count,
131  std::size_t sizeof_element,
132  int (*compare)(const void*,const void*)
133  );
134 
135 ON_DECL
136 void ON_qsort(
137  void* base,
138  std::size_t count,
139  std::size_t sizeof_element,
140  int (*compare)(const void*,const void*)
141  );
142 
143 ON_DECL
144 void ON_hsort(
145  void* base,
146  std::size_t count,
147  std::size_t sizeof_element,
148  int (*compare)(void*,const void*,const void*),
149  void* context
150  );
151 
152 ON_DECL
153 void ON_qsort(
154  void* base,
155  std::size_t count,
156  std::size_t sizeof_element,
157  int (*compare)(void*,const void*,const void*),
158  void* context
159  );
160 
161 /*
162 Description:
163  Sort an array of doubles in place.
164 Parameters:
165  sort_algorithm - [in]
166  ON::quick_sort (best in general) or ON::heap_sort
167  Use ON::heap_sort only if you have done extensive testing with
168  optimized release builds and are confident heap sort is
169  significantly faster in your case.
170  a - [in / out]
171  The values in a[] are sorted so that a[i] <= a[i+1].
172  a[] cannot contain NaNs.
173  nel - [in]
174  length of array a[]
175 */
176 ON_DECL
177 void ON_SortDoubleArray(
178  ON::sort_algorithm sort_algorithm,
179  double* a,
180  std::size_t nel
181  );
182 
183 /*
184 Description:
185  Sort an array of ints in place.
186 Parameters:
187  sort_algorithm - [in]
188  ON::quick_sort (best in general) or ON::heap_sort
189  Use ON::heap_sort only if you have done extensive testing with
190  optimized release builds and are confident heap sort is
191  significantly faster in your case.
192  a - [in / out]
193  The values in a[] are sorted so that a[i] <= a[i+1].
194  nel - [in]
195  length of array a[]
196 */
197 ON_DECL
198 void ON_SortIntArray(
199  ON::sort_algorithm sort_algorithm,
200  int* a,
201  std::size_t nel
202  );
203 
204 /*
205 Description:
206  Sort an array of unsigned ints in place.
207 Parameters:
208  sort_algorithm - [in]
209  ON::quick_sort (best in general) or ON::heap_sort
210  Use ON::heap_sort only if you have done extensive testing with
211  optimized release builds and are confident heap sort is
212  significantly faster in your case.
213  a - [in / out]
214  The values in a[] are sorted so that a[i] <= a[i+1].
215  nel - [in]
216  length of array a[]
217 */
218 ON_DECL
219 void ON_SortUnsignedIntArray(
220  ON::sort_algorithm sort_algorithm,
221  unsigned int* a,
222  std::size_t nel
223  );
224 
225 /*
226 Description:
227  Sort an array of unsigned null terminated char strings in place.
228 Parameters:
229  sort_algorithm - [in]
230  ON::quick_sort (best in general) or ON::heap_sort
231  Use ON::heap_sort only if you have done extensive testing with
232  optimized release builds and are confident heap sort is
233  significantly faster in your case.
234  a - [in / out]
235  The values in a[] are sorted so that strcmp(a[i],a[i+1]) <= 0.
236  nel - [in]
237  length of array a[]
238 */
239 ON_DECL
240 void ON_SortStringArray(
241  ON::sort_algorithm sort_algorithm,
242  char** a,
243  std::size_t nel
244  );
245 
246 ON_DECL
247 const int* ON_BinarySearchIntArray(
248  int key,
249  const int* base,
250  std::size_t nel
251  );
252 
253 ON_DECL
254 const unsigned int* ON_BinarySearchUnsignedIntArray(
255  unsigned int key,
256  const unsigned int* base,
257  std::size_t nel
258  );
259 
260 ON_DECL
261 const double* ON_BinarySearchDoubleArray(
262  double key,
263  const double* base,
264  std::size_t nel
265  );
266 
267 
268 
269 /*
270  This class is intended to be used to determine if a file's
271  contents have changed.
272 */
273 class ON_CLASS ON_CheckSum
274 {
275 public:
276  ON_CheckSum();
277  ~ON_CheckSum();
278 
280 
281  // zeros all fields.
282  void Zero();
283 
284  /*
285  Returns:
286  True if checksum is set.
287  */
288  bool IsSet() const;
289 
290  // C++ default operator=, operator==,
291  // and copy constructor work fine.
292 
293  /*
294  Descripton:
295  Set check sum values for a buffer
296  Parameters:
297  size - [in]
298  number of bytes in buffer
299  buffer - [in]
300  time - [in]
301  last modified time in seconds since Jan 1, 1970, UCT
302  Returns:
303  True if checksum is set.
304  */
305  bool SetBufferCheckSum(
306  std::size_t size,
307  const void* buffer,
308  time_t time
309  );
310 
311  /*
312  Descripton:
313  Set check sum values for a file.
314  Parameters:
315  fp - [in] pointer to a file opened with ON:FileOpen(...,"rb")
316  Returns:
317  True if checksum is set.
318  */
319  bool SetFileCheckSum(
320  FILE* fp
321  );
322 
323  /*
324  Descripton:
325  Set check sum values for a file.
326  Parameters:
327  filename - [in] name of file.
328  Returns:
329  True if checksum is set.
330  */
331  bool SetFileCheckSum(
332  const wchar_t* filename
333  );
334 
335  /*
336  Description:
337  Test buffer to see if it has a matching checksum.
338  Paramters:
339  size - [in] size in bytes
340  buffer - [in]
341  Returns:
342  True if the buffer has a matching checksum.
343  */
344  bool CheckBuffer(
345  std::size_t size,
346  const void* buffer
347  ) const;
348 
349  /*
350  Description:
351  Test buffer to see if it has a matching checksum.
352  Paramters:
353  fp - [in] pointer to file opened with ON::OpenFile(...,"rb")
354  bSkipTimeCheck - [in] if true, the time of last
355  modification is not checked.
356  Returns:
357  True if the file has a matching checksum.
358  */
359  bool CheckFile(
360  FILE* fp,
361  bool bSkipTimeCheck = false
362  ) const;
363 
364  /*
365  Description:
366  Test buffer to see if it has a matching checksum.
367  Paramters:
368  filename - [in]
369  bSkipTimeCheck - [in] if true, the time of last
370  modification is not checked.
371  Returns:
372  True if the file has a matching checksum.
373  */
374  bool CheckFile(
375  const wchar_t* filename,
376  bool bSkipTimeCheck = false
377  ) const;
378 
379  bool Write(class ON_BinaryArchive&) const;
380  bool Read(class ON_BinaryArchive&);
381 
382  void Dump(class ON_TextLog&) const;
383 
384 public:
385  std::size_t m_size; // bytes in the file.
386  time_t m_time; // last modified time in seconds since Jan 1, 1970, UCT
387  ON__UINT32 m_crc[8]; // crc's
388 };
389 
390 /////////////////////////////////////////////////////////////////////////////
391 //
392 // ON_String is a char (a.k.a single byte or ascii) string
393 //
394 // ON_wString is a wide char (a.k.a double byte or unicode) string
395 //
396 
397 class ON_String; // char (a.k.a single byte or ascii) string
398 class ON_wString; // wide character (a.k.a double byte or unicode) string
399 
400 /////////////////////////////////////////////////////////////////////////////
401 /////////////////////////////////////////////////////////////////////////////
402 /////////////////////////////////////////////////////////////////////////////
403 /////////////////////////////////////////////////////////////////////////////
404 
405 class ON_CLASS ON_String
406 {
407 public:
408 
409 // Constructors
410  ON_String();
411  ON_String( const ON_String& );
412 
413  ON_String( const char* );
414  ON_String( const char*, int /*length*/ ); // from substring
415  ON_String( char, int = 1 /* repeat count */ );
416 
417  ON_String( const unsigned char* );
418  ON_String( const unsigned char*, int /*length*/ ); // from substring
419  ON_String( unsigned char, int = 1 /* repeat count */ );
420 
421  // construct a UTF-8 string string from a UTF-16 string.
422  ON_String( const wchar_t* src ); // src = UTF-16 string
423  ON_String( const wchar_t* src, int length ); // from a UTF-16 substring
424  ON_String( const ON_wString& src ); // src = UTF-16 string
425 
426 #if defined(ON_OS_WINDOWS)
427  // Windows support
428  bool LoadResourceString( HINSTANCE, UINT); // load from Windows string resource
429  // 2047 chars max
430 #endif
431 
432  void Create();
433  void Destroy(); // releases any memory and initializes to default empty string
434  void EmergencyDestroy();
435 
436  /*
437  Description:
438  Enables reference counting. I limited cases, this is useful
439  for large strings or strings that are frequently passed around.
440  Reference counted strings must be carefully managed in
441  when multi-threading is used.
442  Parameters:
443  If EnableReferenceCounting()
444  is not called, then the string will not be referanceThe default is to not use
445  reference counted strings.
446  */
447  void EnableReferenceCounting( bool bEnable );
448 
449  /*
450  Returns:
451  True if the string is reference counted.
452  */
453  bool IsReferenceCounted() const;
454 
455 
456  // Attributes & Operations
457  // as an array of characters
458  int Length() const;
459  bool IsEmpty() const; // returns true if length == 0
460  void Empty(); // sets length to zero - if possible, memory is retained
461 
462  char& operator[](int);
463  char operator[](int) const;
464  char GetAt(int) const;
465  void SetAt(int, char);
466  void SetAt(int, unsigned char);
467  operator const char*() const; // as a C string
468 
469  // overloaded assignment
470  ON_String& operator=(const ON_String&);
471  ON_String& operator=(char);
472  ON_String& operator=(const char*);
473  ON_String& operator=(unsigned char);
474  ON_String& operator=(const unsigned char*);
475  ON_String& operator=(const wchar_t* src); // src = UTF-16 string, result is a UTF-8 string
476  ON_String& operator=(const ON_wString& src); // src = UTF-16 string, result is a UTF-8 string
477 
478  // operator+()
479  ON_String operator+(const ON_String&) const;
480  ON_String operator+(char) const;
481  ON_String operator+(unsigned char) const;
482  ON_String operator+(const char*) const;
483  ON_String operator+(const unsigned char*) const;
484 
485  // string comparison
486  bool operator==(const ON_String&) const;
487  bool operator==(const char*)const ;
488  bool operator!=(const ON_String&)const ;
489  bool operator!=(const char*)const ;
490  bool operator<(const ON_String&)const ;
491  bool operator<(const char*)const ;
492  bool operator>(const ON_String&)const ;
493  bool operator>(const char*)const ;
494  bool operator<=(const ON_String&)const ;
495  bool operator<=(const char*)const ;
496  bool operator>=(const ON_String&)const ;
497  bool operator>=(const char*)const ;
498 
499  // string concatenation
500  void Append( const char*, int ); // append specified number of characters
501  void Append( const unsigned char*, int ); // append specified number of characters
502  const ON_String& operator+=(const ON_String&);
503  const ON_String& operator+=(char);
504  const ON_String& operator+=(unsigned char);
505  const ON_String& operator+=(const char*);
506  const ON_String& operator+=(const unsigned char*);
507 
508  // string comparison
509  // If this < string, returns < 0.
510  // If this = string, returns 0.
511  // If this < string, returns > 0.
512  int Compare( const char* ) const;
513  int Compare( const unsigned char* ) const;
514 
515  int CompareNoCase( const char* ) const;
516  int CompareNoCase( const unsigned char* ) const;
517 
518  // Description:
519  // Simple case sensitive wildcard matching. A question mark (?) in the
520  // pattern matches a single character. An asterisk (*) in the pattern
521  // mathes zero or more occurances of any character.
522  //
523  // Parameters:
524  // pattern - [in] pattern string where ? and * are wild cards.
525  //
526  // Returns:
527  // true if the string mathes the wild card pattern.
528  bool WildCardMatch( const char* ) const;
529  bool WildCardMatch( const unsigned char* ) const;
530 
531  // Description:
532  // Simple case insensitive wildcard matching. A question mark (?) in the
533  // pattern matches a single character. An asterisk (*) in the pattern
534  // mathes zero or more occurances of any character.
535  //
536  // Parameters:
537  // pattern - [in] pattern string where ? and * are wild cards.
538  //
539  // Returns:
540  // true if the string mathes the wild card pattern.
541  bool WildCardMatchNoCase( const char* ) const;
542  bool WildCardMatchNoCase( const unsigned char* ) const;
543 
544  /*
545  Description:
546  Replace all substrings that match token1 with token2
547  Parameters:
548  token1 - [in]
549  token2 - [in]
550  Returns:
551  Number of times token1 was replaced with token2.
552  */
553  int Replace( const char* token1, const char* token2 );
554  int Replace( const unsigned char* token1, const unsigned char* token2 );
555  int Replace( char token1, char token2 );
556  int Replace( unsigned char token1, unsigned char token2 );
557 
558 
559  // simple sub-string extraction
560  ON_String Mid(
561  int, // index of first char
562  int // count
563  ) const;
564  ON_String Mid(
565  int // index of first char
566  ) const;
567  ON_String Left(
568  int // number of chars to keep
569  ) const;
570  ON_String Right(
571  int // number of chars to keep
572  ) const;
573 
574  // upper/lower/reverse conversion
575  void MakeUpper();
576  void MakeLower();
577  void MakeReverse();
578  void TrimLeft(const char* = NULL);
579  void TrimRight(const char* = NULL);
580  void TrimLeftAndRight(const char* = NULL);
581 
582  // remove occurrences of chRemove
583  int Remove( const char chRemove);
584 
585  // searching (return starting index, or -1 if not found)
586  // look for a single character match
587  int Find(char) const;
588  int Find(unsigned char) const;
589  int ReverseFind(char) const;
590  int ReverseFind(unsigned char) const;
591 
592  // look for a specific sub-string
593  int Find(const char*) const;
594  int Find(const unsigned char*) const;
595 
596  // simple formatting
597  void ON_MSC_CDECL Format( const char*, ...);
598  void ON_MSC_CDECL Format( const unsigned char*, ...);
599 
600  // Low level access to string contents as character array
601  void ReserveArray(std::size_t); // make sure internal array has at least
602  // the requested capacity.
603  void ShrinkArray(); // shrink internal storage to minimum size
604  void SetLength(std::size_t); // set length (<=capacity)
605  char* Array();
606  const char* Array() const;
607 
608  /*
609  Returns:
610  Total number of bytes of memory used by this class.
611  (For use in ON_Object::SizeOf() overrides.
612  */
613  unsigned int SizeOf() const;
614 
615  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
616 
617  /*
618  Description:
619  Find the locations in a path the specify the drive, directory,
620  file name and file extension.
621  Parameters:
622  path - [in]
623  path to split
624  drive - [out] (pass null if you don't need the drive)
625  If drive is not null and the path parameter contains a Windows
626  drive specification, then the returned value of *drive will
627  either be empty or the Windows drive letter followed by
628  the trailing colon.
629  dir - [out] (pass null if you don't need the directory)
630  If dir is not null and the path parameter contains a
631  directory specification, then the returned value of *dir
632  will be the directory specification including the trailing
633  slash.
634  fname - [out] (pass null if you don't need the file name)
635  If fname is not null and the path parameter contains a
636  file name specification, then the returned value of *fname
637  will be the file name.
638  ext - [out] (pass null if you don't need the extension)
639  If ext is not null and the path parameter contains a
640  file extension specification, then the returned value of
641  *ext will be the file extension including the initial
642  '.' character.
643  Remarks:
644  This function will treat a front slash ( / ) and a back slash
645  ( \ ) as directory separators. Because this function parses
646  file names store in .3dm files and the .3dm file may have been
647  written on a Windows computer and then read on a another
648  computer, it looks for a drive dpecification even when the
649  operating system is not Windows.
650  This function will not return an directory that does not
651  end with a trailing slash.
652  This function will not return an empty filename and a non-empty
653  extension.
654  This function parses the path string according to these rules.
655  It does not check the actual file system to see if the answer
656  is correct.
657  See Also:
658  on_splitpath
659  */
660  static void SplitPath(
661  const char* path,
662  ON_String* drive,
663  ON_String* dir,
664  ON_String* fname,
665  ON_String* ext
666  );
667 
668 // Implementation
669 public:
670  ~ON_String();
671 
672 protected:
673  char* m_s; // pointer to ref counted string array
674  // m_s - 12 bytes points at the string's ON_aStringHeader
675 
676  // implementation helpers
677  struct ON_aStringHeader* Header() const;
678  void CreateArray(int);
679  void CopyArray();
680  void CopyToArray( const ON_String& );
681  void CopyToArray( int, const char* );
682  void CopyToArray( int, const unsigned char* );
683  void CopyToArray( int, const wchar_t* );
684  void AppendToArray( const ON_String& );
685  void AppendToArray( int, const char* );
686  void AppendToArray( int, const unsigned char* );
687  static int Length(const char*); // handles NULL pointers without crashing
688  static int Length(const unsigned char*); // handles NULL pointers without crashing
689 };
690 
691 
692 /////////////////////////////////////////////////////////////////////////////
693 /////////////////////////////////////////////////////////////////////////////
694 /////////////////////////////////////////////////////////////////////////////
695 /////////////////////////////////////////////////////////////////////////////
696 //
697 // ON_wString
698 //
699 
700 class PCL_EXPORTS ON_CLASS ON_wString
701 {
702 public:
703 
704 // Constructors
705  ON_wString();
706  ON_wString( const ON_wString& );
707 
708  ON_wString( const ON_String& src ); // src = UTF-8 string
709 
710  ON_wString( const char* src ); // src = nul; terminated UTF-8 string
711  ON_wString( const char* src, int /*length*/ ); // from UTF-8 substring
712  ON_wString( char, int = 1 /* repeat count */ );
713 
714  ON_wString( const unsigned char* src); // src = nul; terminated UTF-8 string
715  ON_wString( const unsigned char*src, int /*length*/ ); // from UTF-8 substring
716  ON_wString( unsigned char, int = 1 /* repeat count */ );
717 
718  ON_wString( const wchar_t* );
719  ON_wString( const wchar_t*, int /*length*/ ); // from substring
720  ON_wString( wchar_t, int = 1 /* repeat count */ );
721 
722 #if defined(ON_OS_WINDOWS)
723  // Windows support
724  bool LoadResourceString(HINSTANCE, UINT); // load from string resource
725  // 2047 characters max
726 #endif
727 
728  void Create();
729  void Destroy(); // releases any memory and initializes to default empty string
730  void EmergencyDestroy();
731 
732  /*
733  Description:
734  Enables reference counting. I limited cases, this is useful
735  for large strings or strings that are frequently passed around.
736  Reference counted strings must be carefully managed in
737  when multi-threading is used.
738  Parameters:
739  If EnableReferenceCounting()
740  is not called, then the string will not be referanceThe default is to not use
741  reference counted strings.
742  */
743  void EnableReferenceCounting( bool bEnable );
744 
745  /*
746  Returns:
747  True if the string is reference counted.
748  */
749  bool IsReferenceCounted() const;
750 
751 // Attributes & Operations
752  // as an array of characters
753  int Length() const;
754  bool IsEmpty() const;
755  void Empty(); // sets length to zero - if possible, memory is retained
756 
757  wchar_t& operator[](int);
758  wchar_t operator[](int) const;
759  wchar_t GetAt(int) const;
760  void SetAt(int, char);
761  void SetAt(int, unsigned char);
762  void SetAt(int, wchar_t);
763  operator const wchar_t*() const; // as a UNICODE string
764 
765  // overloaded assignment
766  const ON_wString& operator=(const ON_wString&);
767  const ON_wString& operator=(const ON_String& src); // src = UTF-8 string
768  const ON_wString& operator=(char);
769  const ON_wString& operator=(const char* src); // src = UTF-8 string
770  const ON_wString& operator=(unsigned char);
771  const ON_wString& operator=(const unsigned char* src); // src = UTF-8 string
772  const ON_wString& operator=(wchar_t);
773  const ON_wString& operator=(const wchar_t*);
774 
775  // string concatenation
776  void Append( const char* sUTF8, int ); // append specified number of elements from a UTF-8 string
777  void Append( const unsigned char* sUTF8, int ); // append specified number of elements from a UTF-8 string
778  void Append( const wchar_t*, int ); // append specified number of elements
779  const ON_wString& operator+=(const ON_wString&);
780  const ON_wString& operator+=(const ON_String& sUTF8); // append UTF-8 string
781  const ON_wString& operator+=(char);
782  const ON_wString& operator+=(unsigned char);
783  const ON_wString& operator+=(wchar_t);
784  const ON_wString& operator+=(const char* sUTF8); // append UTF-8 string
785  const ON_wString& operator+=(const unsigned char* sUTF8); // append UTF-8 string
786  const ON_wString& operator+=(const wchar_t*);
787 
788  // operator+()
789  ON_wString operator+(const ON_wString&) const;
790  ON_wString operator+(const ON_String& sUTF8) const; // concatinate with a UTF-8 string
791  ON_wString operator+(char) const;
792  ON_wString operator+(unsigned char) const;
793  ON_wString operator+(wchar_t) const;
794  ON_wString operator+(const char* sUTF8) const; // concatinate with a UTF-8 string
795  ON_wString operator+(const unsigned char* sUTF8) const; // concatinate with a UTF-8 string
796  ON_wString operator+(const wchar_t*) const;
797 
798  // string comparison
799  bool operator==(const ON_wString&) const;
800  bool operator==(const wchar_t*) const;
801  bool operator!=(const ON_wString&) const;
802  bool operator!=(const wchar_t*) const;
803  bool operator<(const ON_wString&) const;
804  bool operator<(const wchar_t*) const;
805  bool operator>(const ON_wString&) const;
806  bool operator>(const wchar_t*) const;
807  bool operator<=(const ON_wString&) const;
808  bool operator<=(const wchar_t*) const;
809  bool operator>=(const ON_wString&) const;
810  bool operator>=(const wchar_t*) const;
811 
812  // string comparison
813  // If this < string, returns < 0.
814  // If this == string, returns 0.
815  // If this < string, returns > 0.
816  int Compare( const char* sUTF8 ) const; // compare to UTF-8 string
817  int Compare( const unsigned char* sUTF8 ) const; // compare to UTF-8 string
818  int Compare( const wchar_t* ) const;
819 
820  int CompareNoCase( const char* sUTF8) const; // compare to UTF-8 string
821  int CompareNoCase( const unsigned char* sUTF8) const; // compare to UTF-8 string
822  int CompareNoCase( const wchar_t* ) const;
823 
824  // Description:
825  // Simple case sensitive wildcard matching. A question mark (?) in the
826  // pattern matches a single character. An asterisk (*) in the pattern
827  // mathes zero or more occurances of any character.
828  //
829  // Parameters:
830  // pattern - [in] pattern string where ? and * are wild cards.
831  //
832  // Returns:
833  // true if the string mathes the wild card pattern.
834  bool WildCardMatch( const wchar_t* ) const;
835 
836  // Description:
837  // Simple case insensitive wildcard matching. A question mark (?) in the
838  // pattern matches a single character. An asterisk (*) in the pattern
839  // mathes zero or more occurances of any character.
840  //
841  // Parameters:
842  // pattern - [in] pattern string where ? and * are wild cards.
843  //
844  // Returns:
845  // true if the string mathes the wild card pattern.
846  bool WildCardMatchNoCase( const wchar_t* ) const;
847 
848  /*
849  Description:
850  Replace all substrings that match token1 with token2
851  Parameters:
852  token1 - [in]
853  token2 - [in]
854  Returns:
855  Number of times toke1 was replaced with token2
856  */
857  int Replace( const wchar_t* token1, const wchar_t* token2 );
858  int Replace( wchar_t token1, wchar_t token2 );
859 
860  /*
861  Description:
862  Replaces all characters in the string whose values are
863  not '0-9', 'A-Z', or 'a-z' with a percent sign followed
864  by a 2 digit hex value.
865  */
866  void UrlEncode();
867 
868  /*
869  Description:
870  Replaces all %xx where xx a two digit hexadecimal number,
871  with a single character. Returns false if the orginal
872  string contained
873  */
874  bool UrlDecode();
875 
876  /*
877  Description:
878  Replace all white-space characters with the token.
879  If token is zero, the string will end up with
880  internal 0's
881  Parameters:
882  token - [in]
883  whitespace - [in] if not null, this is a 0 terminated
884  string that lists the characters considered to be
885  white space. If null, then (1,2,...,32,127) is used.
886  Returns:
887  Number of whitespace characters replaced.
888  See Also:
889  ON_wString::RemoveWhiteSpace
890  */
891  int ReplaceWhiteSpace( wchar_t token, const wchar_t* whitespace = 0 );
892 
893  /*
894  Description:
895  Removes all white-space characters with the token.
896  Parameters:
897  whitespace - [in] if not null, this is a 0 terminated
898  string that lists the characters considered to be
899  white space. If null, then (1,2,...,32,127) is used.
900  Returns:
901  Number of whitespace characters removed.
902  See Also:
903  ON_wString::ReplaceWhiteSpace
904  */
905  int RemoveWhiteSpace( const wchar_t* whitespace = 0 );
906 
907  // simple sub-string extraction
908  ON_wString Mid(
909  int, // index of first char
910  int // count
911  ) const;
912  ON_wString Mid(
913  int // index of first char
914  ) const;
915  ON_wString Left(
916  int // number of chars to keep
917  ) const;
918  ON_wString Right(
919  int // number of chars to keep
920  ) const;
921 
922  // upper/lower/reverse conversion
923  void MakeUpper();
924  void MakeLower();
925  void MakeReverse();
926  void TrimLeft(const wchar_t* = NULL);
927  void TrimRight(const wchar_t* = NULL);
928  void TrimLeftAndRight(const wchar_t* = NULL);
929 
930  /*
931  Description:
932  Remove all occurrences of c.
933  */
934  int Remove( wchar_t c);
935 
936  // searching (return starting index, or -1 if not found)
937  // look for a single character match
938  int Find(char) const;
939  int Find(unsigned char) const;
940  int Find(wchar_t) const;
941  int ReverseFind(char) const;
942  int ReverseFind(unsigned char) const;
943  int ReverseFind(wchar_t) const;
944 
945  // look for a specific sub-string
946  int Find(const char*) const;
947  int Find(const unsigned char*) const;
948  int Find(const wchar_t*) const;
949 
950 
951  // simple formatting - be careful with %s in format string
952  void ON_MSC_CDECL Format( const char*, ...);
953  void ON_MSC_CDECL Format( const unsigned char*, ...);
954  void ON_MSC_CDECL Format( const wchar_t*, ...);
955 
956  // Low level access to string contents as character array
957  void ReserveArray(std::size_t); // make sure internal array has at least
958  // the requested capacity.
959  void ShrinkArray(); // shrink internal storage to minimum size
960  void SetLength(std::size_t); // set length (<=capacity)
961  wchar_t* Array();
962  const wchar_t* Array() const;
963 
964  /*
965  Returns:
966  Total number of bytes of memory used by this class.
967  (For use in ON_Object::SizeOf() overrides.
968  */
969  unsigned int SizeOf() const;
970 
971  /*
972  Returns:
973  CRC of the string.
974  */
975  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
976 
977  /*
978  Returns:
979  CRC of the lower case version of the string. Useful
980  for case insensitive CRCs and hash codes.
981  */
982  ON__UINT32 DataCRCLower(ON__UINT32 current_remainder) const;
983 
984  /*
985  Description:
986  Find the locations in a path the specify the drive, directory,
987  file name and file extension.
988  Parameters:
989  path - [in]
990  path to split
991  drive - [out] (pass null if you don't need the drive)
992  If drive is not null and the path parameter contains a Windows
993  drive specification, then the returned value of *drive will
994  either be empty or the Windows drive letter followed by
995  the trailing colon.
996  dir - [out] (pass null if you don't need the directory)
997  If dir is not null and the path parameter contains a
998  directory specification, then the returned value of *dir
999  will be the directory specification including the trailing
1000  slash.
1001  fname - [out] (pass null if you don't need the file name)
1002  If fname is not null and the path parameter contains a
1003  file name specification, then the returned value of *fname
1004  will be the file name.
1005  ext - [out] (pass null if you don't need the extension)
1006  If ext is not null and the path parameter contains a
1007  file extension specification, then the returned value of
1008  *ext will be the file extension including the initial
1009  '.' character.
1010  Remarks:
1011  This function will treat a front slash ( / ) and a back slash
1012  ( \ ) as directory separators. Because this function parses
1013  file names store in .3dm files and the .3dm file may have been
1014  written on a Windows computer and then read on a another
1015  computer, it looks for a drive dpecification even when the
1016  operating system is not Windows.
1017  This function will not return an directory that does not
1018  end with a trailing slash.
1019  This function will not return an empty filename and a non-empty
1020  extension.
1021  This function parses the path string according to these rules.
1022  It does not check the actual file system to see if the answer
1023  is correct.
1024  See Also:
1025  on_splitpath
1026  on_wsplitpath
1027  */
1028  static void SplitPath(
1029  const char* path,
1030  ON_wString* drive,
1031  ON_wString* dir,
1032  ON_wString* fname,
1033  ON_wString* ext
1034  );
1035 
1036  static void SplitPath(
1037  const wchar_t* path,
1038  ON_wString* drive,
1039  ON_wString* dir,
1040  ON_wString* fname,
1041  ON_wString* ext
1042  );
1043 // Implementation
1044 public:
1045  ~ON_wString();
1046 
1047 protected:
1048  wchar_t* m_s; // pointer to ref counted string array
1049  // m_s - 12 bytes points at the string's ON_wStringHeader
1050 
1051  // implementation helpers
1052  struct ON_wStringHeader* Header() const;
1053  void CreateArray(int);
1054  void CopyArray();
1055  void CopyToArray( const ON_wString& );
1056  void CopyToArray( int, const char* );
1057  void CopyToArray( int, const unsigned char* );
1058  void CopyToArray( int, const wchar_t* );
1059  void AppendToArray( const ON_wString& );
1060  void AppendToArray( int, const char* );
1061  void AppendToArray( int, const unsigned char* );
1062  void AppendToArray( int, const wchar_t* );
1063  static int Length(const char*); // handles NULL pointers without crashing
1064  static int Length(const unsigned char*); // handles NULL pointers without crashing
1065  static int Length(const wchar_t*); // handles NULL pointers without crashing
1066 };
1067 
1068 class ON_CLASS ON_UnitSystem
1069 {
1070 public:
1071  ON_UnitSystem(); // default constructor units are millimeters.
1072  ~ON_UnitSystem();
1073 
1074  ON_UnitSystem(ON::unit_system);
1075  ON_UnitSystem& operator=(ON::unit_system);
1076 
1077  bool operator==(const ON_UnitSystem&);
1078  bool operator!=(const ON_UnitSystem&);
1079 
1080  bool IsValid() const;
1081 
1082  void Default(); // millimeters = default unit system
1083 
1084  bool Read( class ON_BinaryArchive& );
1085  bool Write( class ON_BinaryArchive& ) const;
1086  void Dump( class ON_TextLog& ) const;
1087 
1088  ON::unit_system m_unit_system;
1089 
1090  // The m_custom_unit_... settings apply when m_unit_system = ON::custom_unit_system
1091  double m_custom_unit_scale; // 1 meter = m_custom_unit_scale custom units
1092  ON_wString m_custom_unit_name; // name of custom units
1093 
1094  // Custom units example:
1095  // 1 Nautical league = 5556 meters
1096  // So, if you wanted your unit system to be nautical leagues
1097  // your ON_UnitSystem would be
1098  // m_unit_system = ON::custom_unit_system
1099  // m_custom_unit_scale = 1.0/5556.0 = 0.0001799856...
1100  // m_custom_unit_name = "Nautical leagues"
1101 };
1102 
1103 
1104 #endif
static const ON_CheckSum UnsetCheckSum
ON::unit_system m_unit_system
double m_custom_unit_scale
ON_wString m_custom_unit_name
std::size_t m_size
#define PCL_EXPORTS
Definition: pcl_macros.h:241