opennurbs_string.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #if !defined(ON_STRING_INC_)
00018 #define ON_STRING_INC_
00019 
00020 
00021 
00022 /*
00023 Description:
00024   Sort an index array.
00025 Parameters
00026   method - [in]
00027     ON::quick_sort (best in general) or ON::heap_sort.
00028     Use ON::heap_sort only after doing meaningful performance
00029     testing using optimized release builds that demonstrate
00030     ON::heap_sort is significantly better.
00031   index - [out] 
00032     Pass in an array of count integers.  The returned
00033     index[] is a permutation of (0,1,..,count-1)
00034     such that compare(B[index[i]],B[index[i+1]) <= 0
00035     where B[i] = base + i*sizeof_element
00036   base - [in]
00037     array of count elements
00038   count - [in]
00039     number of elements in the index[] and base[] arrays
00040   sizeof_element - [in]
00041     number of bytes between consecutive elements in the
00042     base[] array.
00043   compare - [in]
00044     Comparison function a la qsort().
00045 */
00046 ON_DECL
00047 void ON_Sort( 
00048         ON::sort_algorithm method,
00049         int* index,
00050         const void* base,
00051         size_t count,
00052         size_t sizeof_element,
00053         int (*compare)(const void*,const void*) // int compar(const void*,const void*)
00054         );
00055 
00056 /*
00057 Description:
00058   Sort an index array using a compare function
00059   that takes an additional pointer that can be used to
00060   pass extra informtation.
00061 Parameters
00062   method - [in]
00063     ON::quick_sort (best in general) or ON::heap_sort.
00064     Use ON::heap_sort only after doing meaningful performance
00065     testing using optimized release builds that demonstrate
00066     ON::heap_sort is significantly better.
00067   index - [out] 
00068     Pass in an array of count integers.  The returned
00069     index[] is a permutation of (0,1,..,count-1)
00070     such that compare(B[index[i]],B[index[i+1]) <= 0
00071     where B[i] = base + i*sizeof_element
00072   base - [in]
00073     array of count elements
00074   count - [in]
00075     number of elements in the index[] and base[] arrays
00076   sizeof_element - [in]
00077     number of bytes between consecutive elements in the
00078     base[] array.
00079   compare - [in]
00080     Comparison function a la qsort().  The context parameter
00081     is pass as the third argument.
00082   context - [in]
00083     pointer passed as the third argument to compare().
00084 */
00085 ON_DECL
00086 void ON_Sort( 
00087         ON::sort_algorithm method,
00088         int* index,
00089         const void* base,
00090         size_t count,
00091         size_t sizeof_element,
00092         int (*compare)(const void*,const void*,void*), // int compar(const void* a,const void* b, void* ptr)
00093         void* context
00094         );
00095 
00096 /*
00097 Description:
00098   Various sorts. When in doubt, use ON_qsort().
00099   ON_qsort - quick sort.
00100   ON_hsort = hearp sort.
00101 Parameters
00102   base - [in]
00103     array of count elements
00104   count - [in]
00105     number of elements in the index[] and base[] arrays
00106   sizeof_element - [in]
00107     number of bytes between consecutive elements in the
00108     base[] array.
00109   compare - [in]
00110     Comparison function a la qsort().  The context parameter
00111     is pass as the third argument.
00112   context - [in]
00113     pointer passed as the third argument to compare().
00114 Remarks:
00115   As a rule, use quick sort unless extensive tests in your case
00116   prove that heap sort is faster. 
00117   
00118   This implementation of quick sort is generally faster than 
00119   heap sort, even when the input arrays are nearly sorted.
00120   The only common case when heap sort is faster occurs when
00121   the arrays are strictly "chevron" (3,2,1,2,3) or "carat" 
00122   (1,2,3,2,1) ordered, and in these cases heap sort is about
00123   50% faster.  If the "chevron" or "caret" ordered arrays 
00124   have a little randomness added, the two algorithms have 
00125   the same speed.
00126 */
00127 ON_DECL
00128 void ON_hsort( 
00129         void* base,
00130         size_t count,
00131         size_t sizeof_element,
00132         int (*compare)(const void*,const void*)
00133         );
00134 
00135 ON_DECL
00136 void ON_qsort( 
00137         void* base,
00138         size_t count,
00139         size_t sizeof_element,
00140         int (*compare)(const void*,const void*)
00141         );
00142 
00143 ON_DECL
00144 void ON_hsort( 
00145         void* base,
00146         size_t count,
00147         size_t sizeof_element,
00148         int (*compare)(void*,const void*,const void*),
00149         void* context
00150         );
00151 
00152 ON_DECL
00153 void ON_qsort( 
00154         void* base,
00155         size_t count,
00156         size_t sizeof_element,
00157         int (*compare)(void*,const void*,const void*),
00158         void* context
00159         );
00160 
00161 /*
00162 Description:
00163   Sort an array of doubles in place.
00164 Parameters:
00165   sort_algorithm - [in]  
00166     ON::quick_sort (best in general) or ON::heap_sort
00167     Use ON::heap_sort only if you have done extensive testing with
00168     optimized release builds and are confident heap sort is 
00169     significantly faster in your case.
00170   a - [in / out] 
00171     The values in a[] are sorted so that a[i] <= a[i+1].
00172     a[] cannot contain NaNs.
00173   nel - [in]
00174     length of array a[]
00175 */
00176 ON_DECL
00177 void ON_SortDoubleArray( 
00178         ON::sort_algorithm sort_algorithm,
00179         double* a,
00180         size_t nel
00181         );
00182 
00183 /*
00184 Description:
00185   Sort an array of ints in place.
00186 Parameters:
00187   sort_algorithm - [in]  
00188     ON::quick_sort (best in general) or ON::heap_sort
00189     Use ON::heap_sort only if you have done extensive testing with
00190     optimized release builds and are confident heap sort is 
00191     significantly faster in your case.
00192   a - [in / out] 
00193     The values in a[] are sorted so that a[i] <= a[i+1].
00194   nel - [in]
00195     length of array a[]
00196 */
00197 ON_DECL
00198 void ON_SortIntArray(
00199         ON::sort_algorithm sort_algorithm,
00200         int* a,
00201         size_t nel
00202         );
00203 
00204 /*
00205 Description:
00206   Sort an array of unsigned ints in place.
00207 Parameters:
00208   sort_algorithm - [in]  
00209     ON::quick_sort (best in general) or ON::heap_sort
00210     Use ON::heap_sort only if you have done extensive testing with
00211     optimized release builds and are confident heap sort is 
00212     significantly faster in your case.
00213   a - [in / out] 
00214     The values in a[] are sorted so that a[i] <= a[i+1].
00215   nel - [in]
00216     length of array a[]
00217 */
00218 ON_DECL
00219 void ON_SortUnsignedIntArray(
00220         ON::sort_algorithm sort_algorithm,
00221         unsigned int* a,
00222         size_t nel
00223         );
00224 
00225 /*
00226 Description:
00227   Sort an array of unsigned null terminated char strings in place.
00228 Parameters:
00229   sort_algorithm - [in]  
00230     ON::quick_sort (best in general) or ON::heap_sort
00231     Use ON::heap_sort only if you have done extensive testing with
00232     optimized release builds and are confident heap sort is 
00233     significantly faster in your case.
00234   a - [in / out] 
00235     The values in a[] are sorted so that strcmp(a[i],a[i+1]) <= 0.
00236   nel - [in]
00237     length of array a[]
00238 */
00239 ON_DECL
00240 void ON_SortStringArray(
00241         ON::sort_algorithm sort_algorithm,
00242         char** a,
00243         size_t nel
00244         );
00245 
00246 ON_DECL
00247 const int* ON_BinarySearchIntArray( 
00248           int key, 
00249           const int* base, 
00250           size_t nel
00251           );
00252 
00253 ON_DECL
00254 const unsigned int* ON_BinarySearchUnsignedIntArray( 
00255           unsigned int key, 
00256           const unsigned int* base, 
00257           size_t nel
00258           );
00259 
00260 ON_DECL
00261 const double* ON_BinarySearchDoubleArray( 
00262           double key, 
00263           const double* base, 
00264           size_t nel
00265           );
00266 
00267 
00268 
00269 /*
00270   This class is intended to be used to determine if a file's
00271   contents have changed.
00272 */
00273 class ON_CLASS ON_CheckSum
00274 {
00275 public:
00276   ON_CheckSum();
00277   ~ON_CheckSum();
00278 
00279   static const ON_CheckSum UnsetCheckSum;
00280 
00281   // zeros all fields.
00282   void Zero();
00283 
00284   /*
00285   Returns:
00286     True if checksum is set.
00287   */
00288   bool IsSet() const;
00289 
00290   // C++ default operator=, operator==,
00291   // and copy constructor work fine.
00292 
00293   /*
00294   Descripton:
00295     Set check sum values for a buffer
00296   Parameters:
00297     size - [in] 
00298       number of bytes in buffer
00299     buffer - [in]  
00300     time - [in]
00301       last modified time in seconds since Jan 1, 1970, UCT
00302   Returns:
00303     True if checksum is set.
00304   */
00305   bool SetBufferCheckSum( 
00306     size_t size, 
00307     const void* buffer,
00308     time_t time
00309    );
00310 
00311   /*
00312   Descripton:
00313     Set check sum values for a file.
00314   Parameters:
00315     fp - [in] pointer to a file opened with ON:FileOpen(...,"rb")
00316   Returns:
00317     True if checksum is set.
00318   */
00319   bool SetFileCheckSum( 
00320     FILE* fp
00321    );
00322 
00323   /*
00324   Descripton:
00325     Set check sum values for a file.
00326   Parameters:
00327     filename - [in] name of file.
00328   Returns:
00329     True if checksum is set.
00330   */
00331   bool SetFileCheckSum( 
00332     const wchar_t* filename
00333    );
00334 
00335   /*
00336   Description:
00337     Test buffer to see if it has a matching checksum.
00338   Paramters:
00339     size - [in]   size in bytes
00340     buffer - [in]
00341   Returns:
00342     True if the buffer has a matching checksum.
00343   */
00344   bool CheckBuffer( 
00345     size_t size, 
00346     const void* buffer
00347     ) const;
00348 
00349   /*
00350   Description:
00351     Test buffer to see if it has a matching checksum.
00352   Paramters:
00353     fp - [in] pointer to file opened with ON::OpenFile(...,"rb")
00354     bSkipTimeCheck - [in] if true, the time of last
00355        modification is not checked.
00356   Returns:
00357     True if the file has a matching checksum.
00358   */
00359   bool CheckFile( 
00360     FILE* fp,
00361     bool bSkipTimeCheck = false
00362     ) const;
00363 
00364   /*
00365   Description:
00366     Test buffer to see if it has a matching checksum.
00367   Paramters:
00368     filename - [in]
00369     bSkipTimeCheck - [in] if true, the time of last
00370        modification is not checked.
00371   Returns:
00372     True if the file has a matching checksum.
00373   */
00374   bool CheckFile( 
00375     const wchar_t* filename,
00376     bool bSkipTimeCheck = false
00377     ) const;
00378 
00379   bool Write(class ON_BinaryArchive&) const;
00380   bool Read(class ON_BinaryArchive&);
00381 
00382   void Dump(class ON_TextLog&) const;
00383 
00384 public:
00385   size_t     m_size;   // bytes in the file.
00386   time_t     m_time;   // last modified time in seconds since Jan 1, 1970, UCT
00387   ON__UINT32 m_crc[8]; // crc's
00388 };
00389 
00391 // 
00392 // ON_String is a char (a.k.a single byte or ascii) string
00393 //
00394 // ON_wString is a wide char (a.k.a double byte or unicode) string
00395 //
00396 
00397 class ON_String;  // char (a.k.a single byte or ascii) string
00398 class ON_wString; // wide character (a.k.a double byte or unicode) string
00399 
00404 
00405 class ON_CLASS ON_String
00406 {
00407 public:
00408 
00409 // Constructors
00410         ON_String();
00411         ON_String( const ON_String& );
00412 
00413         ON_String( const char* );
00414         ON_String( const char*, int /*length*/ );        // from substring
00415         ON_String( char, int = 1 /* repeat count */ );   
00416 
00417         ON_String( const unsigned char* );
00418         ON_String( const unsigned char*, int /*length*/ );        // from substring
00419         ON_String( unsigned char, int = 1 /* repeat count */ ); 
00420   
00421   // construct a UTF-8 string string from a UTF-16 string.
00422         ON_String( const wchar_t* src );  // src = UTF-16 string
00423         ON_String( const wchar_t* src, int length ); // from a UTF-16 substring
00424   ON_String( const ON_wString& src ); // src = UTF-16 string
00425 
00426 #if defined(ON_OS_WINDOWS)
00427   // Windows support
00428         bool LoadResourceString( HINSTANCE, UINT); // load from Windows string resource
00429                                                                                                          // 2047 chars max
00430 #endif
00431 
00432   void Create();
00433   void Destroy(); // releases any memory and initializes to default empty string
00434   void EmergencyDestroy();
00435 
00436   /*
00437   Description:
00438     Enables reference counting.  I limited cases, this is useful 
00439     for large strings or strings that are frequently passed around.
00440     Reference counted strings must be carefully managed in
00441     when multi-threading is used.
00442   Parameters:
00443     If EnableReferenceCounting()
00444     is not called, then the string will not be referanceThe default is to not use
00445     reference counted strings.
00446   */
00447   void EnableReferenceCounting( bool bEnable );
00448 
00449   /*
00450   Returns:
00451     True if the string is reference counted.
00452   */
00453   bool IsReferenceCounted() const;
00454 
00455 
00456   // Attributes & Operations
00457         // as an array of characters
00458         int Length() const;
00459         bool IsEmpty() const; // returns true if length == 0 
00460   void Empty();   // sets length to zero - if possible, memory is retained
00461 
00462         char& operator[](int);
00463         char operator[](int) const;
00464   char GetAt(int) const;
00465         void SetAt(int, char);
00466         void SetAt(int, unsigned char);
00467         operator const char*() const;  // as a C string
00468 
00469         // overloaded assignment
00470         ON_String& operator=(const ON_String&);
00471         ON_String& operator=(char);
00472         ON_String& operator=(const char*);
00473         ON_String& operator=(unsigned char);
00474         ON_String& operator=(const unsigned char*);
00475         ON_String& operator=(const wchar_t* src); // src = UTF-16 string, result is a UTF-8 string
00476         ON_String& operator=(const ON_wString& src);  // src = UTF-16 string, result is a UTF-8 string
00477 
00478   // operator+()
00479   ON_String operator+(const ON_String&) const;
00480   ON_String operator+(char) const;
00481   ON_String operator+(unsigned char) const;
00482   ON_String operator+(const char*) const;
00483   ON_String operator+(const unsigned char*) const;
00484 
00485         // string comparison 
00486   bool operator==(const ON_String&) const;
00487   bool operator==(const char*)const ;
00488   bool operator!=(const ON_String&)const ;
00489   bool operator!=(const char*)const ;
00490   bool operator<(const ON_String&)const ;
00491   bool operator<(const char*)const ;
00492   bool operator>(const ON_String&)const ;
00493   bool operator>(const char*)const ;
00494   bool operator<=(const ON_String&)const ;
00495   bool operator<=(const char*)const ;
00496   bool operator>=(const ON_String&)const ;
00497   bool operator>=(const char*)const ;
00498 
00499   // string concatenation
00500   void Append( const char*, int ); // append specified number of characters
00501   void Append( const unsigned char*, int ); // append specified number of characters
00502         const ON_String& operator+=(const ON_String&);
00503         const ON_String& operator+=(char);
00504         const ON_String& operator+=(unsigned char);
00505         const ON_String& operator+=(const char*);
00506         const ON_String& operator+=(const unsigned char*);
00507 
00508         // string comparison 
00509   // If this < string, returns < 0.
00510   // If this = string, returns 0.
00511   // If this < string, returns > 0.
00512         int Compare( const char* ) const;
00513         int Compare( const unsigned char* ) const;
00514 
00515         int CompareNoCase( const char* ) const;
00516         int CompareNoCase( const unsigned char* ) const;
00517 
00518   // Description:
00519   //   Simple case sensitive wildcard matching. A question mark (?) in the
00520   //   pattern matches a single character.  An asterisk (*) in the pattern
00521   //   mathes zero or more occurances of any character.
00522   //
00523   // Parameters:
00524   //   pattern - [in] pattern string where ? and * are wild cards.
00525   //
00526   // Returns:
00527   //   true if the string mathes the wild card pattern.
00528         bool WildCardMatch( const char* ) const;
00529         bool WildCardMatch( const unsigned char* ) const;
00530 
00531   // Description:
00532   //   Simple case insensitive wildcard matching. A question mark (?) in the
00533   //   pattern matches a single character.  An asterisk (*) in the pattern
00534   //   mathes zero or more occurances of any character.
00535   //
00536   // Parameters:
00537   //   pattern - [in] pattern string where ? and * are wild cards.
00538   //
00539   // Returns:
00540   //   true if the string mathes the wild card pattern.
00541         bool WildCardMatchNoCase( const char* ) const;
00542         bool WildCardMatchNoCase( const unsigned char* ) const;
00543 
00544   /*
00545   Description:
00546     Replace all substrings that match token1 with token2
00547   Parameters:
00548     token1 - [in]
00549     token2 - [in]
00550   Returns:
00551     Number of times token1 was replaced with token2.
00552   */
00553   int Replace( const char* token1, const char* token2 );
00554   int Replace( const unsigned char* token1, const unsigned char* token2 );
00555   int Replace( char token1, char token2 );
00556   int Replace( unsigned char token1, unsigned char token2 );
00557 
00558 
00559         // simple sub-string extraction
00560         ON_String Mid(
00561     int, // index of first char
00562     int  // count
00563     ) const;
00564         ON_String Mid(
00565     int // index of first char
00566     ) const;
00567         ON_String Left(
00568     int // number of chars to keep
00569     ) const;
00570         ON_String Right(
00571     int // number of chars to keep
00572     ) const;
00573 
00574         // upper/lower/reverse conversion
00575         void MakeUpper();
00576         void MakeLower();
00577         void MakeReverse();
00578   void TrimLeft(const char* = NULL);
00579   void TrimRight(const char* = NULL);
00580   void TrimLeftAndRight(const char* = NULL);
00581 
00582   // remove occurrences of chRemove
00583         int Remove( const char chRemove);
00584 
00585         // searching (return starting index, or -1 if not found)
00586         // look for a single character match
00587         int Find(char) const;
00588         int Find(unsigned char) const;
00589         int ReverseFind(char) const;
00590         int ReverseFind(unsigned char) const;
00591 
00592         // look for a specific sub-string
00593         int Find(const char*) const;
00594         int Find(const unsigned char*) const;
00595 
00596         // simple formatting
00597         void ON_MSC_CDECL Format( const char*, ...);
00598         void ON_MSC_CDECL Format( const unsigned char*, ...);
00599 
00600         // Low level access to string contents as character array
00601         void ReserveArray(size_t); // make sure internal array has at least
00602                           // the requested capacity.
00603         void ShrinkArray();     // shrink internal storage to minimum size
00604   void SetLength(size_t);    // set length (<=capacity)
00605   char* Array();
00606   const char* Array() const;
00607 
00608   /*
00609   Returns:
00610     Total number of bytes of memory used by this class.
00611     (For use in ON_Object::SizeOf() overrides.
00612   */
00613   unsigned int SizeOf() const;
00614 
00615   ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
00616 
00617   /*
00618   Description:
00619     Find the locations in a path the specify the drive, directory,
00620     file name and file extension.
00621   Parameters:
00622     path - [in]
00623       path to split
00624     drive - [out] (pass null if you don't need the drive)
00625       If drive is not null and the path parameter contains a Windows 
00626       drive specification, then the returned value of *drive will
00627       either be empty or the Windows drive letter followed by
00628       the trailing colon.
00629     dir - [out] (pass null if you don't need the directory)
00630       If dir is not null and the path parameter contains a
00631       directory specification, then the returned value of *dir
00632       will be the directory specification including the trailing
00633       slash.
00634     fname - [out] (pass null if you don't need the file name)
00635       If fname is not null and the path parameter contains a
00636       file name specification, then the returned value of *fname
00637       will be the file name.
00638     ext - [out] (pass null if you don't need the extension)
00639       If ext is not null and the path parameter contains a
00640       file extension specification, then the returned value of
00641       *ext will be the file extension including the initial
00642       '.' character.
00643   Remarks:
00644     This function will treat a front slash ( / ) and a back slash
00645     ( \ ) as directory separators.  Because this function parses
00646     file names store in .3dm files and the .3dm file may have been
00647     written on a Windows computer and then read on a another
00648     computer, it looks for a drive dpecification even when the
00649     operating system is not Windows.
00650     This function will not return an directory that does not
00651     end with a trailing slash.
00652     This function will not return an empty filename and a non-empty
00653     extension.
00654     This function parses the path string according to these rules.
00655     It does not check the actual file system to see if the answer
00656     is correct.
00657   See Also:
00658     on_splitpath
00659   */
00660   static void SplitPath( 
00661     const char* path,
00662     ON_String* drive,
00663     ON_String* dir,
00664     ON_String* fname,
00665     ON_String* ext
00666     );
00667 
00668 // Implementation
00669 public:
00670         ~ON_String();
00671 
00672 protected:
00673         char* m_s; // pointer to ref counted string array
00674              // m_s - 12 bytes points at the string's ON_aStringHeader
00675 
00676         // implementation helpers
00677         struct ON_aStringHeader* Header() const;
00678         void CreateArray(int);
00679   void CopyArray();
00680   void CopyToArray( const ON_String& );
00681   void CopyToArray( int, const char* );
00682   void CopyToArray( int, const unsigned char* );
00683   void CopyToArray( int, const wchar_t* );
00684   void AppendToArray( const ON_String& );
00685   void AppendToArray( int, const char* );
00686   void AppendToArray( int, const unsigned char* );
00687         static int Length(const char*);  // handles NULL pointers without crashing
00688         static int Length(const unsigned char*);  // handles NULL pointers without crashing
00689 };
00690 
00691 
00696 //
00697 // ON_wString
00698 //
00699 
00700 class ON_CLASS ON_wString
00701 {
00702 public:
00703 
00704 // Constructors
00705         ON_wString();
00706         ON_wString( const ON_wString& );
00707 
00708         ON_wString( const ON_String& src ); // src = UTF-8 string
00709 
00710         ON_wString( const char* src ); // src = nul; terminated UTF-8 string
00711         ON_wString( const char* src, int /*length*/ );  // from UTF-8 substring
00712         ON_wString( char, int = 1 /* repeat count */ );   
00713 
00714         ON_wString( const unsigned char* src); // src = nul; terminated UTF-8 string
00715         ON_wString( const unsigned char*src, int /*length*/ );        // from UTF-8 substring
00716         ON_wString( unsigned char, int = 1 /* repeat count */ ); 
00717   
00718         ON_wString( const wchar_t* );
00719         ON_wString( const wchar_t*, int /*length*/ );        // from substring
00720         ON_wString( wchar_t, int = 1 /* repeat count */ );   
00721 
00722 #if defined(ON_OS_WINDOWS)
00723   // Windows support
00724         bool LoadResourceString(HINSTANCE, UINT); // load from string resource
00725                                                                                                         // 2047 characters max
00726 #endif
00727 
00728   void Create();
00729   void Destroy(); // releases any memory and initializes to default empty string
00730   void EmergencyDestroy();
00731 
00732   /*
00733   Description:
00734     Enables reference counting.  I limited cases, this is useful 
00735     for large strings or strings that are frequently passed around.
00736     Reference counted strings must be carefully managed in
00737     when multi-threading is used.
00738   Parameters:
00739     If EnableReferenceCounting()
00740     is not called, then the string will not be referanceThe default is to not use
00741     reference counted strings.
00742   */
00743   void EnableReferenceCounting( bool bEnable );
00744 
00745   /*
00746   Returns:
00747     True if the string is reference counted.
00748   */
00749   bool IsReferenceCounted() const;
00750 
00751 // Attributes & Operations
00752         // as an array of characters
00753         int Length() const;
00754         bool IsEmpty() const;
00755   void Empty();   // sets length to zero - if possible, memory is retained
00756 
00757         wchar_t& operator[](int);
00758         wchar_t operator[](int) const;
00759   wchar_t GetAt(int) const;
00760         void SetAt(int, char);
00761         void SetAt(int, unsigned char);
00762         void SetAt(int, wchar_t);
00763         operator const wchar_t*() const;  // as a UNICODE string
00764 
00765         // overloaded assignment
00766         const ON_wString& operator=(const ON_wString&);
00767         const ON_wString& operator=(const ON_String& src); // src = UTF-8 string
00768         const ON_wString& operator=(char);
00769         const ON_wString& operator=(const char* src); // src = UTF-8 string
00770         const ON_wString& operator=(unsigned char);
00771         const ON_wString& operator=(const unsigned char* src); // src = UTF-8 string
00772   const ON_wString& operator=(wchar_t);
00773   const ON_wString& operator=(const wchar_t*);
00774 
00775         // string concatenation
00776   void Append( const char* sUTF8, int ); // append specified number of elements from a UTF-8 string
00777   void Append( const unsigned char* sUTF8, int ); // append specified number of elements from a UTF-8 string
00778   void Append( const wchar_t*, int ); // append specified number of elements
00779         const ON_wString& operator+=(const ON_wString&);
00780         const ON_wString& operator+=(const ON_String& sUTF8); // append UTF-8 string
00781         const ON_wString& operator+=(char);
00782         const ON_wString& operator+=(unsigned char);
00783         const ON_wString& operator+=(wchar_t);
00784         const ON_wString& operator+=(const char* sUTF8); // append UTF-8 string
00785         const ON_wString& operator+=(const unsigned char* sUTF8); // append UTF-8 string
00786         const ON_wString& operator+=(const wchar_t*);
00787 
00788   // operator+()
00789   ON_wString operator+(const ON_wString&) const;
00790   ON_wString operator+(const ON_String& sUTF8) const; // concatinate with a UTF-8 string
00791   ON_wString operator+(char) const;
00792   ON_wString operator+(unsigned char) const;
00793   ON_wString operator+(wchar_t) const;
00794   ON_wString operator+(const char* sUTF8) const; // concatinate with a UTF-8 string
00795   ON_wString operator+(const unsigned char* sUTF8) const; // concatinate with a UTF-8 string
00796   ON_wString operator+(const wchar_t*) const;
00797 
00798         // string comparison 
00799   bool operator==(const ON_wString&) const;
00800   bool operator==(const wchar_t*) const;
00801   bool operator!=(const ON_wString&) const;
00802   bool operator!=(const wchar_t*) const;
00803   bool operator<(const ON_wString&) const;
00804   bool operator<(const wchar_t*) const;
00805   bool operator>(const ON_wString&) const;
00806   bool operator>(const wchar_t*) const;
00807   bool operator<=(const ON_wString&) const;
00808   bool operator<=(const wchar_t*) const;
00809   bool operator>=(const ON_wString&) const;
00810   bool operator>=(const wchar_t*) const;
00811 
00812         // string comparison 
00813   // If this < string, returns < 0.
00814   // If this == string, returns 0.
00815   // If this < string, returns > 0.
00816         int Compare( const char* sUTF8 ) const; // compare to UTF-8 string
00817         int Compare( const unsigned char* sUTF8 ) const; // compare to UTF-8 string
00818         int Compare( const wchar_t* ) const;
00819 
00820         int CompareNoCase( const char* sUTF8) const; // compare to UTF-8 string
00821         int CompareNoCase( const unsigned char* sUTF8) const; // compare to UTF-8 string
00822         int CompareNoCase( const wchar_t* ) const;
00823 
00824   // Description:
00825   //   Simple case sensitive wildcard matching. A question mark (?) in the
00826   //   pattern matches a single character.  An asterisk (*) in the pattern
00827   //   mathes zero or more occurances of any character.
00828   //
00829   // Parameters:
00830   //   pattern - [in] pattern string where ? and * are wild cards.
00831   //
00832   // Returns:
00833   //   true if the string mathes the wild card pattern.
00834         bool WildCardMatch( const wchar_t* ) const;
00835 
00836   // Description:
00837   //   Simple case insensitive wildcard matching. A question mark (?) in the
00838   //   pattern matches a single character.  An asterisk (*) in the pattern
00839   //   mathes zero or more occurances of any character.
00840   //
00841   // Parameters:
00842   //   pattern - [in] pattern string where ? and * are wild cards.
00843   //
00844   // Returns:
00845   //   true if the string mathes the wild card pattern.
00846         bool WildCardMatchNoCase( const wchar_t* ) const;
00847 
00848   /*
00849   Description:
00850     Replace all substrings that match token1 with token2
00851   Parameters:
00852     token1 - [in]
00853     token2 - [in]
00854   Returns:
00855     Number of times toke1 was replaced with token2
00856   */
00857   int Replace( const wchar_t* token1, const wchar_t* token2 );
00858   int Replace( wchar_t token1, wchar_t token2 );
00859 
00860   /*
00861   Description:
00862     Replaces all characters in the string whose values are
00863     not '0-9', 'A-Z', or 'a-z' with a percent sign followed
00864     by a 2 digit hex value.
00865   */
00866   void UrlEncode();
00867 
00868   /*
00869   Description:
00870     Replaces all %xx where xx a two digit hexadecimal number,
00871     with a single character. Returns false if the orginal
00872     string contained 
00873   */
00874   bool UrlDecode();
00875 
00876   /*
00877   Description:
00878     Replace all white-space characters with the token.
00879     If token is zero, the string will end up with
00880     internal 0's
00881   Parameters:
00882     token - [in]
00883     whitespace - [in] if not null, this is a 0 terminated
00884       string that lists the characters considered to be 
00885       white space.  If null, then (1,2,...,32,127) is used.
00886   Returns:
00887     Number of whitespace characters replaced.
00888   See Also:
00889     ON_wString::RemoveWhiteSpace
00890   */
00891   int ReplaceWhiteSpace( wchar_t token, const wchar_t* whitespace = 0 );
00892 
00893   /*
00894   Description:
00895     Removes all white-space characters with the token.
00896   Parameters:
00897     whitespace - [in] if not null, this is a 0 terminated
00898       string that lists the characters considered to be 
00899       white space.  If null, then (1,2,...,32,127) is used.
00900   Returns:
00901     Number of whitespace characters removed.
00902   See Also:
00903     ON_wString::ReplaceWhiteSpace
00904   */
00905   int RemoveWhiteSpace( const wchar_t* whitespace = 0 );
00906 
00907   // simple sub-string extraction
00908         ON_wString Mid(
00909     int, // index of first char
00910     int  // count
00911     ) const;
00912         ON_wString Mid(
00913     int // index of first char
00914     ) const;
00915         ON_wString Left(
00916     int // number of chars to keep
00917     ) const;
00918         ON_wString Right(
00919     int // number of chars to keep
00920     ) const;
00921 
00922         // upper/lower/reverse conversion
00923         void MakeUpper();
00924         void MakeLower();
00925         void MakeReverse();
00926   void TrimLeft(const wchar_t* = NULL);
00927   void TrimRight(const wchar_t* = NULL);
00928   void TrimLeftAndRight(const wchar_t* = NULL);
00929 
00930   /*
00931   Description:
00932     Remove all occurrences of c.
00933   */
00934         int Remove( wchar_t c);
00935 
00936         // searching (return starting index, or -1 if not found)
00937         // look for a single character match
00938         int Find(char) const;
00939         int Find(unsigned char) const;
00940         int Find(wchar_t) const;
00941         int ReverseFind(char) const;
00942         int ReverseFind(unsigned char) const;
00943         int ReverseFind(wchar_t) const;
00944 
00945         // look for a specific sub-string
00946         int Find(const char*) const;
00947         int Find(const unsigned char*) const;
00948         int Find(const wchar_t*) const;
00949 
00950 
00951         // simple formatting - be careful with %s in format string
00952         void ON_MSC_CDECL Format( const char*, ...);
00953         void ON_MSC_CDECL Format( const unsigned char*, ...);
00954         void ON_MSC_CDECL Format( const wchar_t*, ...);
00955 
00956         // Low level access to string contents as character array
00957         void ReserveArray(size_t); // make sure internal array has at least
00958                           // the requested capacity.
00959         void ShrinkArray();     // shrink internal storage to minimum size
00960   void SetLength(size_t); // set length (<=capacity)
00961   wchar_t* Array();
00962   const wchar_t* Array() const;
00963 
00964   /*
00965   Returns:
00966     Total number of bytes of memory used by this class.
00967     (For use in ON_Object::SizeOf() overrides.
00968   */
00969   unsigned int SizeOf() const;
00970 
00971   /*
00972   Returns:
00973     CRC of the string.
00974   */
00975   ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
00976 
00977   /*
00978   Returns:
00979     CRC of the lower case version of the string. Useful
00980     for case insensitive CRCs and hash codes.
00981   */
00982   ON__UINT32 DataCRCLower(ON__UINT32 current_remainder) const;
00983 
00984   /*
00985   Description:
00986     Find the locations in a path the specify the drive, directory,
00987     file name and file extension.
00988   Parameters:
00989     path - [in]
00990       path to split
00991     drive - [out] (pass null if you don't need the drive)
00992       If drive is not null and the path parameter contains a Windows 
00993       drive specification, then the returned value of *drive will
00994       either be empty or the Windows drive letter followed by
00995       the trailing colon.
00996     dir - [out] (pass null if you don't need the directory)
00997       If dir is not null and the path parameter contains a
00998       directory specification, then the returned value of *dir
00999       will be the directory specification including the trailing
01000       slash.
01001     fname - [out] (pass null if you don't need the file name)
01002       If fname is not null and the path parameter contains a
01003       file name specification, then the returned value of *fname
01004       will be the file name.
01005     ext - [out] (pass null if you don't need the extension)
01006       If ext is not null and the path parameter contains a
01007       file extension specification, then the returned value of
01008       *ext will be the file extension including the initial
01009       '.' character.
01010   Remarks:
01011     This function will treat a front slash ( / ) and a back slash
01012     ( \ ) as directory separators.  Because this function parses
01013     file names store in .3dm files and the .3dm file may have been
01014     written on a Windows computer and then read on a another
01015     computer, it looks for a drive dpecification even when the
01016     operating system is not Windows.
01017     This function will not return an directory that does not
01018     end with a trailing slash.
01019     This function will not return an empty filename and a non-empty
01020     extension.
01021     This function parses the path string according to these rules.
01022     It does not check the actual file system to see if the answer
01023     is correct.
01024   See Also:
01025     on_splitpath
01026     on_wsplitpath
01027   */
01028   static void SplitPath( 
01029     const char* path,
01030     ON_wString* drive,
01031     ON_wString* dir,
01032     ON_wString* fname,
01033     ON_wString* ext
01034     );
01035 
01036   static void SplitPath( 
01037     const wchar_t* path,
01038     ON_wString* drive,
01039     ON_wString* dir,
01040     ON_wString* fname,
01041     ON_wString* ext
01042     );
01043 // Implementation
01044 public:
01045         ~ON_wString();
01046 
01047 protected:
01048         wchar_t* m_s; // pointer to ref counted string array
01049                 // m_s - 12 bytes points at the string's ON_wStringHeader
01050 
01051         // implementation helpers
01052         struct ON_wStringHeader* Header() const;
01053         void CreateArray(int);
01054   void CopyArray();
01055   void CopyToArray( const ON_wString& );
01056   void CopyToArray( int, const char* );
01057   void CopyToArray( int, const unsigned char* );
01058   void CopyToArray( int, const wchar_t* );
01059   void AppendToArray( const ON_wString& );
01060   void AppendToArray( int, const char* );
01061   void AppendToArray( int, const unsigned char* );
01062   void AppendToArray( int, const wchar_t* );
01063         static int Length(const char*);  // handles NULL pointers without crashing
01064         static int Length(const unsigned char*);  // handles NULL pointers without crashing
01065         static int Length(const wchar_t*); // handles NULL pointers without crashing
01066 };
01067 
01068 class ON_CLASS ON_UnitSystem
01069 {
01070 public:
01071   ON_UnitSystem();   // default constructor units are millimeters.
01072   ~ON_UnitSystem();
01073 
01074   ON_UnitSystem(ON::unit_system);
01075   ON_UnitSystem& operator=(ON::unit_system);
01076 
01077   bool operator==(const ON_UnitSystem&);
01078   bool operator!=(const ON_UnitSystem&);
01079 
01080   bool IsValid() const;
01081 
01082   void Default(); // millimeters = default unit system
01083 
01084   bool Read( class ON_BinaryArchive& );
01085   bool Write( class ON_BinaryArchive& ) const;
01086   void Dump( class ON_TextLog& ) const;
01087 
01088   ON::unit_system m_unit_system;
01089 
01090   // The m_custom_unit_... settings apply when m_unit_system = ON::custom_unit_system
01091   double m_custom_unit_scale;      // 1 meter = m_custom_unit_scale custom units
01092   ON_wString m_custom_unit_name;   // name of custom units
01093 
01094   // Custom units example:
01095   //    1 Nautical league = 5556 meters
01096   //    So, if you wanted your unit system to be nautical leagues
01097   //    your ON_UnitSystem would be
01098   //      m_unit_system       = ON::custom_unit_system
01099   //      m_custom_unit_scale = 1.0/5556.0 = 0.0001799856...
01100   //      m_custom_unit_name  = "Nautical leagues"
01101 };
01102 
01103 
01104 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:03