Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

vtkStringOps.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * $Id: vtkStringOps.h,v 1.4 2004/08/10 07:37:21 xpxqx Exp $ 00004 * 00005 * Copyright (c) 2004 Sean McInerney 00006 * All rights reserved. 00007 * 00008 * See Copyright.txt or http://vtkextensions.sourceforge.net/Copyright.html 00009 * for details. 00010 * 00011 * This software is distributed WITHOUT ANY WARRANTY; without even 00012 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the above copyright notice for more information. 00014 * 00015 */ 00016 #ifndef VTK_STRING_OPS_H_ 00017 # define VTK_STRING_OPS_H_ 00018 # include "vtkExtensionsCommonConfigure.h" // vtkExtensions configuration 00019 # include "vtkExtensionsTypes.h" // vtkExtensions types 00020 # include "vtkExtensionsExceptions.h" // vtkExtensions exceptions 00021 // VTK Common 00022 # include "vtkIOStream.h" // '<<' operator 00023 // C++ forwarding ANSI C 00024 # include <cerrno> // errno 00025 00026 VTK_EXTENSIONS_NAMESPACE_BEGIN 00027 00036 class VTK_EXTENSIONS_COMMON_EXPORT vtkStringOps 00037 { 00038 public: 00039 00041 template <typename T> 00042 static inline vtkBoolType IsSpace (T const& ch) THROW_SPEC(); 00043 00047 template <typename T> 00048 static inline vtkBoolType IsWhiteSpace (T const& ch) THROW_SPEC(); 00049 00054 template <typename T> 00055 static inline vtkBoolType IsLatin1 (T const& ch) THROW_SPEC(); 00056 static inline vtkBoolType IsLatin1 (char const& ch) THROW_SPEC(); 00057 static inline vtkBoolType IsLatin1 (unsigned char const& ch) THROW_SPEC(); 00064 template <typename T> 00065 static inline vtkBoolType IsChar (T const& ch) THROW_SPEC(); 00066 static inline vtkBoolType IsChar (char const& ch) THROW_SPEC(); 00067 static inline vtkBoolType IsChar (unsigned char const& ch) THROW_SPEC(); 00071 template <typename T> 00072 static inline vtkBoolType IsMemberOf (T const& ch, 00073 const T* const& set) THROW_SPEC(); 00074 00076 template <typename T> 00077 static inline vtkBoolType IsUpper (T const& ch) THROW_SPEC(); 00078 00080 template <typename T> 00081 static inline vtkBoolType IsLower (T const& ch) THROW_SPEC(); 00082 00084 template <typename T> 00085 static inline vtkBoolType IsAlpha (T const& ch) THROW_SPEC(); 00086 00089 template <typename T> 00090 static inline vtkBoolType IsDigit (T const& ch) THROW_SPEC(); 00091 static inline vtkBoolType IsDigit (char const& ch) THROW_SPEC(); 00092 static inline vtkBoolType IsDigit (unsigned char const& ch) THROW_SPEC(); 00097 template <typename T> 00098 static inline vtkBoolType IsHexDigit (T const& ch) THROW_SPEC(); 00099 static inline vtkBoolType IsHexDigit (char const& ch) THROW_SPEC(); 00100 static inline vtkBoolType IsHexDigit (unsigned char const& ch) 00101 THROW_SPEC(); 00105 template <typename T> 00106 static inline vtkBoolType IsAlnum (T const& ch) THROW_SPEC(); 00107 00110 template <typename T> 00111 static inline vtkBoolType IsCombiningChar (T const& ch) THROW_SPEC(); 00112 static inline vtkBoolType IsCombiningChar (char const& ch) THROW_SPEC(); 00113 static inline vtkBoolType IsCombiningChar (unsigned char const& ch) 00114 THROW_SPEC(); 00119 template <typename T> 00120 static inline vtkBoolType IsBaseChar (T const& ch) THROW_SPEC(); 00121 static inline vtkBoolType IsBaseChar (char const& ch) THROW_SPEC(); 00122 static inline vtkBoolType IsBaseChar (unsigned char const& ch) 00123 THROW_SPEC(); 00128 template <typename T> 00129 static inline vtkBoolType IsIdeographic (T const& ch) THROW_SPEC(); 00130 static inline vtkBoolType IsIdeographic (char const& ch) THROW_SPEC(); 00131 static inline vtkBoolType IsIdeographic (unsigned char const& ch) 00132 THROW_SPEC(); 00136 template <typename T> 00137 static inline vtkBoolType IsLetter (T const& ch) THROW_SPEC(); 00138 00141 template <typename T> 00142 static inline vtkBoolType IsExtender (T const& ch) THROW_SPEC(); 00143 static inline vtkBoolType IsExtender (char const& ch) THROW_SPEC(); 00144 static inline vtkBoolType IsExtender (unsigned char const& ch) 00145 THROW_SPEC(); 00149 template <typename T> 00150 static inline vtkBoolType IsNameChar (T const& ch) THROW_SPEC(); 00151 00153 template <typename T> 00154 static inline vtkBoolType IsNCNameChar (T const& ch) THROW_SPEC(); 00155 00157 template <typename T> 00158 static inline vtkBoolType IsPubidChar (T const& ch) THROW_SPEC(); 00159 00171 template <typename T> 00172 static inline T* CreateEmptyString (void); 00173 00175 template <typename T> 00176 static inline vtkBoolType IsNull (const T* const& str) THROW_SPEC(); 00177 00179 template <typename T> 00180 static inline vtkBoolType IsEmpty (const T* const& str) THROW_SPEC(); 00181 00186 template <typename T> 00187 static inline T* ToLower (const T* const& a); 00188 00193 template <typename T> 00194 static inline T* ToUpper (const T* const& a); 00195 00200 template <typename T> 00201 static inline vtkSizeType Length (const T* const& str) THROW_SPEC(); 00202 00207 template <typename T> 00208 static inline vtkBoolType IsAllWhiteSpace (const T* const& str) 00209 THROW_SPEC(); 00210 00216 template <typename T> 00217 static inline vtkBoolType IsAllWhiteSpace (const T* const& str, 00218 int len) 00219 THROW_SPEC(); 00220 00226 template <typename T> 00227 static inline void Concatenate (T* const& dst, 00228 const T* const& src) THROW_SPEC(); 00229 00236 template <typename T> 00237 static inline void Concatenate (T* const& dst, 00238 const T* const& src, 00239 const vtkSizeType dstMax) THROW_SPEC(); 00240 00248 template <typename T> 00249 static inline void Concatenate (T* const& dst, 00250 const T* const& src, 00251 const vtkSizeType dstMax, 00252 const vtkSizeType srcSize) THROW_SPEC(); 00253 00259 template <typename T> 00260 static inline void Concatenate (T* const& dst, 00261 T const& ch) THROW_SPEC(); 00262 00269 template <typename T> 00270 static inline void Concatenate (T* const& dst, 00271 T const& ch, 00272 const vtkSizeType dstMax) THROW_SPEC(); 00273 00279 template <typename T> 00280 static inline void Copy (T* const& dst, 00281 const T* const& src) THROW_SPEC(); 00282 00289 template <typename T> 00290 static inline void Copy (T* const& dst, 00291 const T* const& src, 00292 const vtkSizeType dstMax) THROW_SPEC(); 00293 00298 template <typename T> 00299 static inline void Trim (T* const& str) THROW_SPEC(); 00300 00310 template <typename T> 00311 static inline T* Duplicate (const T* const& src); 00312 00314 template <typename T> 00315 static inline int IndexOf (const T* const& str, 00316 const T ch) THROW_SPEC(); 00317 00322 template <typename T> 00323 static inline int IndexOf (const T* const& str, 00324 const T ch, 00325 const vtkSizeType from) THROW_SPEC(); 00326 00328 template <typename T> 00329 static inline int LastIndexOf (const T* const& str, 00330 const T ch) THROW_SPEC(); 00331 00336 template <typename T> 00337 static inline int LastIndexOf (const T* const& str, 00338 const T ch, 00339 const vtkSizeType from) THROW_SPEC(); 00340 00342 template <typename T> 00343 static inline int IndexNotOf (const T* const& str, 00344 const T ch) THROW_SPEC(); 00345 00350 template <typename T> 00351 static inline int IndexNotOf (const T* const& str, 00352 const T ch, 00353 const vtkSizeType from) THROW_SPEC(); 00354 00356 template <typename T> 00357 static inline int LastIndexNotOf (const T* const& str, 00358 const T ch) THROW_SPEC(); 00359 00364 template <typename T> 00365 static inline int LastIndexNotOf (const T* const& str, 00366 const T ch, 00367 const vtkSizeType from) THROW_SPEC(); 00368 00375 template <typename T> 00376 static inline void Move (T* const& dst, 00377 const T* const& src, 00378 const vtkSizeType length); 00379 00388 static inline char* Transcode (const vtkUTF8ChType* const); 00389 static inline char* Transcode (const vtkUTF16ChType* const); 00390 static inline vtkUTF16ChType* Transcode (const char* const); 00393 static vtkBoolType Transcode (const vtkUTF8ChType* const& in, 00394 char** out, 00395 const int max) 00396 THROW_SPEC(); 00397 00398 static vtkBoolType Transcode (const vtkUTF16ChType* const& in, 00399 char** out, 00400 const int max) 00401 THROW_SPEC(); 00402 00403 static vtkBoolType Transcode (const char* const& in, 00404 vtkUTF8ChType** out, 00405 const int max) 00406 THROW_SPEC(); 00407 00408 static vtkBoolType Transcode (const vtkUTF16ChType* const& in, 00409 vtkUTF8ChType** out, 00410 const int max) 00411 THROW_SPEC(); 00412 00413 static vtkBoolType Transcode (const char* const& in, 00414 vtkUTF16ChType** out, 00415 const int max) 00416 THROW_SPEC(); 00417 00418 static vtkBoolType Transcode (const vtkUTF8ChType* const& in, 00419 vtkUTF16ChType** out, 00420 const int max) 00421 THROW_SPEC(); 00422 00438 template <typename T> 00439 static inline T* SubString (const T* const& src, 00440 const int start); 00441 00456 template <typename T> 00457 static inline T* SubString (const T* const& src, 00458 const int start, 00459 const int end); 00460 00470 template <typename T> 00471 static inline void SubString (T* const& dst, 00472 const T* const& src, 00473 const int start) THROW_SPEC(); 00474 00483 template <typename T> 00484 static inline void SubString (T* const& dst, 00485 const T* const& src, 00486 const int start, 00487 const int end) THROW_SPEC(); 00488 00490 template <typename T> 00491 static inline vtkBoolType ValidateRegion (const T* const& str1, 00492 const vtkSSizeType offset1, 00493 const T* const& str2, 00494 const vtkSSizeType offset2, 00495 const vtkSizeType length) 00496 THROW_SPEC(); 00497 00500 template <typename T> 00501 static inline vtkBoolType Equals (const T* const& str1, 00502 const T* const& str2) THROW_SPEC(); 00503 template <typename T> 00504 static inline vtkBoolType Equals (const T* const& str1, 00505 const T* const& str2, 00506 const vtkSizeType length) THROW_SPEC(); 00507 template <typename T> 00508 static inline vtkBoolType Equals (const T* const& str1, 00509 const vtkSSizeType offset1, 00510 const T* const& str2, 00511 const vtkSSizeType offset2, 00512 const vtkSizeType length) THROW_SPEC(); 00513 template <typename T> 00514 static inline vtkBoolType Equals (const T* const& str, 00515 T const& ch) THROW_SPEC(); 00523 template <typename T> 00524 static inline vtkBoolType EqualsI (const T* const& str1, 00525 const T* const& str2) THROW_SPEC(); 00526 template <typename T> 00527 static inline vtkBoolType EqualsI (const T* const& str1, 00528 const T* const& str2, 00529 const vtkSizeType length) THROW_SPEC(); 00530 template <typename T> 00531 static inline vtkBoolType EqualsI (const T* const& str1, 00532 const vtkSSizeType offset1, 00533 const T* const& str2, 00534 const vtkSSizeType offset2, 00535 const vtkSizeType length) THROW_SPEC(); 00536 template <typename T> 00537 static inline vtkBoolType EqualsI (const T* const& str, 00538 T const& ch) THROW_SPEC(); 00551 template <typename T> 00552 static inline int Compare (const T* const& str1, 00553 const T* const& str2) THROW_SPEC(); 00554 template <typename T> 00555 static inline int Compare (const T* const& str1, 00556 const T* const& str2, 00557 const vtkSizeType length); 00568 template <typename T> 00569 static inline vtkBoolType IsPrefix (const T* const& test, 00570 const T* const& prefix); 00571 00580 template <typename T> 00581 static inline vtkBoolType IsSuffix (const T* const& test, 00582 const T* const& suffix); 00583 00595 template <typename T> 00596 static inline const T* FindAny (const T* const& test, 00597 const T* const& searchList); 00598 00607 template <typename T> 00608 static inline int FindSubString (const T* const& test, 00609 const T* const& subStr); 00610 00618 template <typename T> 00619 static inline vtkBoolType TextToBin (const T* const&, unsigned int&); 00620 00631 template <typename T> 00632 static inline int ParseIntVec (const T* const& str, 00633 unsigned int len, 00634 int* data); 00635 00639 template <typename T> 00640 static inline int ParseInt (const T* const& str); 00641 00652 template <typename T> 00653 static inline int ParseFloatVec (const T* const& str, 00654 unsigned int len, 00655 float* data); 00656 00660 template <typename T> 00661 static inline float ParseFloat (const T* const& str); 00662 00673 template <typename T> 00674 static inline int ParseDoubleVec (const T* const& str, 00675 unsigned int len, 00676 double* data); 00677 00682 template <typename T> 00683 static inline double ParseDouble (const T* const& str); 00684 00695 template <typename T> 00696 static inline int ParseUintVec (const T* const& str, 00697 unsigned int len, 00698 unsigned int* data); 00699 00704 template <typename T> 00705 static inline unsigned int ParseUint (const T* const& str); 00706 00711 template <typename T> 00712 static inline vtkBoolType ParseBoolean (const T* const& str); 00713 00723 template <typename T> 00724 static inline T** Tokenize (const T* const& src, 00725 unsigned int maxTokens = 128); 00726 00727 template <typename T> 00728 static inline T** Tokenize (const T* const& src, 00729 const T* const& delimiters, 00730 unsigned int maxTokens = 128); 00731 00732 template <typename T> 00733 static inline vtkBoolType IsAbsoluteURI (const T* uri) THROW_SPEC(); 00734 00746 template <typename T> 00747 static inline void ParseURI (const T* uri, 00748 T* buffer, 00749 const vtkSizeType bufLen, 00750 T** scheme, 00751 T** authority, 00752 T** path, 00753 T** query, 00754 T** fragment) THROW_SPEC(); 00755 00765 template <typename T> 00766 static inline void ResolveURIReference (const T* baseURI, 00767 const T* referenceURI, 00768 T* buffer, 00769 const vtkSizeType bufLen); 00770 00777 template <typename T> 00778 static inline vtkUint32Type Hash (const T* const& a) THROW_SPEC(); 00779 template <typename T> 00780 static inline vtkUint32Type HashN (const T* const& a, 00781 const vtkSizeType n) THROW_SPEC(); 00786 template <typename T> 00787 static inline vtkUint32Type Hash (const T* const& str, 00788 const vtkSizeType modulus) THROW_SPEC(); 00789 00791 template <typename T> 00792 static inline vtkUint32Type HashN (const T* const& str, 00793 const vtkSizeType n, 00794 const vtkSizeType modulus) THROW_SPEC(); 00805 static char* UTF8toLatin1 (const vtkUTF8ChType* const& str) 00806 THROW_SPEC(); 00807 static char* UTF16toLatin1 (const vtkUTF16ChType* const& str) 00808 THROW_SPEC(); 00809 static vtkUTF8ChType* Latin1toUTF8 (const char* const& str) 00810 THROW_SPEC(); 00811 static vtkUTF8ChType* UTF16toUTF8 (const vtkUTF16ChType* const& str) 00812 THROW_SPEC(); 00813 static vtkUTF16ChType* Latin1toUTF16 (const char* const& str) 00814 THROW_SPEC(); 00815 static vtkUTF16ChType* UTF8toUTF16 (const vtkUTF8ChType* const& str) 00816 THROW_SPEC(); 00826 static char* UCS2toUTF7 (const vtkUCS2ChType* const& str) 00827 THROW_SPEC(); 00828 static vtkUCS2ChType* UTF7toUCS2 (const char* const& str) 00829 THROW_SPEC(); 00833 template <typename T> 00834 static inline T* FileRootname (const T* const& filename); 00835 00837 template <typename T> 00838 static inline const T* FileTailPointer (const T* const& fileName); 00839 00841 template <typename T> 00842 static inline const T* FileExtensionPointer (const T* const& fileName); 00843 00845 template <typename T> 00846 static inline T* FileExtension (const T* const& filename); 00847 00849 template <typename T> 00850 static inline T* FileDirname (const T* const& filename); 00851 00853 template <typename T> 00854 static inline T* FileJoin (const T* const& head, const T* const& tail); 00855 00857 template <typename T> 00858 static inline T* FileJoin (const T** const& list, 00859 vtkBoolType absolute = VTK_TRUE); 00860 00863 template <typename T> 00864 static inline vtkBoolType CreateDirectory (const T* const& dirName, 00865 mode_t mode); 00866 static inline vtkBoolType CreateDirectory (const char* const& dirName, 00867 mode_t mode); 00872 static vtkBoolType GetCWD (char* buffer, vtkSizeType size); 00873 static inline vtkBoolType GetCWD (char** buffer); 00874 static inline char* GetCWD (void); 00878 template <typename T> 00879 static inline vtkBoolType CanReadDirectory (const T* const& dirName); 00880 00882 template <typename T> 00883 static inline vtkBoolType CanReadFile (const T* const& fileName); 00884 00886 template <typename T> 00887 static inline vtkBoolType CanWriteDirectory (const T* const& dirName); 00888 00891 template <typename T> 00892 static inline vtkBoolType CanWriteFile (const T* const& fileName); 00893 static inline vtkBoolType CanWriteFile (const char* const& fileName); 00897 template <typename T> 00898 static inline vtkBoolType CheckDirectoryExists (const T* const& dirName); 00899 00901 template <typename T> 00902 static inline vtkBoolType CheckFileExists (const T* const& fileName); 00903 00904 # if 1 00905 00911 template <typename T> 00912 static inline T* GetRelativePrefix (const T* const& fileName, 00913 const T* const& rootPath) 00914 THROW_SPEC(); 00915 # else 00916 00917 template <typename T> 00918 static inline T** GetRelativePrefix (const T* const& fileName, 00919 const T* const& rootPath) 00920 THROW_SPEC(); 00921 # endif /* 0 */ 00922 00923 # if 1 00924 00930 template <typename T> 00931 static inline T* GetRelativeDirPrefix (const T* const& dirName, 00932 const T* const& rootPath, 00933 T** const& pfxResult = (T **) 0) 00934 THROW_SPEC(); 00935 # else 00936 00937 template <typename T> 00938 static inline T** GetRelativeDirPrefix (const T* const& dirName, 00939 const T* const& rootPath) 00940 THROW_SPEC(); 00941 # endif /* 0 */ 00942 00944 template <typename T> 00945 static inline void Release (T** const&); 00946 00948 template <typename T> 00949 static inline void Release (T*** const&); 00950 00955 class ToLatin1 00956 { 00957 public: 00961 ToLatin1 (const char* const a) 00962 : m(vtkStringOps::Duplicate(a)) {} 00963 ToLatin1 (const vtkUTF8ChType* const a) 00964 : m(vtkStringOps::Transcode(a)) {} 00965 ToLatin1 (const vtkUTF16ChType* const a) 00966 : m(vtkStringOps::Transcode(a)) {} 00967 ~ToLatin1() { vtkStringOps::Release(&m); } 00968 const char* data() const { return m; } 00969 00970 private: 00971 char* m; // This is the Unicode UTF-8 format of the string. 00972 }; 00973 00978 class ToUTF8 00979 { 00980 public: 00981 ToUTF8 (const char* const a) 00982 : m(vtkStringOps::Latin1toUTF8(a)) {} 00986 ToUTF8 (const vtkUTF8ChType* const a) 00987 : m(vtkStringOps::Duplicate(a)) {} 00988 ToUTF8 (const vtkUTF16ChType* const a) 00989 : m(vtkStringOps::UTF16toUTF8(a)) {} 00990 ~ToUTF8() { vtkStringOps::Release(&m); } 00991 const vtkUTF8ChType* data() const { return m; } 00992 00993 private: 00994 vtkUTF8ChType* m; // This is the Unicode UTF-8 format of the string. 00995 }; 00996 01001 class ToUTF16 01002 { 01003 public: 01004 ToUTF16 (const char* const a) 01005 : m(vtkStringOps::Transcode(a)) {} 01006 ToUTF16 (const vtkUTF8ChType* const a) 01007 : m(vtkStringOps::UTF8toUTF16(a)) {} 01011 ToUTF16 (const vtkUTF16ChType* const a) 01012 : m(vtkStringOps::Duplicate(a)) {} 01013 ~ToUTF16() { vtkStringOps::Release(&m); } 01014 const vtkUTF16ChType* data() const { return m; } 01015 01016 private: 01017 vtkUTF16ChType* m; // This is the Unicode UTF-16 format of the string. 01018 }; 01019 01021 template <typename T> 01022 class Janitor 01023 { 01024 public: 01025 Janitor (T* const& a) THROW_SPEC() : m(a) {} 01026 ~Janitor() { vtkStringOps::Release(&m); } 01027 void set (T* const& a) THROW_SPEC() { this->m = a; } 01028 const T* data (void) const THROW_SPEC() { return this->m; } 01029 01030 private: 01031 T* m; 01032 }; 01033 01034 protected: 01036 static long Strtol (const char* str, char** end, int base = 10); 01037 static double Strtod (const char* str, char** end); 01038 static unsigned long Strtoul (const char* str, char** end, int base = 10); 01042 static void* Memccpy (void* const dstPtr, const void* const srcPtr, 01043 int endValue, vtkSizeType numBytes); 01044 01045 static void* Memchr (void* const ptr, int value, vtkSizeType numBytes); 01046 01047 static int Memcmp (const void* const ptr1, const void* const ptr2, 01048 vtkSizeType numBytes); 01049 01050 static void* Memcpy (void* const dstPtr, const void* const srcPtr, 01051 vtkSizeType numBytes); 01052 01053 static void* Memmove (void* const dstPtr, const void* const srcPtr, 01054 vtkSizeType numBytes); 01055 01056 static void* Memset (void* const ptr, int value, vtkSizeType numBytes); 01060 static vtkBoolType Mkdir (const char* const& dirName, mode_t mode); 01061 01062 static vtkBoolType CanStatFile (const char* const& aPathName); 01063 01064 static vtkBoolType FileIsDirectory (const char* const& aPathName); 01065 01066 static vtkBoolType FileIsReadable (const char* const& aPathName); 01067 01068 static vtkBoolType FileIsWritable (const char* const& aPathName); 01069 01070 static vtkBoolType FileExists (const char* const& aPathName); 01073 private: 01074 vtkStringOps (void); // Not implemented. 01075 ~vtkStringOps (void); // Not implemented. 01076 vtkStringOps (const vtkStringOps&); // Not implemented. 01077 void operator= (const vtkStringOps&); // Not implemented. 01078 }; 01079 01080 # define LATIN1_TO_UTF16(_str) \ 01081 vtkStringOps::ToUTF16(static_cast<const char*>(_str)).data() 01082 # define UTF8_TO_UTF16(_str) \ 01083 vtkStringOps::ToUTF16(static_cast<const vtkUTF8ChType*>(_str)).data() 01084 # define LATIN1_TO_UTF8(_str) \ 01085 vtkStringOps::ToUTF8(static_cast<const char*>(_str)).data() 01086 # define UTF16_TO_UTF8(_str) \ 01087 vtkStringOps::ToUTF8(static_cast<const vtkUTF16ChType*>(_str)).data() 01088 # define UTF8_TO_LATIN1(_str) \ 01089 vtkStringOps::ToLatin1(static_cast<const vtkUTF8ChType*>(_str)).data() 01090 # define UTF16_TO_LATIN1(_str) \ 01091 vtkStringOps::ToLatin1(static_cast<const vtkUTF16ChType*>(_str)).data() 01092 # define XML_TO_LATIN1(_str) \ 01093 vtkStringOps::ToLatin1(_str).data() 01094 01095 # define LATIN1_TMP(_x) \ 01096 vtkStringOps::Janitor<char>(static_cast<char*>(_x)).data() 01097 # define UTF8_TMP(_x) \ 01098 vtkStringOps::Janitor<vtkUTF8ChType>(static_cast<vtkUTF8ChType*>(_x)).data() 01099 # define UTF16_TMP(_x) \ 01100 vtkStringOps::Janitor<vtkUTF16ChType>(static_cast<vtkUTF16ChType*>(_x)).data() 01101 01109 # define vtkSetXMLStringBodyMacro(_name, _arg) \ 01110 { \ 01111 vtkDebugMacro(<< "Set" << #_name "(\"" \ 01112 << (_arg!=NULL?XML_TO_LATIN1(_arg):"") << "\")" ); \ 01113 if ( this->_name == NULL && _arg == NULL ) { return; } \ 01114 if ( this->_name != NULL && _arg != NULL && \ 01115 vtkStringOps::Equals(this->_name, _arg) ) { return; } \ 01116 if (this->_name != NULL) { vtkStringOps::Release(&(this->_name)); } \ 01117 if (_arg != NULL) { this->_name = vtkStringOps::Duplicate(_arg); } \ 01118 this->Modified(); \ 01119 } 01120 01130 # define vtkCxxSetXMLStringMacro(_class, _name, _type) \ 01131 void _class::Set##_name (const _type* const& _arg) \ 01132 { \ 01133 vtkSetXMLStringBodyMacro(_name, _arg); \ 01134 } 01135 01145 # define vtkSetXMLStringMacro(_name, _type) \ 01146 void Set##_name (const _type* const& _arg) \ 01147 { \ 01148 vtkSetXMLStringBodyMacro(_name, _arg); \ 01149 } 01150 01160 # define vtkCxxGetXMLStringMacro(_class, _name, _type) \ 01161 _type* _class::Get##_name (void) const \ 01162 { \ 01163 vtkDebugMacro(<< "Get" << #_name "() returning \"" \ 01164 << (this->_name!=NULL?XML_TO_LATIN1(this->_name):"") \ 01165 << "\"."); \ 01166 return this->_name; \ 01167 } 01168 01178 # define vtkGetXMLStringMacro(_name, _type) \ 01179 _type* Get##_name (void) const \ 01180 { \ 01181 vtkDebugMacro(<< "Get" << #_name "() returning \"" \ 01182 << (this->_name!=NULL?XML_TO_LATIN1(this->_name):"") \ 01183 << "\"."); \ 01184 return this->_name; \ 01185 } 01186 01188 # define vtkCxxXMLStringMacro(_class, _name, _type) \ 01189 vtkCxxSetXMLStringMacro(_class, _name, _type); \ 01190 vtkCxxGetXMLStringMacro(_class, _name, _type); 01191 01192 01193 // ---------------------------------------------------------------------------- 01194 inline char* 01195 vtkStringOps::Transcode (const vtkUTF8ChType* const a) 01196 { return UTF8toLatin1(a); } 01197 01198 inline char* 01199 vtkStringOps::Transcode (const vtkUTF16ChType* const a) 01200 { return UTF16toLatin1(a); } 01201 01202 inline vtkUTF16ChType* 01203 vtkStringOps::Transcode (const char* const a) 01204 { return Latin1toUTF16(a); } 01205 01206 // ---------------------------------------------------------------------------- 01207 template <typename T> 01208 inline vtkBoolType 01209 vtkStringOps::IsSpace (T const& a) THROW_SPEC() 01210 { 01211 return ( (T(0x9) == a) || (T(0xA) == a) || (T(0xD) == a) || (T(0x20) == a) 01212 ? VTK_TRUE : VTK_FALSE ); 01213 } 01214 01215 // ---------------------------------------------------------------------------- 01216 template <typename T> 01217 inline vtkBoolType 01218 vtkStringOps::IsWhiteSpace (T const& a) THROW_SPEC() 01219 { 01220 return ( (T(0x9) == a) || (T(0xA) == a) || (T(0xD) == a) || (T(0x20) == a) 01221 ? VTK_TRUE : VTK_FALSE ); 01222 } 01223 01224 // ---------------------------------------------------------------------------- 01225 template <typename T> 01226 inline vtkBoolType 01227 vtkStringOps::IsLatin1 (T const& a) THROW_SPEC() 01228 { 01229 return ( vtkStringOps::IsWhiteSpace(a) || 01230 ((T(0x21) <= a) && (a <= T(0xFF))) 01231 ? VTK_TRUE : VTK_FALSE ); 01232 } 01233 01234 inline vtkBoolType 01235 vtkStringOps::IsLatin1 (char const& a) THROW_SPEC() 01236 { 01237 return ( vtkStringOps::IsWhiteSpace(a) || 01238 ((char(0x21) <= a) && (a <= char(0x7A))) 01239 ? VTK_TRUE : VTK_FALSE ); 01240 } 01241 01242 inline vtkBoolType 01243 vtkStringOps::IsLatin1 (unsigned char const& a) THROW_SPEC() 01244 { 01245 return ( vtkStringOps::IsWhiteSpace(a) || 01246 (((unsigned char)(0x21) <= a)/* && (a <= T(0x7A))*/) 01247 ? VTK_TRUE : VTK_FALSE ); 01248 } 01249 01250 // ---------------------------------------------------------------------------- 01251 template <typename T> 01252 inline vtkBoolType 01253 vtkStringOps::IsChar (T const& a) THROW_SPEC() 01254 { 01255 return ( vtkStringOps::IsLatin1(a) || 01256 ((T(0x100) <= a) && (a <= T(0xD7FF))) || 01257 ((T(0xE000) <= a) && (a <= T(0xFFFD))) || 01258 ((T(0x10000) <= a) && (a <= T(0x10FFFF))) 01259 ? VTK_TRUE : VTK_FALSE ); 01260 } 01261 01262 inline vtkBoolType 01263 vtkStringOps::IsChar (char const& a) THROW_SPEC() 01264 { 01265 return vtkStringOps::IsLatin1(a); 01266 } 01267 01268 inline vtkBoolType 01269 vtkStringOps::IsChar (unsigned char const& a) THROW_SPEC() 01270 { 01271 return vtkStringOps::IsLatin1(a); 01272 } 01273 01274 // ---------------------------------------------------------------------------- 01275 template <typename T> 01276 inline vtkBoolType 01277 vtkStringOps::IsMemberOf (T const& a, const T* const& aSet) THROW_SPEC() 01278 { 01279 const T* p = aSet; 01280 01281 while (*p != T(0)/*'<control> NUL'*/) 01282 if (a == *p++) 01283 return VTK_TRUE; 01284 01285 return VTK_FALSE; 01286 } 01287 01288 // ---------------------------------------------------------------------------- 01289 template <typename T> 01290 inline vtkBoolType 01291 vtkStringOps::IsUpper (T const& a) THROW_SPEC() 01292 { 01293 return ( (T(0x0041) <= a) && (a <= T(0x005A)) 01294 ? VTK_TRUE : VTK_FALSE ); 01295 } 01296 01297 // ---------------------------------------------------------------------------- 01298 template <typename T> 01299 inline vtkBoolType 01300 vtkStringOps::IsLower (T const& a) THROW_SPEC() 01301 { 01302 return ( (T(0x0061) <= a) && (a <= T(0x007A)) 01303 ? VTK_TRUE : VTK_FALSE ); 01304 } 01305 01306 // ---------------------------------------------------------------------------- 01307 template <typename T> 01308 inline vtkBoolType 01309 vtkStringOps::IsAlpha (T const& a) THROW_SPEC() 01310 { 01311 return ( vtkStringOps::IsUpper(a) || vtkStringOps::IsLower(a) ); 01312 } 01313 01314 // ---------------------------------------------------------------------------- 01315 template <typename T> 01316 inline vtkBoolType 01317 vtkStringOps::IsDigit (T const& a) THROW_SPEC() 01318 { 01319 return 01320 ( ((T(0x0030) <= a) && (a <= T(0x0039))) || 01321 ((T(0x0660) <= a) && (a <= T(0x0669))) || 01322 ((T(0x06F0) <= a) && (a <= T(0x06F9))) || 01323 ((T(0x0966) <= a) && (a <= T(0x096F))) || 01324 ((T(0x09E6) <= a) && (a <= T(0x09EF))) || 01325 ((T(0x0A66) <= a) && (a <= T(0x0A6F))) || 01326 ((T(0x0AE6) <= a) && (a <= T(0x0AEF))) || 01327 ((T(0x0B66) <= a) && (a <= T(0x0B6F))) || 01328 ((T(0x0BE7) <= a) && (a <= T(0x0BEF))) || 01329 ((T(0x0C66) <= a) && (a <= T(0x0C6F))) || 01330 ((T(0x0CE6) <= a) && (a <= T(0x0CEF))) || 01331 ((T(0x0D66) <= a) && (a <= T(0x0D6F))) || 01332 ((T(0x0E50) <= a) && (a <= T(0x0E59))) || 01333 ((T(0x0ED0) <= a) && (a <= T(0x0ED9))) || 01334 ((T(0x0F20) <= a) && (a <= T(0x0F29))) 01335 ? VTK_TRUE : VTK_FALSE ); 01336 } 01337 01338 inline vtkBoolType 01339 vtkStringOps::IsDigit (char const& a) THROW_SPEC() 01340 { 01341 return ( (char(0x0030) <= a) && (a <= char(0x0039)) 01342 ? VTK_TRUE : VTK_FALSE ); 01343 } 01344 01345 inline vtkBoolType 01346 vtkStringOps::IsDigit (unsigned char const& a) THROW_SPEC() 01347 { 01348 return ( ((unsigned char)(0x0030) <= a) && (a <= (unsigned char)(0x0039)) 01349 ? VTK_TRUE : VTK_FALSE ); 01350 } 01351 01352 // ---------------------------------------------------------------------------- 01353 template <typename T> 01354 inline vtkBoolType 01355 vtkStringOps::IsHexDigit (T const& a) THROW_SPEC() 01356 { 01357 return 01358 ( // [10] DIGIT ZERO..DIGIT NINE 01359 ((T(0x0030) <= a) && (a <= T(0x0039))) || 01360 // [6] LATIN CAPITAL LETTER A..LATIN CAPITAL LETTER F 01361 ((T(0x0041) <= a) && (a <= T(0x0046))) || 01362 // [6] LATIN SMALL LETTER A..LATIN SMALL LETTER F 01363 ((T(0x0061) <= a) && (a <= T(0x0066))) || 01364 // [10] FULLWIDTH DIGIT ZERO..FULLWIDTH DIGIT NINE 01365 ((T(0xFF10) <= a) && (a <= T(0xFF19))) || 01366 // [6] FULLWIDTH LATIN CAPITAL LETTER A..FULLWIDTH LATIN CAPITAL LETTER F 01367 ((T(0xFF21) <= a) && (a <= T(0xFF26))) || 01368 // [6] FULLWIDTH LATIN SMALL LETTER A..FULLWIDTH LATIN SMALL LETTER F 01369 ((T(0xFF41) <= a) && (a <= T(0xFF46))) 01370 ? VTK_TRUE : VTK_FALSE ); 01371 } 01372 01373 inline vtkBoolType 01374 vtkStringOps::IsHexDigit (char const& a) THROW_SPEC() 01375 { 01376 return 01377 ( // [10] DIGIT ZERO..DIGIT NINE 01378 ((char(0x0030) <= a) && (a <= char(0x0039))) || 01379 // [6] LATIN CAPITAL LETTER A..LATIN CAPITAL LETTER F 01380 ((char(0x0041) <= a) && (a <= char(0x0046))) || 01381 // [6] LATIN SMALL LETTER A..LATIN SMALL LETTER F 01382 ((char(0x0061) <= a) && (a <= char(0x0066))) 01383 ? VTK_TRUE : VTK_FALSE ); 01384 } 01385 01386 inline vtkBoolType 01387 vtkStringOps::IsHexDigit (unsigned char const& a) THROW_SPEC() 01388 { 01389 return 01390 ( // [10] DIGIT ZERO..DIGIT NINE 01391 (((unsigned char)(0x0030) <= a) && (a <= (unsigned char)(0x0039))) || 01392 // [6] LATIN CAPITAL LETTER A..LATIN CAPITAL LETTER F 01393 (((unsigned char)(0x0041) <= a) && (a <= (unsigned char)(0x0046))) || 01394 // [6] LATIN SMALL LETTER A..LATIN SMALL LETTER F 01395 (((unsigned char)(0x0061) <= a) && (a <= (unsigned char)(0x0066))) 01396 ? VTK_TRUE : VTK_FALSE ); 01397 } 01398 01399 // ---------------------------------------------------------------------------- 01400 template <typename T> 01401 inline vtkBoolType 01402 vtkStringOps::IsAlnum (T const& a) THROW_SPEC() 01403 { 01404 return (vtkStringOps::IsAlpha(a) || vtkStringOps::IsDigit(a)); 01405 } 01406 01407 // ---------------------------------------------------------------------------- 01408 template <typename T> 01409 inline vtkBoolType 01410 vtkStringOps::IsCombiningChar (T const& a) THROW_SPEC() 01411 { 01412 return 01413 ( ((T(0x0300) <= a) && (a <= T(0x0345))) || 01414 ((T(0x0360) <= a) && (a <= T(0x0361))) || 01415 ((T(0x0483) <= a) && (a <= T(0x0486))) || 01416 ((T(0x0591) <= a) && (a <= T(0x05A1))) || 01417 ((T(0x05A3) <= a) && (a <= T(0x05B9))) || 01418 ((T(0x05BB) <= a) && (a <= T(0x05BD))) || 01419 (T(0x05BF) == a) || 01420 ((T(0x05C1) <= a) && (a <= T(0x05C2))) || 01421 (T(0x05C4) == a) || 01422 ((T(0x064B) <= a) && (a <= T(0x0652))) || 01423 (T(0x0670) == a) || 01424 ((T(0x06D6) <= a) && (a <= T(0x06DC))) || 01425 ((T(0x06DD) <= a) && (a <= T(0x06DF))) || 01426 ((T(0x06E0) <= a) && (a <= T(0x06E4))) || 01427 ((T(0x06E7) <= a) && (a <= T(0x06E8))) || 01428 ((T(0x06EA) <= a) && (a <= T(0x06ED))) || 01429 ((T(0x0901) <= a) && (a <= T(0x0903))) || 01430 (T(0x093C) == a) || 01431 ((T(0x093E) <= a) && (a <= T(0x094C))) || 01432 (T(0x094D) == a) || 01433 ((T(0x0951) <= a) && (a <= T(0x0954))) || 01434 ((T(0x0962) <= a) && (a <= T(0x0963))) || 01435 ((T(0x0981) <= a) && (a <= T(0x0983))) || 01436 (T(0x09BC) == a) || 01437 (T(0x09BE) == a) || 01438 (T(0x09BF) == a) || 01439 ((T(0x09C0) <= a) && (a <= T(0x09C4))) || 01440 ((T(0x09C7) <= a) && (a <= T(0x09C8))) || 01441 ((T(0x09CB) <= a) && (a <= T(0x09CD))) || 01442 (T(0x09D7) == a) || 01443 ((T(0x09E2) <= a) && (a <= T(0x09E3))) || 01444 (T(0x0A02) == a) || 01445 (T(0x0A3C) == a) || 01446 (T(0x0A3E) == a) || 01447 (T(0x0A3F) == a) || 01448 ((T(0x0A40) <= a) && (a <= T(0x0A42))) || 01449 ((T(0x0A47) <= a) && (a <= T(0x0A48))) || 01450 ((T(0x0A4B) <= a) && (a <= T(0x0A4D))) || 01451 ((T(0x0A70) <= a) && (a <= T(0x0A71))) || 01452 ((T(0x0A81) <= a) && (a <= T(0x0A83))) || 01453 (T(0x0ABC) == a) || 01454 ((T(0x0ABE) <= a) && (a <= T(0x0AC5))) || 01455 ((T(0x0AC7) <= a) && (a <= T(0x0AC9))) || 01456 ((T(0x0ACB) <= a) && (a <= T(0x0ACD))) || 01457 ((T(0x0B01) <= a) && (a <= T(0x0B03))) || 01458 (T(0x0B3C) == a) || 01459 ((T(0x0B3E) <= a) && (a <= T(0x0B43))) || 01460 ((T(0x0B47) <= a) && (a <= T(0x0B48))) || 01461 ((T(0x0B4B) <= a) && (a <= T(0x0B4D))) || 01462 ((T(0x0B56) <= a) && (a <= T(0x0B57))) || 01463 ((T(0x0B82) <= a) && (a <= T(0x0B83))) || 01464 ((T(0x0BBE) <= a) && (a <= T(0x0BC2))) || 01465 ((T(0x0BC6) <= a) && (a <= T(0x0BC8))) || 01466 ((T(0x0BCA) <= a) && (a <= T(0x0BCD))) || 01467 (T(0x0BD7) == a) || 01468 ((T(0x0C01) <= a) && (a <= T(0x0C03))) || 01469 ((T(0x0C3E) <= a) && (a <= T(0x0C44))) || 01470 ((T(0x0C46) <= a) && (a <= T(0x0C48))) || 01471 ((T(0x0C4A) <= a) && (a <= T(0x0C4D))) || 01472 ((T(0x0C55) <= a) && (a <= T(0x0C56))) || 01473 ((T(0x0C82) <= a) && (a <= T(0x0C83))) || 01474 ((T(0x0CBE) <= a) && (a <= T(0x0CC4))) || 01475 ((T(0x0CC6) <= a) && (a <= T(0x0CC8))) || 01476 ((T(0x0CCA) <= a) && (a <= T(0x0CCD))) || 01477 ((T(0x0CD5) <= a) && (a <= T(0x0CD6))) || 01478 ((T(0x0D02) <= a) && (a <= T(0x0D03))) || 01479 ((T(0x0D3E) <= a) && (a <= T(0x0D43))) || 01480 ((T(0x0D46) <= a) && (a <= T(0x0D48))) || 01481 ((T(0x0D4A) <= a) && (a <= T(0x0D4D))) || 01482 (T(0x0D57) == a) || 01483 (T(0x0E31) == a) || 01484 ((T(0x0E34) <= a) && (a <= T(0x0E3A))) || 01485 ((T(0x0E47) <= a) && (a <= T(0x0E4E))) || 01486 (T(0x0EB1) == a) || 01487 ((T(0x0EB4) <= a) && (a <= T(0x0EB9))) || 01488 ((T(0x0EBB) <= a) && (a <= T(0x0EBC))) || 01489 ((T(0x0EC8) <= a) && (a <= T(0x0ECD))) || 01490 ((T(0x0F18) <= a) && (a <= T(0x0F19))) || 01491 (T(0x0F35) == a) || 01492 (T(0x0F37) == a) || 01493 (T(0x0F39) == a) || 01494 (T(0x0F3E) == a) || 01495 (T(0x0F3F) == a) || 01496 ((T(0x0F71) <= a) && (a <= T(0x0F84))) || 01497 ((T(0x0F86) <= a) && (a <= T(0x0F8B))) || 01498 ((T(0x0F90) <= a) && (a <= T(0x0F95))) || 01499 (T(0x0F97) == a) || 01500 ((T(0x0F99) <= a) && (a <= T(0x0FAD))) || 01501 ((T(0x0FB1) <= a) && (a <= T(0x0FB7))) || 01502 (T(0x0FB9) == a) || 01503 ((T(0x20D0) <= a) && (a <= T(0x20DC))) || 01504 (T(0x20E1) == a) || 01505 ((T(0x302A) <= a) && (a <= T(0x302F))) || 01506 (T(0x3099) == a) || 01507 (T(0x309A) == a) 01508 ? VTK_TRUE : VTK_FALSE ); 01509 } 01510 01511 inline vtkBoolType 01512 vtkStringOps::IsCombiningChar (char const&) THROW_SPEC() 01513 { 01514 return VTK_FALSE; 01515 } 01516 01517 inline vtkBoolType 01518 vtkStringOps::IsCombiningChar (unsigned char const&) THROW_SPEC() 01519 { 01520 return VTK_FALSE; 01521 } 01522 01523 // ---------------------------------------------------------------------------- 01524 template <typename T> 01525 inline vtkBoolType 01526 vtkStringOps::IsBaseChar (T const& a) THROW_SPEC() 01527 { 01528 return 01529 ( ((T(0x0041) <= a) && (a <= T(0x005A))) || 01530 ((T(0x0061) <= a) && (a <= T(0x007A))) || 01531 ((T(0x00C0) <= a) && (a <= T(0x00D6))) || 01532 ((T(0x00D8) <= a) && (a <= T(0x00F6))) || 01533 ((T(0x00F8) <= a) && (a <= T(0x00FF))) || 01534 ((T(0x0100) <= a) && (a <= T(0x0131))) || 01535 ((T(0x0134) <= a) && (a <= T(0x013E))) || 01536 ((T(0x0141) <= a) && (a <= T(0x0148))) || 01537 ((T(0x014A) <= a) && (a <= T(0x017E))) || 01538 ((T(0x0180) <= a) && (a <= T(0x01C3))) || 01539 ((T(0x01CD) <= a) && (a <= T(0x01F0))) || 01540 ((T(0x01F4) <= a) && (a <= T(0x01F5))) || 01541 ((T(0x01FA) <= a) && (a <= T(0x0217))) || 01542 ((T(0x0250) <= a) && (a <= T(0x02A8))) || 01543 ((T(0x02BB) <= a) && (a <= T(0x02C1))) || 01544 (T(0x0386) == a) || 01545 ((T(0x0388) <= a) && (a <= T(0x038A))) || 01546 (T(0x038C) == a) || 01547 ((T(0x038E) <= a) && (a <= T(0x03A1))) || 01548 ((T(0x03A3) <= a) && (a <= T(0x03CE))) || 01549 ((T(0x03D0) <= a) && (a <= T(0x03D6))) || 01550 (T(0x03DA) == a) || 01551 (T(0x03DC) == a) || 01552 (T(0x03DE) == a) || 01553 (T(0x03E0) == a) || 01554 ((T(0x03E2) <= a) && (a <= T(0x03F3))) || 01555 ((T(0x0401) <= a) && (a <= T(0x040C))) || 01556 ((T(0x040E) <= a) && (a <= T(0x044F))) || 01557 ((T(0x0451) <= a) && (a <= T(0x045C))) || 01558 ((T(0x045E) <= a) && (a <= T(0x0481))) || 01559 ((T(0x0490) <= a) && (a <= T(0x04C4))) || 01560 ((T(0x04C7) <= a) && (a <= T(0x04C8))) || 01561 ((T(0x04CB) <= a) && (a <= T(0x04CC))) || 01562 ((T(0x04D0) <= a) && (a <= T(0x04EB))) || 01563 ((T(0x04EE) <= a) && (a <= T(0x04F5))) || 01564 ((T(0x04F8) <= a) && (a <= T(0x04F9))) || 01565 ((T(0x0531) <= a) && (a <= T(0x0556))) || 01566 (T(0x0559) == a) || 01567 ((T(0x0561) <= a) && (a <= T(0x0586))) || 01568 ((T(0x05D0) <= a) && (a <= T(0x05EA))) || 01569 ((T(0x05F0) <= a) && (a <= T(0x05F2))) || 01570 ((T(0x0621) <= a) && (a <= T(0x063A))) || 01571 ((T(0x0641) <= a) && (a <= T(0x064A))) || 01572 ((T(0x0671) <= a) && (a <= T(0x06B7))) || 01573 ((T(0x06BA) <= a) && (a <= T(0x06BE))) || 01574 ((T(0x06C0) <= a) && (a <= T(0x06CE))) || 01575 ((T(0x06D0) <= a) && (a <= T(0x06D3))) || 01576 (T(0x06D5) == a) || 01577 ((T(0x06E5) <= a) && (a <= T(0x06E6))) || 01578 ((T(0x0905) <= a) && (a <= T(0x0939))) || 01579 (T(0x093D) == a) || 01580 ((T(0x0958) <= a) && (a <= T(0x0961))) || 01581 ((T(0x0985) <= a) && (a <= T(0x098C))) || 01582 ((T(0x098F) <= a) && (a <= T(0x0990))) || 01583 ((T(0x0993) <= a) && (a <= T(0x09A8))) || 01584 ((T(0x09AA) <= a) && (a <= T(0x09B0))) || 01585 (T(0x09B2) == a) || 01586 ((T(0x09B6) <= a) && (a <= T(0x09B9))) || 01587 ((T(0x09DC) <= a) && (a <= T(0x09DD))) || 01588 ((T(0x09DF) <= a) && (a <= T(0x09E1))) || 01589 ((T(0x09F0) <= a) && (a <= T(0x09F1))) || 01590 ((T(0x0A05) <= a) && (a <= T(0x0A0A))) || 01591 ((T(0x0A0F) <= a) && (a <= T(0x0A10))) || 01592 ((T(0x0A13) <= a) && (a <= T(0x0A28))) || 01593 ((T(0x0A2A) <= a) && (a <= T(0x0A30))) || 01594 ((T(0x0A32) <= a) && (a <= T(0x0A33))) || 01595 ((T(0x0A35) <= a) && (a <= T(0x0A36))) || 01596 ((T(0x0A38) <= a) && (a <= T(0x0A39))) || 01597 ((T(0x0A59) <= a) && (a <= T(0x0A5C))) || 01598 (T(0x0A5E) == a) || 01599 ((T(0x0A72) <= a) && (a <= T(0x0A74))) || 01600 ((T(0x0A85) <= a) && (a <= T(0x0A8B))) || 01601 (T(0x0A8D) == a) || 01602 ((T(0x0A8F) <= a) && (a <= T(0x0A91))) || 01603 ((T(0x0A93) <= a) && (a <= T(0x0AA8))) || 01604 ((T(0x0AAA) <= a) && (a <= T(0x0AB0))) || 01605 ((T(0x0AB2) <= a) && (a <= T(0x0AB3))) || 01606 ((T(0x0AB5) <= a) && (a <= T(0x0AB9))) || 01607 (T(0x0ABD) == a) || 01608 (T(0x0AE0) == a) || 01609 ((T(0x0B05) <= a) && (a <= T(0x0B0C))) || 01610 ((T(0x0B0F) <= a) && (a <= T(0x0B10))) || 01611 ((T(0x0B13) <= a) && (a <= T(0x0B28))) || 01612 ((T(0x0B2A) <= a) && (a <= T(0x0B30))) || 01613 ((T(0x0B32) <= a) && (a <= T(0x0B33))) || 01614 ((T(0x0B36) <= a) && (a <= T(0x0B39))) || 01615 (T(0x0B3D) == a) || 01616 ((T(0x0B5C) <= a) && (a <= T(0x0B5D))) || 01617 ((T(0x0B5F) <= a) && (a <= T(0x0B61))) || 01618 ((T(0x0B85) <= a) && (a <= T(0x0B8A))) || 01619 ((T(0x0B8E) <= a) && (a <= T(0x0B90))) || 01620 ((T(0x0B92) <= a) && (a <= T(0x0B95))) || 01621 ((T(0x0B99) <= a) && (a <= T(0x0B9A))) || 01622 (T(0x0B9C) == a) || 01623 ((T(0x0B9E) <= a) && (a <= T(0x0B9F))) || 01624 ((T(0x0BA3) <= a) && (a <= T(0x0BA4))) || 01625 ((T(0x0BA8) <= a) && (a <= T(0x0BAA))) || 01626 ((T(0x0BAE) <= a) && (a <= T(0x0BB5))) || 01627 ((T(0x0BB7) <= a) && (a <= T(0x0BB9))) || 01628 ((T(0x0C05) <= a) && (a <= T(0x0C0C))) || 01629 ((T(0x0C0E) <= a) && (a <= T(0x0C10))) || 01630 ((T(0x0C12) <= a) && (a <= T(0x0C28))) || 01631 ((T(0x0C2A) <= a) && (a <= T(0x0C33))) || 01632 ((T(0x0C35) <= a) && (a <= T(0x0C39))) || 01633 ((T(0x0C60) <= a) && (a <= T(0x0C61))) || 01634 ((T(0x0C85) <= a) && (a <= T(0x0C8C))) || 01635 ((T(0x0C8E) <= a) && (a <= T(0x0C90))) || 01636 ((T(0x0C92) <= a) && (a <= T(0x0CA8))) || 01637 ((T(0x0CAA) <= a) && (a <= T(0x0CB3))) || 01638 ((T(0x0CB5) <= a) && (a <= T(0x0CB9))) || 01639 (T(0x0CDE) == a) || 01640 ((T(0x0CE0) <= a) && (a <= T(0x0CE1))) || 01641 ((T(0x0D05) <= a) && (a <= T(0x0D0C))) || 01642 ((T(0x0D0E) <= a) && (a <= T(0x0D10))) || 01643 ((T(0x0D12) <= a) && (a <= T(0x0D28))) || 01644 ((T(0x0D2A) <= a) && (a <= T(0x0D39))) || 01645 ((T(0x0D60) <= a) && (a <= T(0x0D61))) || 01646 ((T(0x0E01) <= a) && (a <= T(0x0E2E))) || 01647 (T(0x0E30) == a) || 01648 ((T(0x0E32) <= a) && (a <= T(0x0E33))) || 01649 ((T(0x0E40) <= a) && (a <= T(0x0E45))) || 01650 ((T(0x0E81) <= a) && (a <= T(0x0E82))) || 01651 (T(0x0E84) == a) || 01652 ((T(0x0E87) <= a) && (a <= T(0x0E88))) || 01653 (T(0x0E8A) == a) || 01654 (T(0x0E8D) == a) || 01655 ((T(0x0E94) <= a) && (a <= T(0x0E97))) || 01656 ((T(0x0E99) <= a) && (a <= T(0x0E9F))) || 01657 ((T(0x0EA1) <= a) && (a <= T(0x0EA3))) || 01658 (T(0x0EA5) == a) || 01659 (T(0x0EA7) == a) || 01660 ((T(0x0EAA) <= a) && (a <= T(0x0EAB))) || 01661 ((T(0x0EAD) <= a) && (a <= T(0x0EAE))) || 01662 (T(0x0EB0) == a) || 01663 ((T(0x0EB2) <= a) && (a <= T(0x0EB3))) || 01664 (T(0x0EBD) == a) || 01665 ((T(0x0EC0) <= a) && (a <= T(0x0EC4))) || 01666 ((T(0x0F40) <= a) && (a <= T(0x0F47))) || 01667 ((T(0x0F49) <= a) && (a <= T(0x0F69))) || 01668 ((T(0x10A0) <= a) && (a <= T(0x10C5))) || 01669 ((T(0x10D0) <= a) && (a <= T(0x10F6))) || 01670 (T(0x1100) == a) || 01671 ((T(0x1102) <= a) && (a <= T(0x1103))) || 01672 ((T(0x1105) <= a) && (a <= T(0x1107))) || 01673 (T(0x1109) == a) || 01674 ((T(0x110B) <= a) && (a <= T(0x110C))) || 01675 ((T(0x110E) <= a) && (a <= T(0x1112))) || 01676 (T(0x113C) == a) || 01677 (T(0x113E) == a) || 01678 (T(0x1140) == a) || 01679 (T(0x114C) == a) || 01680 (T(0x114E) == a) || 01681 (T(0x1150) == a) || 01682 ((T(0x1154) <= a) && (a <= T(0x1155))) || 01683 (T(0x1159) == a) || 01684 ((T(0x115F) <= a) && (a <= T(0x1161))) || 01685 (T(0x1163) == a) || 01686 (T(0x1165) == a) || 01687 (T(0x1167) == a) || 01688 (T(0x1169) == a) || 01689 ((T(0x116D) <= a) && (a <= T(0x116E))) || 01690 ((T(0x1172) <= a) && (a <= T(0x1173))) || 01691 (T(0x1175) == a) || 01692 (T(0x119E) == a) || 01693 (T(0x11A8) == a) || 01694 (T(0x11AB) == a) || 01695 ((T(0x11AE) <= a) && (a <= T(0x11AF))) || 01696 ((T(0x11B7) <= a) && (a <= T(0x11B8))) || 01697 (T(0x11BA) == a) || 01698 ((T(0x11BC) <= a) && (a <= T(0x11C2))) || 01699 (T(0x11EB) == a) || 01700 (T(0x11F0) == a) || 01701 (T(0x11F9) == a) || 01702 ((T(0x1E00) <= a) && (a <= T(0x1E9B))) || 01703 ((T(0x1EA0) <= a) && (a <= T(0x1EF9))) || 01704 ((T(0x1F00) <= a) && (a <= T(0x1F15))) || 01705 ((T(0x1F18) <= a) && (a <= T(0x1F1D))) || 01706 ((T(0x1F20) <= a) && (a <= T(0x1F45))) || 01707 ((T(0x1F48) <= a) && (a <= T(0x1F4D))) || 01708 ((T(0x1F50) <= a) && (a <= T(0x1F57))) || 01709 (T(0x1F59) == a) || 01710 (T(0x1F5B) == a) || 01711 (T(0x1F5D) == a) || 01712 ((T(0x1F5F) <= a) && (a <= T(0x1F7D))) || 01713 ((T(0x1F80) <= a) && (a <= T(0x1FB4))) || 01714 ((T(0x1FB6) <= a) && (a <= T(0x1FBC))) || 01715 (T(0x1FBE) == a) || 01716 ((T(0x1FC2) <= a) && (a <= T(0x1FC4))) || 01717 ((T(0x1FC6) <= a) && (a <= T(0x1FCC))) || 01718 ((T(0x1FD0) <= a) && (a <= T(0x1FD3))) || 01719 ((T(0x1FD6) <= a) && (a <= T(0x1FDB))) || 01720 ((T(0x1FE0) <= a) && (a <= T(0x1FEC))) || 01721 ((T(0x1FF2) <= a) && (a <= T(0x1FF4))) || 01722 ((T(0x1FF6) <= a) && (a <= T(0x1FFC))) || 01723 (T(0x2126) == a) || 01724 ((T(0x212A) <= a) && (a <= T(0x212B))) || 01725 (T(0x212E) == a) || 01726 ((T(0x2180) <= a) && (a <= T(0x2182))) || 01727 ((T(0x3041) <= a) && (a <= T(0x3094))) || 01728 ((T(0x30A1) <= a) && (a <= T(0x30FA))) || 01729 ((T(0x3105) <= a) && (a <= T(0x312C))) || 01730 ((T(0xAC00) <= a) && (a <= T(0xD7A3))) 01731 ? VTK_TRUE : VTK_FALSE ); 01732 } 01733 01734 inline vtkBoolType 01735 vtkStringOps::IsBaseChar (char const& a) THROW_SPEC() 01736 { 01737 return 01738 ( ((char(0x0041) <= a) && (a <= char(0x005A))) || 01739 ((char(0x0061) <= a) && (a <= char(0x007A))) 01740 ? VTK_TRUE : VTK_FALSE ); 01741 } 01742 01743 inline vtkBoolType 01744 vtkStringOps::IsBaseChar (unsigned char const& a) THROW_SPEC() 01745 { 01746 return 01747 ( (((unsigned char)(0x0041) <= a) && (a <= (unsigned char)(0x005A))) || 01748 (((unsigned char)(0x0061) <= a) && (a <= (unsigned char)(0x007A))) || 01749 (((unsigned char)(0x00C0) <= a) && (a <= (unsigned char)(0x00D6))) || 01750 (((unsigned char)(0x00D8) <= a) && (a <= (unsigned char)(0x00F6))) || 01751 (((unsigned char)(0x00F8) <= a)/* && (a <= (unsigned char)(0x00FF))*/) 01752 ? VTK_TRUE : VTK_FALSE ); 01753 } 01754 01755 // ---------------------------------------------------------------------------- 01756 template <typename T> 01757 inline vtkBoolType 01758 vtkStringOps::IsIdeographic (T const& a) THROW_SPEC() 01759 { 01760 return 01761 ( ((T(0x4E00) <= a) && (a <= T(0x9FA5))) || 01762 (T(0x3007) == a) || 01763 ((T(0x3021) <= a) && (a <= T(0x3029))) 01764 ? VTK_TRUE : VTK_FALSE ); 01765 } 01766 01767 inline vtkBoolType 01768 vtkStringOps::IsIdeographic (char const&) THROW_SPEC() 01769 { 01770 return VTK_FALSE; 01771 } 01772 01773 inline vtkBoolType 01774 vtkStringOps::IsIdeographic (unsigned char const&) THROW_SPEC() 01775 { 01776 return VTK_FALSE; 01777 } 01778 01779 // ---------------------------------------------------------------------------- 01780 template <typename T> 01781 inline vtkBoolType 01782 vtkStringOps::IsLetter (T const& a) THROW_SPEC() 01783 { 01784 return ( vtkStringOps::IsBaseChar(a) || vtkStringOps::IsIdeographic(a) ); 01785 } 01786 01787 // ---------------------------------------------------------------------------- 01788 template <typename T> 01789 inline vtkBoolType 01790 vtkStringOps::IsExtender (T const& a) THROW_SPEC() 01791 { 01792 return 01793 ( (T(0x00B7) == a) || 01794 (T(0x02D0) == a) || 01795 (T(0x02D1) == a) || 01796 (T(0x0387) == a) || 01797 (T(0x0640) == a) || 01798 (T(0x0E46) == a) || 01799 (T(0x0EC6) == a) || 01800 (T(0x3005) == a) || 01801 ((T(0x3031) <= a) && (a <= T(0x3035))) || 01802 ((T(0x309D) <= a) && (a <= T(0x309E))) || 01803 ((T(0x30FC) <= a) && (a <= T(0x30FE))) 01804 ? VTK_TRUE : VTK_FALSE ); 01805 } 01806 01807 inline vtkBoolType 01808 vtkStringOps::IsExtender (char const&) THROW_SPEC() 01809 { 01810 return VTK_FALSE; 01811 } 01812 01813 inline vtkBoolType 01814 vtkStringOps::IsExtender (unsigned char const& a) THROW_SPEC() 01815 { 01816 return ((unsigned char)(0x00B7) == a); 01817 } 01818 01819 // ---------------------------------------------------------------------------- 01820 template <typename T> 01821 inline vtkBoolType 01822 vtkStringOps::IsNameChar (T const& a) THROW_SPEC() 01823 { 01824 return 01825 ( vtkStringOps::IsLetter(a) || 01826 vtkStringOps::IsDigit(a) || 01827 (T(0x002e) == a) || 01828 (T(0x002d) == a) || 01829 (T(0x005f) == a) || 01830 (T(0x003a) == a) || 01831 vtkStringOps::IsCombiningChar(a) || 01832 vtkStringOps::IsExtender(a) 01833 ? VTK_TRUE : VTK_FALSE ); 01834 } 01835 01836 // ---------------------------------------------------------------------------- 01837 template <typename T> 01838 inline vtkBoolType 01839 vtkStringOps::IsNCNameChar (T const& a) THROW_SPEC() 01840 { 01841 return 01842 ( vtkStringOps::IsLetter(c) || 01843 vtkStringOps::IsDigit(c) || 01844 (T(0x002E/* FULL STOP */) == a) || 01845 (T(0x002D/* HYPHEN-MINUS */) == a) || 01846 (T(0x005F/* LOW LINE */) == a) || 01847 vtkStringOps::IsCombiningChar(c) || 01848 vtkStringOps::IsExtender(c) 01849 ? VTK_TRUE : VTK_FALSE ); 01850 } 01851 01852 // ---------------------------------------------------------------------------- 01853 template <typename T> 01854 inline vtkBoolType 01855 vtkStringOps::IsPubidChar (T const& a) THROW_SPEC() 01856 { 01857 return 01858 ( (T(0x0020) == a) || 01859 (T(0x000D) == a) || 01860 (T(0x000A) == a) || // space 01861 ((T(0x0061) <= a) && (a <= T(0x007a))) || // a-z 01862 ((T(0x003F) <= a) && (a <= T(0x005a))) || // ?@A-Z 01863 ((T(0x0027) <= a) && (a <= T(0x003B))) || // '()*+,-./0123456789:; 01864 (T(0x003d) == a) || // = 01865 (T(0x0021) == a) || // ! 01866 ((T(0x0023) <= a) && (a <= T(0x0025))) || // #$% 01867 (T(0x005f) == a) // _ 01868 ? VTK_TRUE : VTK_FALSE ); 01869 } 01870 01871 // ---------------------------------------------------------------------------- 01872 template <typename T> 01873 inline T* 01874 vtkStringOps::CreateEmptyString (void) 01875 { 01876 T* empty = new T [1]; 01877 01878 empty = T(0); 01879 01880 return empty; 01881 } 01882 01883 // ---------------------------------------------------------------------------- 01884 template <typename T> 01885 inline vtkBoolType 01886 vtkStringOps::IsNull (const T* const& a) THROW_SPEC() 01887 { 01888 if (a == (T *) 0) 01889 return VTK_TRUE; 01890 return VTK_FALSE; 01891 } 01892 01893 template <typename T> 01894 inline vtkBoolType 01895 vtkStringOps::IsEmpty (const T* const& a) THROW_SPEC() 01896 { 01897 if (vtkStringOps::IsNull(a) || *a == T(0)/*'<control> NUL'*/) 01898 return VTK_TRUE; 01899 return VTK_FALSE; 01900 } 01901 01902 // ---------------------------------------------------------------------------- 01903 template <typename T> 01904 inline T* 01905 vtkStringOps::ToLower (const T* const& a) 01906 { 01907 if (vtkStringOps::IsEmpty(a)) 01908 return vtkStringOps::CreateEmptyString<T>(); 01909 01910 T* result = Duplicate(a); 01911 01912 for (int i=0; result[i] != T(0)/*'<control> NUL'*/; i++) 01913 result[i] = tolower(result[i]); 01914 01915 return result; 01916 } 01917 01918 template <typename T> 01919 inline T* 01920 vtkStringOps::ToUpper (const T* const& a) 01921 { 01922 if (vtkStringOps::IsEmpty(a)) 01923 return vtkStringOps::CreateEmptyString<T>(); 01924 01925 T* result = Duplicate(a); 01926 01927 for (int i=0; result[i] != T(0)/*'<control> NUL'*/; i++) 01928 result[i] = toupper(result[i]); 01929 01930 return result; 01931 } 01932 01933 // ---------------------------------------------------------------------------- 01934 template <typename T> 01935 inline vtkSizeType 01936 vtkStringOps::Length (const T* const& a) THROW_SPEC() 01937 { 01938 if (vtkStringOps::IsEmpty(a)) 01939 return 0; 01940 01941 const T* ptr = a + 1; 01942 01943 while (*ptr != T(0)/*'<control> NUL'*/) ++ptr; 01944 01945 return vtkSizeType(ptr - a); 01946 } 01947 01948 // ---------------------------------------------------------------------------- 01949 template <typename T> 01950 inline vtkBoolType 01951 vtkStringOps::IsAllWhiteSpace (const T* const& aData) THROW_SPEC() 01952 { 01953 vtkSizeType length; 01954 01955 // usually call from top of overriden CharacterData() methods 01956 if ((length = vtkStringOps::Length(aData)) == 0) 01957 return VTK_TRUE; // early exit - empty string, may never occur?? 01958 01959 if ((length == 1) && (aData[0] == T(0)/*'<control> NUL'*/)) 01960 return VTK_TRUE; // early exit - empty string, may never occur?? 01961 01962 // CR or LF alone 01963 if ((length == 1) && ((aData[0] == T(0x000D)) || (aData[0] == T(0x000A)))) 01964 return VTK_TRUE; 01965 01966 if ((length == 2) && ((aData[0] == T(0x000A)) && (aData[1] == T(0x000D)))) 01967 return VTK_TRUE; // early exit - newline 01968 01969 const int endIndex = length - 1; 01970 01971 if (vtkStringOps::IsWhiteSpace(aData[endIndex])) 01972 { 01973 int index; 01974 01975 for (index=0; index<endIndex; index++) 01976 if (vtkStringOps::IsWhiteSpace(aData[index]) == VTK_FALSE) 01977 break; 01978 01979 if (index == endIndex) 01980 return VTK_TRUE; // early exit - all spaces 01981 } 01982 01983 return VTK_FALSE; 01984 } 01985 01986 template <typename T> 01987 inline vtkBoolType 01988 vtkStringOps::IsAllWhiteSpace (const T* const& aData, 01989 int aLength) THROW_SPEC() 01990 { 01991 // usually call from top of overriden CharacterData() methods 01992 if (aLength == 0) 01993 return VTK_TRUE; // early exit - empty string, may never occur?? 01994 01995 if ((aLength == 1) && (aData[0] == T(0)/*'<control> NUL'*/)) 01996 return VTK_TRUE; // early exit - empty string, may never occur?? 01997 01998 // CR or LF alone 01999 if ((aLength == 1) && ((aData[0] == T(0x000D)) || (aData[0] == T(0x000A)))) 02000 return VTK_TRUE; 02001 02002 // DOS-style CRLF 02003 if ((aLength == 2) && ((aData[0] == T(0x000A)) && (aData[1] == T(0x000D)))) 02004 return VTK_TRUE; 02005 02006 const int endIndex = aLength - 1; 02007 02008 if (vtkStringOps::IsWhiteSpace(aData[endIndex])) 02009 { 02010 int index; 02011 02012 for (index=0; index<endIndex; index++) 02013 if (vtkStringOps::IsWhiteSpace(aData[index]) == VTK_FALSE) 02014 break; 02015 02016 if (index == endIndex) 02017 return VTK_TRUE; // early exit - all spaces 02018 } 02019 02020 return VTK_FALSE; 02021 } 02022 02023 // ---------------------------------------------------------------------------- 02024 template <typename T> 02025 inline void 02026 vtkStringOps::Concatenate (T* const& aDst, 02027 const T* const& aSrc) THROW_SPEC() 02028 { 02029 if (vtkStringOps::IsNull(aDst) || vtkStringOps::IsEmpty(aSrc)) 02030 return; 02031 02032 // Get the starting point for the cat on the target XMLString 02033 vtkSizeType index = vtkStringOps::Length(aDst); 02034 const T* srcPtr = aSrc; 02035 02036 // While the source is not zero, add them to target and bump 02037 while (*srcPtr != T(0)/*'<control> NUL'*/) 02038 aDst[index++] = *srcPtr++; 02039 02040 // Cap off the target where we ended 02041 aDst[index] = T(0)/*'<control> NUL'*/; 02042 } 02043 02044 template <typename T> 02045 inline void 02046 vtkStringOps::Concatenate (T* const& aDst, 02047 const T* const& aSrc, 02048 const vtkSizeType aDstMax) THROW_SPEC() 02049 { 02050 if (vtkStringOps::IsNull(aDst) || vtkStringOps::IsEmpty(aSrc)) 02051 return; 02052 02053 // Get the starting point for the cat on the target XMLString 02054 vtkSizeType index = vtkStringOps::Length(aDst); 02055 02056 if (index < (aDstMax-1)) 02057 { 02058 const T* srcPtr = aSrc; 02059 02060 // While the source is not zero, add them to target and bump 02061 while (*srcPtr != T(0)/*'<control> NUL'*/ && index < (aDstMax - 1)) 02062 aDst[index++] = *srcPtr++; 02063 02064 // Cap off the target where we ended 02065 aDst[index] = T(0)/*'<control> NUL'*/; 02066 } 02067 } 02068 02069 template <typename T> 02070 inline void 02071 vtkStringOps::Concatenate (T* const& aDst, 02072 const T* const& aSrc, 02073 const vtkSizeType aDstMax, 02074 const vtkSizeType aSrcMax) THROW_SPEC() 02075 { 02076 if (vtkStringOps::IsNull(aDst) || vtkStringOps::IsEmpty(aSrc)) 02077 return; 02078 02079 // Get the starting point for the cat on the target XMLString 02080 vtkSizeType dstIndex = vtkStringOps::Length(aDst); 02081 vtkSizeType srcIndex = 0; 02082 02083 if (dstIndex < (aDstMax - 1)) 02084 { 02085 // While the source is not zero, add them to target and bump 02086 while ( (aSrc[srcIndex] != T(0)/*'<control> NUL'*/) && 02087 (dstIndex < (aDstMax - 1)) && 02088 (srcIndex < aSrcMax) ) 02089 aDst[dstIndex++] = aSrc[srcIndex++]; 02090 02091 // Cap off the target where we ended 02092 aDst[dstIndex] = T(0)/*'<control> NUL'*/; 02093 } 02094 } 02095 02096 template <typename T> 02097 inline void 02098 vtkStringOps::Concatenate (T* const& aDst, 02099 T const& aChar) THROW_SPEC() 02100 { 02101 if (vtkStringOps::IsNull(aDst) || aChar == T(0)/*'<control> NUL'*/) 02102 return; 02103 02104 // Get the starting point for the cat on the target XMLString 02105 vtkSizeType dstIndex = vtkStringOps::Length(aDst); 02106 02107 aDst[dstIndex] = aChar; 02108 aDst[dstIndex+1] = T(0)/*'<control> NUL'*/; 02109 } 02110 02111 template <typename T> 02112 inline void 02113 vtkStringOps::Concatenate (T* const& aDst, 02114 T const& aChar, 02115 const vtkSizeType aDstMax) THROW_SPEC() 02116 { 02117 if (vtkStringOps::IsNull(aDst) || aChar == T(0)/*'<control> NUL'*/) 02118 return; 02119 02120 // Get the starting point for the cat on the target XMLString 02121 vtkSizeType dstIndex = vtkStringOps::Length(aDst); 02122 02123 if (dstIndex < (aDstMax - 1)) 02124 { 02125 aDst[dstIndex] = aChar; 02126 aDst[dstIndex+1] = T(0)/*'<control> NUL'*/; 02127 } 02128 } 02129 02130 // ---------------------------------------------------------------------------- 02131 template <typename T> 02132 inline void 02133 vtkStringOps::Copy (T* const& aDst, 02134 const T* const& aSrc) THROW_SPEC() 02135 { 02136 if (vtkStringOps::IsEmpty(aSrc)) 02137 { 02138 *aDst = T(0)/*'<control> NUL'*/; 02139 return; 02140 } 02141 02142 vtkSizeType dstIndex = 0; 02143 const T* srcPtr = aSrc; 02144 02145 // While the source is not zero, add them to target and bump 02146 while (*srcPtr != T(0)/*'<control> NUL'*/) 02147 aDst[dstIndex++] = *srcPtr++; 02148 02149 // Cap off the target where we ended 02150 aDst[dstIndex] = T(0)/*'<control> NUL'*/; 02151 } 02152 02153 // ---------------------------------------------------------------------------- 02154 template <typename T> 02155 inline void 02156 vtkStringOps::Copy (T* const& aDst, 02157 const T* const& aSrc, 02158 const vtkSizeType aDstMax) THROW_SPEC() 02159 { 02160 if (vtkStringOps::IsEmpty(aSrc) || aDstMax < 2) 02161 { 02162 if (aDstMax == 1) 02163 *aDst = T(0)/*'<control> NUL'*/; 02164 return; 02165 } 02166 02167 vtkSizeType dstIndex = 0; 02168 const T* srcPtr = aSrc; 02169 02170 // While the source is not zero, add them to target and bump 02171 while (*srcPtr != T(0)/*'<control> NUL'*/ && dstIndex < (aDstMax - 1)) 02172 aDst[dstIndex++] = *srcPtr++; 02173 02174 // Cap off the target where we ended 02175 aDst[dstIndex] = T(0)/*'<control> NUL'*/; 02176 } 02177 02178 // ---------------------------------------------------------------------------- 02179 template <typename T> 02180 inline void 02181 vtkStringOps::Trim (T* const& a) THROW_SPEC() 02182 { 02183 const vtkSizeType length = vtkStringOps::Length(a); 02184 vtkSizeType skip; 02185 02186 for (skip=0; skip<length; skip++) 02187 if (vtkStringOps::IsWhiteSpace(a[skip]) == VTK_FALSE) 02188 break; 02189 02190 vtkSizeType scrape; 02191 02192 for (scrape=length; scrape>skip; scrape--) 02193 if (vtkStringOps::IsWhiteSpace(a[scrape - 1]) == VTK_FALSE) 02194 break; 02195 02196 // Cap off at the scrap point 02197 if (scrape != length) 02198 a[scrape] = T(0)/*'<control> NUL'*/; 02199 02200 if (skip != 0) 02201 { // Copy the chars down 02202 vtkSizeType index = 0; 02203 02204 while (a[skip] != T(0)/*'<control> NUL'*/) 02205 a[index++] = a[skip++]; 02206 02207 a[index] = T(0)/*'<control> NUL'*/; 02208 } 02209 } 02210 02211 // ---------------------------------------------------------------------------- 02212 template <typename T> 02213 inline T* 02214 vtkStringOps::Duplicate (const T* const& a) 02215 { 02216 T* result = (T *) 0; // If a null string, return a null string! 02217 02218 if (vtkStringOps::IsNull(a) == VTK_FALSE) 02219 { 02220 const vtkSizeType length = vtkStringOps::Length(a); 02221 02222 // Will return an allocated empty string if the source string is empty. 02223 result = new T [length + 1]; // Could throw bad_alloc. 02224 02225 vtkStringOps::Memcpy(result, a, (length + 1) * sizeof(T)); 02226 } 02227 02228 return result; 02229 } 02230 02231 // ---------------------------------------------------------------------------- 02232 template <typename T> 02233 inline int 02234 vtkStringOps::IndexOf (const T* const& aToSearch, 02235 const T aChar) THROW_SPEC() 02236 { 02237 const vtkSizeType length = vtkStringOps::Length(aToSearch); 02238 02239 for (vtkSizeType j=0; j<length; j++) 02240 if (aToSearch[j] == aChar) 02241 return j; 02242 02243 return -1; 02244 } 02245 02246 template <typename T> 02247 inline int 02248 vtkStringOps::IndexOf (const T* const& aToSearch, 02249 const T aChar, 02250 const vtkSizeType aFromIndex) THROW_SPEC() 02251 { 02252 const vtkSizeType length = vtkStringOps::Length(aToSearch); 02253 02254 // Make sure the start index is within the vtkStringOps bounds 02255 if (int(aFromIndex) > (length - 1)) 02256 return -1; 02257 02258 for (vtkSizeType j=aFromIndex; j<length; j++) 02259 if (aToSearch[j] == aChar) 02260 return j; 02261 02262 return -1; 02263 } 02264 02265 // ---------------------------------------------------------------------------- 02266 template <typename T> 02267 inline int 02268 vtkStringOps::LastIndexOf (const T* const& aToSearch, 02269 const T aChar) THROW_SPEC() 02270 { 02271 const vtkSSizeType length = vtkStringOps::Length(aToSearch); 02272 02273 for (vtkSSizeType j=length-1; j>=0; j--) 02274 if (aToSearch[j] == aChar) 02275 return j; 02276 02277 return -1; 02278 } 02279 02280 template <typename T> 02281 inline int 02282 vtkStringOps::LastIndexOf (const T* const& aToSearch, 02283 const T aChar, 02284 const vtkSizeType aFromIndex) THROW_SPEC() 02285 { 02286 const vtkSSizeType length = vtkStringOps::Length(aToSearch); 02287 02288 // Make sure the start index is within the vtkStringOps bounds 02289 if (vtkSSizeType(aFromIndex) > (length - 1)) 02290 return -1; 02291 02292 for (vtkSSizeType j=vtkSSizeType(aFromIndex); j>=0; j--) 02293 if (aToSearch[j] == aChar) 02294 return j; 02295 02296 return -1; 02297 } 02298 02299 // ---------------------------------------------------------------------------- 02300 template <typename T> 02301 inline int 02302 vtkStringOps::IndexNotOf (const T* const& aToSearch, 02303 const T aChar) THROW_SPEC() 02304 { 02305 const vtkSizeType length = vtkStringOps::Length(aToSearch); 02306 02307 for (vtkSizeType j=0; j<length; j++) 02308 if (aToSearch[j] != aChar) 02309 return j; 02310 02311 return -1; 02312 } 02313 02314 template <typename T> 02315 inline int 02316 vtkStringOps::IndexNotOf (const T* const& aToSearch, 02317 const T aChar, 02318 const vtkSizeType aFromIndex) THROW_SPEC() 02319 { 02320 const vtkSizeType length = vtkStringOps::Length(aToSearch); 02321 02322 // Make sure the start index is within the vtkStringOps bounds 02323 if (int(aFromIndex) > (length - 1)) 02324 return -1; 02325 02326 for (vtkSizeType j=aFromIndex; j<length; j++) 02327 if (aToSearch[j] != aChar) 02328 return j; 02329 02330 return -1; 02331 } 02332 02333 // ---------------------------------------------------------------------------- 02334 template <typename T> 02335 inline int 02336 vtkStringOps::LastIndexNotOf (const T* const& aToSearch, 02337 const T aChar) THROW_SPEC() 02338 { 02339 const vtkSSizeType length = vtkStringOps::Length(aToSearch); 02340 02341 for (vtkSSizeType j=length-1; j>=0; j--) 02342 if (aToSearch[j] != aChar) 02343 return j; 02344 02345 return -1; 02346 } 02347 02348 template <typename T> 02349 inline int 02350 vtkStringOps::LastIndexNotOf (const T* const& aToSearch, 02351 const T aChar, 02352 const vtkSizeType aFromIndex) THROW_SPEC() 02353 { 02354 const vtkSSizeType length = vtkStringOps::Length(aToSearch); 02355 02356 // Make sure the start index is within the vtkStringOps bounds 02357 if (vtkSSizeType(aFromIndex) > (length - 1)) 02358 return -1; 02359 02360 for (vtkSSizeType j=vtkSSizeType(aFromIndex); j>=0; j--) 02361 if (aToSearch[j] != aChar) 02362 return j; 02363 02364 return -1; 02365 } 02366 02367 // ---------------------------------------------------------------------------- 02368 template <typename T> 02369 inline void 02370 vtkStringOps::Move (T* const& aDst, 02371 const T* const& aSrc, 02372 const vtkSizeType aLength) 02373 { 02374 vtkStringOps::Memmove(aDst, aSrc, aLength * sizeof(T)); 02375 } 02376 02377 // ---------------------------------------------------------------------------- 02378 template <typename T> 02379 inline T* 02380 vtkStringOps::SubString (const T* const& aSrc, 02381 const int aStartIndex) 02382 { 02383 const int srcLength = vtkStringOps::Length(aSrc); 02384 const int copySize = srcLength - aStartIndex; 02385 02386 // Make sure the start index is within the XMLString bounds 02387 if (aStartIndex < 0 || aStartIndex > srcLength) 02388 return vtkStringOps::CreateEmptyString<T>(); // Start index past end. 02389 02390 T* dst = new T [copySize + 1]; 02391 02392 for (int j=aStartIndex; j<srcLength; j++) 02393 dst[j - aStartIndex] = aSrc[j]; 02394 02395 dst[copySize] = T(0)/*'<control> NUL'*/; 02396 02397 return dst; 02398 } 02399 02400 template <typename T> 02401 inline T* 02402 vtkStringOps::SubString (const T* const& aSrc, 02403 const int aStartIndex, 02404 const int aEndIndex) 02405 { 02406 const int srcLength = vtkStringOps::Length(aSrc); 02407 const int copySize = aEndIndex - aStartIndex; 02408 02409 // Make sure the start index is within the XMLString bounds 02410 if (aStartIndex < 0 || aStartIndex > aEndIndex || aEndIndex > srcLength) 02411 return vtkStringOps::CreateEmptyString<T>(); // Start index past end. 02412 02413 T* dst = new T [copySize + 1]; 02414 02415 for (int j=aStartIndex; j<aEndIndex; j++) 02416 dst[j - aStartIndex] = aSrc[j]; 02417 02418 dst[copySize] = T(0)/*'<control> NUL'*/; 02419 02420 return dst; 02421 } 02422 02423 // ---------------------------------------------------------------------------- 02424 template <typename T> 02425 inline void 02426 vtkStringOps::SubString (T* const& aDst, 02427 const T* const& aSrc, 02428 const int aStartIndex) THROW_SPEC() 02429 { 02430 if (vtkStringOps::IsNull(aDst)) 02431 return; // Zero sized target buffer. 02432 02433 const int srcLength = vtkStringOps::Length(aSrc); 02434 const int copySize = srcLength - aStartIndex; 02435 02436 // Make sure the start index is within the XMLString bounds 02437 if (aStartIndex < 0 || aStartIndex > srcLength) 02438 return; // Start index past end. 02439 02440 for (int j=aStartIndex; j<srcLength; j++) 02441 aDst[j - aStartIndex] = aSrc[j]; 02442 02443 aDst[copySize] = T(0)/*'<control> NUL'*/; 02444 } 02445 02446 template <typename T> 02447 inline void 02448 vtkStringOps::SubString (T* const& aDst, 02449 const T* const& aSrc, 02450 const int aStartIndex, 02451 const int aEndIndex) THROW_SPEC() 02452 { 02453 if (vtkStringOps::IsNull(aDst)) 02454 return; // Zero sized target buffer. 02455 02456 const int srcLength = vtkStringOps::Length(aSrc); 02457 const int copySize = aEndIndex - aStartIndex; 02458 02459 // Make sure the start index is within the XMLString bounds 02460 if (aStartIndex < 0 || aStartIndex > aEndIndex || aEndIndex > srcLength) 02461 return; // Start index past end. 02462 02463 for (int j=aStartIndex; j<aEndIndex; j++) 02464 aDst[j - aStartIndex] = aSrc[j]; 02465 02466 aDst[copySize] = T(0)/*'<control> NUL'*/; 02467 } 02468 02469 // ---------------------------------------------------------------------------- 02470 template <typename T> 02471 inline vtkBoolType 02472 vtkStringOps::ValidateRegion (const T* const& aStr1, 02473 const vtkSSizeType aOffset1, 02474 const T* const& aStr2, 02475 const vtkSSizeType aOffset2, 02476 const vtkSizeType aLength) THROW_SPEC() 02477 { 02478 if ( (aOffset1 < 0) || (aOffset2 < 0) || 02479 ((aOffset1 + aLength) > vtkStringOps::Length(aStr1)) || 02480 ((aOffset2 + aLength) > vtkStringOps::Length(aStr2)) ) 02481 return VTK_FALSE; 02482 02483 return VTK_TRUE; 02484 } 02485 02486 // ---------------------------------------------------------------------------- 02487 template <typename T> 02488 inline vtkBoolType 02489 vtkStringOps::Equals (const T* const& aStr1, 02490 const T* const& aStr2) THROW_SPEC() 02491 { 02492 const T* ptr1 = aStr1; 02493 const T* ptr2 = aStr2; 02494 02495 if (vtkStringOps::IsNull(ptr1) || vtkStringOps::IsNull(ptr2)) 02496 { 02497 if ( vtkStringOps::IsEmpty(ptr1) == VTK_FALSE || 02498 vtkStringOps::IsEmpty(ptr2) == VTK_FALSE ) 02499 return VTK_FALSE; 02500 else 02501 return VTK_TRUE; 02502 } 02503 02504 while (*ptr1 == *ptr2) 02505 { 02506 // If either has ended, then they both ended, so equal 02507 if (*ptr1 == T(0)/*'<control> NUL'*/) 02508 return VTK_TRUE; 02509 02510 // Move upwards for the next round 02511 ptr1++; 02512 ptr2++; 02513 } 02514 02515 return VTK_FALSE; 02516 } 02517 02518 template <typename T> 02519 inline vtkBoolType 02520 vtkStringOps::Equals (const T* const& aStr1, 02521 const T* const& aStr2, 02522 const vtkSizeType aLength) THROW_SPEC() 02523 { 02524 if (vtkStringOps::IsNull(aStr1) || vtkStringOps::IsNull(aStr2)) 02525 { 02526 if ( vtkStringOps::IsEmpty(aStr1) == VTK_FALSE || 02527 vtkStringOps::IsEmpty(aStr2) == VTK_FALSE ) 02528 return VTK_FALSE; 02529 else 02530 return VTK_TRUE; 02531 } 02532 02533 for (vtkSizeType j=0; j<aLength; j++) 02534 { 02535 if (aStr1[j] != aStr2[j]) 02536 return VTK_FALSE; 02537 else if (aStr1[j] == T(0)/*'<control> NUL'*/) 02538 return VTK_TRUE; // If either has ended, then they both ended, so equal 02539 } 02540 02541 return VTK_TRUE; 02542 } 02543 02544 template <typename T> 02545 inline vtkBoolType 02546 vtkStringOps::Equals (const T* const& aStr1, 02547 const vtkSSizeType aOffset1, 02548 const T* const& aStr2, 02549 const vtkSSizeType aOffset2, 02550 const vtkSizeType aLength) THROW_SPEC() 02551 { 02552 if ( vtkStringOps::ValidateRegion( aStr1, aOffset1, 02553 aStr2, aOffset2, 02554 aLength ) == VTK_FALSE ) 02555 return VTK_FALSE; 02556 02557 return vtkStringOps::Equals(aStr1+aOffset1, aStr2+aOffset2, aLength); 02558 } 02559 02560 template <typename T> 02561 inline vtkBoolType 02562 vtkStringOps::Equals (const T* const& aStr1, 02563 T const& aChar) THROW_SPEC() 02564 { 02565 if (vtkStringOps::IsEmpty(aStr1)) 02566 { 02567 if (aChar == T(0)) 02568 return VTK_TRUE; 02569 else 02570 return VTK_FALSE; 02571 } 02572 02573 if (aStr1[0] == aChar && aStr1[1] == T(0)) 02574 return VTK_TRUE; 02575 02576 return VTK_FALSE; 02577 } 02578 02579 // ---------------------------------------------------------------------------- 02580 template <typename T> 02581 inline vtkBoolType 02582 vtkStringOps::EqualsI (const T* const& aStr1, 02583 const T* const& aStr2) THROW_SPEC() 02584 { 02585 if (vtkStringOps::IsNull(aStr1) || vtkStringOps::IsNull(aStr2)) 02586 { 02587 if (vtkStringOps::IsNull(aStr1)) 02588 return 0 - vtkStringOps::Length(aStr2); 02589 else if (vtkStringOps::IsNull(aStr2)) 02590 return 0 + vtkStringOps::Length(aStr1); 02591 } 02592 02593 const T* ptr1 = aStr1; 02594 const T* ptr2 = aStr2; 02595 02596 if (vtkStringOps::IsNull(ptr1) || vtkStringOps::IsNull(ptr2)) 02597 { 02598 if ( vtkStringOps::IsEmpty(ptr1) == VTK_FALSE || 02599 vtkStringOps::IsEmpty(ptr2) == VTK_FALSE ) 02600 return VTK_FALSE; 02601 else 02602 return VTK_TRUE; 02603 } 02604 02605 while (tolower(*ptr1) == tolower(*ptr2)) 02606 { 02607 // If either has ended, then they both ended, so equal 02608 if (*ptr1 == T(0)/*'<control> NUL'*/) 02609 return VTK_TRUE; 02610 02611 // Move upwards for the next round 02612 ptr1++; 02613 ptr2++; 02614 } 02615 02616 return VTK_FALSE; 02617 } 02618 02619 template <typename T> 02620 inline vtkBoolType 02621 vtkStringOps::EqualsI (const T* const& aStr1, 02622 const T* const& aStr2, 02623 const vtkSizeType aLength) THROW_SPEC() 02624 { 02625 if (vtkStringOps::IsNull(aStr1) || vtkStringOps::IsNull(aStr2)) 02626 { 02627 if ( vtkStringOps::IsEmpty(aStr1) == VTK_FALSE || 02628 vtkStringOps::IsEmpty(aStr2) == VTK_FALSE ) 02629 return VTK_FALSE; 02630 else 02631 return VTK_TRUE; 02632 } 02633 02634 for (vtkSizeType j=0; j<aLength; j++) 02635 { 02636 if (tolower(aStr1[j]) != tolower(aStr2[j])) 02637 return VTK_FALSE; 02638 else if (aStr1[j] == T(0)/*'<control> NUL'*/) 02639 return VTK_TRUE; // If either has ended, then they both ended, so equal 02640 } 02641 02642 return VTK_TRUE; 02643 } 02644 02645 template <typename T> 02646 inline vtkBoolType 02647 vtkStringOps::EqualsI (const T* const& aStr1, 02648 const vtkSSizeType aOffset1, 02649 const T* const& aStr2, 02650 const vtkSSizeType aOffset2, 02651 const vtkSizeType aLength) THROW_SPEC() 02652 { 02653 if ( vtkStringOps::ValidateRegion( aStr1, aOffset1, 02654 aStr2, aOffset2, 02655 aLength ) == VTK_FALSE ) 02656 return VTK_FALSE; 02657 02658 return vtkStringOps::EqualsI(aStr1+aOffset1, aStr2+aOffset2, aLength); 02659 } 02660 02661 template <typename T> 02662 inline vtkBoolType 02663 vtkStringOps::EqualsI (const T* const& aStr1, 02664 T const& aChar) THROW_SPEC() 02665 { 02666 if (vtkStringOps::IsEmpty(aStr1)) 02667 { 02668 if (aChar == T(0)) 02669 return VTK_TRUE; 02670 else 02671 return VTK_FALSE; 02672 } 02673 02674 if (tolower(aStr1[0]) == tolower(aChar) && aStr1[1] == T(0)) 02675 return VTK_TRUE; 02676 02677 return VTK_FALSE; 02678 } 02679 02680 // ---------------------------------------------------------------------------- 02681 template <typename T> 02682 inline int 02683 vtkStringOps::Compare (const T* const& aStr1, 02684 const T* const& aStr2) THROW_SPEC() 02685 { 02686 if (vtkStringOps::IsNull(aStr1) || vtkStringOps::IsNull(aStr2)) 02687 { 02688 if (vtkStringOps::IsNull(aStr1)) 02689 return 0 - vtkStringOps::Length(aStr2); 02690 else if (vtkStringOps::IsNull(aStr2)) 02691 return 0 + vtkStringOps::Length(aStr1); 02692 } 02693 02694 const T* ptr1 = aStr1; 02695 const T* ptr2 = aStr2; 02696 02697 while (1) 02698 { 02699 if (*ptr1 != *ptr2) 02700 { 02701 // If an inequality, then return the difference 02702 return int(*ptr1) - int(*ptr2); 02703 } 02704 else if (*ptr1 == T(0)/*'<control> NUL'*/) 02705 { 02706 // If either has ended, then they both ended, so equal 02707 break; 02708 } 02709 02710 // Move upwards for the next round 02711 ++ptr1; 02712 ++ptr2; 02713 } 02714 02715 return 0; 02716 } 02717 02718 template <typename T> 02719 inline int 02720 vtkStringOps::Compare (const T* const& aStr1, 02721 const T* const& aStr2, 02722 const vtkSizeType aLength) 02723 { 02724 return vtkStringOps::Memcmp( static_cast<const void *>(aStr1), 02725 static_cast<const void *>(aStr2), 02726 aLength * sizeof(T) ); 02727 } 02728 02729 // ---------------------------------------------------------------------------- 02730 template <typename T> 02731 inline vtkBoolType 02732 vtkStringOps::IsPrefix (const T* const& aTest, 02733 const T* const& aPrefix) 02734 { 02735 return 02736 (vtkStringOps::Compare(aTest, aPrefix, vtkStringOps::Length(aPrefix)) == 0); 02737 } 02738 02739 template <typename T> 02740 inline vtkBoolType 02741 vtkStringOps::IsSuffix (const T* const& aTest, 02742 const T* const& aSuffix) 02743 { 02744 vtkSizeType suffixLen = vtkStringOps::Length(aSuffix); 02745 02746 return vtkStringOps::Equals( aTest, vtkStringOps::Length(aTest) - suffixLen, 02747 aSuffix, 0, 02748 suffixLen ); 02749 } 02750 02751 // ---------------------------------------------------------------------------- 02752 template <typename T> 02753 inline const T* 02754 vtkStringOps::FindAny (const T* const& aTest, 02755 const T* const& aSearchList) 02756 { 02757 const T* ptr = aTest; 02758 02759 while (*ptr != T(0)) 02760 { 02761 const T* searchPtr = aSearchList; 02762 const T curCh = *ptr; 02763 02764 while (*searchPtr != T(0)) 02765 { 02766 if (curCh == *searchPtr++) 02767 return ptr; 02768 } 02769 ptr++; 02770 } 02771 02772 return (const T *) 0; 02773 } 02774 02775 template <typename T> 02776 inline int 02777 vtkStringOps::FindSubString (const T* const& aTest, 02778 const T* const& aSubStr) 02779 { 02780 if (vtkStringOps::IsEmpty(aTest)) 02781 return -1; 02782 02783 vtkSizeType subStrLen; 02784 02785 if ((subStrLen = vtkStringOps::Length(aSubStr)) == 0) 02786 return -1; 02787 02788 const T* srcPtr = aTest; 02789 const T* startPtr = aTest; 02790 vtkSizeType subStrIndex = 0; 02791 02792 while (*srcPtr != T(0)) 02793 { 02794 if ( !(*srcPtr++ == aSubStr[subStrIndex++])) 02795 { 02796 subStrIndex = 0; 02797 srcPtr = ++startPtr; 02798 } 02799 else 02800 { 02801 if (subStrIndex == subStrLen) 02802 return (srcPtr - subStrLen - aTest); // full pattern match found 02803 } 02804 } 02805 02806 return -1; 02807 } 02808 02809 // ---------------------------------------------------------------------------- 02810 template <typename T> 02811 inline vtkBoolType 02812 vtkStringOps::TextToBin (const T* const& aToConvert, 02813 unsigned int& aToFill) 02814 { 02815 aToFill = 0; 02816 02817 // If no string, then its a failure 02818 if (vtkStringOps::IsEmpty(aToConvert)) 02819 return VTK_FALSE; 02820 02821 // WARNING: Could throw bad_alloc. 02822 T* trimmedStr = vtkStringOps::Duplicate(aToConvert); 02823 02824 // Ensure deletion of temporary storage. 02825 vtkStringOps::Janitor<T> jan1(trimmedStr); 02826 02827 // Lop any whitespace off the ends. 02828 vtkStringOps::Trim(trimmedStr); 02829 02830 // Remeasure. 02831 unsigned int trimmedStrLen = vtkStringOps::Length(trimmedStr); 02832 02833 if (trimmedStrLen == 0) 02834 return VTK_FALSE; 02835 02836 // We don't allow '-' sign. 02837 if (vtkStringOps::IndexOf(trimmedStr, 0x002D/* HYPHEN-MINUS */) != -1) 02838 return VTK_FALSE; 02839 02840 // The errno set by previous run is NOT automatically cleared. 02841 errno = 0; 02842 02843 ToLatin1 lat1(trimmedStr); // Doesn't need janitor. 02844 02845 const char* nPtr = lat1.data(); 02846 char* endPtr; 02847 02848 // 02849 // REVISIT: conversion of (unsigned long) to (unsigned int) 02850 // may truncate value on 64 bit architectures. 02851 // 02852 aToFill = (unsigned int) (vtkStringOps::Strtoul(nPtr, &endPtr)); 02853 02854 // check if all chars are valid char 02855 // check if overflow/underflow occurs 02856 if (((endPtr - nPtr) != int(trimmedStrLen)) || (errno == ERANGE)) 02857 return VTK_FALSE; 02858 02859 return VTK_TRUE; 02860 } 02861 02862 // ---------------------------------------------------------------------------- 02863 template <typename T> 02864 inline int 02865 vtkStringOps::ParseIntVec (const T* const& aStr, 02866 unsigned int aLen, 02867 int* aData) 02868 { 02869 // If no string, or empty string, then it is a failure 02870 if (vtkStringOps::IsEmpty(aStr) || aLen == 0 || aData == (int *) 0) 02871 { 02872 errno = EINVAL; 02873 return 0; 02874 } 02875 02876 // WARNING: Could throw bad_alloc. 02877 T* trimmedStr = vtkStringOps::Duplicate(aStr); 02878 02879 // Ensure deletion of temporary storage. 02880 vtkStringOps::Janitor<T> jan1(trimmedStr); 02881 02882 // Lop any whitespace off the ends. 02883 vtkStringOps::Trim(trimmedStr); 02884 02885 // Remeasure. 02886 vtkSizeType trimmedLength = vtkStringOps::Length(trimmedStr); 02887 02888 if (trimmedLength == 0) 02889 { 02890 errno = EINVAL; 02891 return 0; 02892 } 02893 02894 // Any error set by a previous run is NOT automatically cleared. 02895 errno = 0; 02896 02897 ToLatin1 lat1(trimmedStr); // Doesn't need janitor. 02898 02899 const char* ptr = lat1.data(); 02900 char* endPtr; 02901 unsigned int n; 02902 02903 for (n=0; n<aLen; n++) 02904 { 02905 if ((aData[n] = int(vtkStringOps::Strtol(ptr,&endPtr)))==0 && endPtr==ptr) 02906 { 02907 if (errno != ERANGE) 02908 errno = EINVAL; 02909 break; 02910 } 02911 while (vtkStringOps::IsWhiteSpace(*endPtr)) 02912 ++endPtr; // chomp whitespace 02913 02914 ptr = endPtr; // point to char after last conversion 02915 endPtr = (char *) 0; // rezero to allow check for conversion failure 02916 } 02917 02918 return n; 02919 } 02920 02921 template <typename T> 02922 inline int 02923 vtkStringOps::ParseInt (const T* const& aStr) 02924 { 02925 int value; 02926 02927 return (vtkStringOps::ParseIntVec(aStr,1,&value)!=1||errno!=0 ? 0 : value); 02928 } 02929 02930 // ---------------------------------------------------------------------------- 02931 template <typename T> 02932 inline int 02933 vtkStringOps::ParseFloatVec (const T* const& aStr, 02934 unsigned int aLen, 02935 float* aData) 02936 { 02937 // If no string, or empty string, then it is a failure 02938 if (vtkStringOps::IsEmpty(aStr) || aLen == 0 || aData == (float *) 0) 02939 { 02940 errno = EINVAL; 02941 return 0; 02942 } 02943 02944 // WARNING: Could throw bad_alloc. 02945 T* trimmedStr = vtkStringOps::Duplicate(aStr); 02946 02947 // Ensure deletion of temporary storage. 02948 vtkStringOps::Janitor<T> jan1(trimmedStr); 02949 02950 // Lop any whitespace off the ends. 02951 vtkStringOps::Trim(trimmedStr); 02952 02953 // Remeasure. 02954 vtkSizeType trimmedLength = vtkStringOps::Length(trimmedStr); 02955 02956 if (trimmedLength == 0) 02957 { 02958 errno = EINVAL; 02959 return 0; 02960 } 02961 02962 // Any error set by a previous run is NOT automatically cleared. 02963 errno = 0; 02964 02965 ToLatin1 lat1(trimmedStr); // Doesn't need janitor. 02966 02967 const char* ptr = lat1.data(); 02968 char* endPtr; 02969 unsigned int n; 02970 02971 for (n=0; n<aLen; n++) 02972 { 02973 if ((aData[n] = float(vtkStringOps::Strtod(ptr,&endPtr)))==0 && endPtr==ptr) 02974 { 02975 if (errno != ERANGE) 02976 errno = EINVAL; 02977 break; 02978 } 02979 while (vtkStringOps::IsWhiteSpace(*endPtr)) 02980 ++endPtr; // chomp whitespace 02981 02982 ptr = endPtr; // point to char after last conversion 02983 endPtr = (char *) 0; // rezero to allow check for conversion failure 02984 } 02985 02986 return n; 02987 } 02988 02989 template <typename T> 02990 inline float 02991 vtkStringOps::ParseFloat (const T* const& aStr) 02992 { 02993 float value; 02994 02995 return (vtkStringOps::ParseFloatVec(aStr,1,&value)!=1||errno!=0 ? 0 : value); 02996 } 02997 02998 // ---------------------------------------------------------------------------- 02999 template <typename T> 03000 inline int 03001 vtkStringOps::ParseDoubleVec (const T* const& aStr, 03002 unsigned int aLen, 03003 double* aData) 03004 { 03005 // If no string, or empty string, then it is a failure 03006 if (vtkStringOps::IsEmpty(aStr) || aLen == 0 || aData == (double *) 0) 03007 { 03008 errno = EINVAL; 03009 return 0; 03010 } 03011 03012 // WARNING: Could throw bad_alloc. 03013 T* trimmedStr = vtkStringOps::Duplicate(aStr); 03014 03015 // Ensure deletion of temporary storage. 03016 vtkStringOps::Janitor<T> jan1(trimmedStr); 03017 03018 // Lop any whitespace off the ends. 03019 vtkStringOps::Trim(trimmedStr); 03020 03021 // Remeasure. 03022 vtkSizeType trimmedLength = vtkStringOps::Length(trimmedStr); 03023 03024 if (trimmedLength == 0) 03025 { 03026 errno = EINVAL; 03027 return 0; 03028 } 03029 03030 // Any error set by a previous run is NOT automatically cleared. 03031 errno = 0; 03032 03033 ToLatin1 lat1(trimmedStr); // Doesn't need janitor. 03034 03035 const char* ptr = lat1.data(); 03036 char* endPtr; 03037 unsigned int n; 03038 03039 for (n=0; n<aLen; n++) 03040 { 03041 if ((aData[n] = vtkStringOps::Strtod(ptr,&endPtr))==0 && endPtr==ptr) 03042 { 03043 if (errno != ERANGE) 03044 errno = EINVAL; 03045 break; 03046 } 03047 while (vtkStringOps::IsWhiteSpace(*endPtr)) 03048 ++endPtr; // chomp whitespace 03049 03050 ptr = endPtr; // point to char after last conversion 03051 endPtr = (char *) 0; // rezero to allow check for conversion failure 03052 } 03053 03054 return n; 03055 } 03056 03057 template <typename T> 03058 inline double 03059 vtkStringOps::ParseDouble (const T* const& aStr) 03060 { 03061 double value; 03062 03063 return (vtkStringOps::ParseDoubleVec(aStr,1,&value)!=1||errno!=0 ? 0 : value); 03064 } 03065 03066 // ---------------------------------------------------------------------------- 03067 template <typename T> 03068 inline int 03069 vtkStringOps::ParseUintVec (const T* const& aStr, 03070 unsigned int aLen, 03071 unsigned int* aData) 03072 { 03073 // If no string, or empty string, then it is a failure 03074 if (vtkStringOps::IsEmpty(aStr) || aLen == 0 || aData == (unsigned int *) 0) 03075 { 03076 errno = EINVAL; 03077 return 0; 03078 } 03079 03080 // WARNING: Could throw bad_alloc. 03081 T* trimmedStr = vtkStringOps::Duplicate(aStr); 03082 03083 // Ensure deletion of temporary storage. 03084 vtkStringOps::Janitor<T> jan1(trimmedStr); 03085 03086 // Lop any whitespace off the ends. 03087 vtkStringOps::Trim(trimmedStr); 03088 03089 // Remeasure. 03090 vtkSizeType trimmedLength = vtkStringOps::Length(trimmedStr); 03091 03092 if (trimmedLength == 0) 03093 { 03094 errno = EINVAL; 03095 return 0; 03096 } 03097 03098 // Any error set by a previous run is NOT automatically cleared. 03099 errno = 0; 03100 03101 ToLatin1 lat1(trimmedStr); // Doesn't need janitor. 03102 03103 const char* ptr = lat1.data(); 03104 char* endPtr; 03105 unsigned int n; 03106 03107 for (n=0; n<aLen; n++) 03108 { 03109 if ( (aData[n] = (unsigned int)(vtkStringOps::Strtoul(ptr,&endPtr)))==0 && 03110 endPtr==ptr ) 03111 { 03112 if (errno != ERANGE) 03113 errno = EINVAL; 03114 break; 03115 } 03116 while (vtkStringOps::IsWhiteSpace(*endPtr)) 03117 ++endPtr; // chomp whitespace 03118 03119 ptr = endPtr; // point to char after last conversion 03120 endPtr = (char *) 0; // rezero to allow check for conversion failure 03121 } 03122 03123 return n; 03124 } 03125 03126 template <typename T> 03127 inline unsigned int 03128 vtkStringOps::ParseUint (const T* const& aStr) 03129 { 03130 unsigned int value; 03131 03132 return (vtkStringOps::ParseUintVec(aStr,1,&value)!=1||errno!=0 ? 0 : value); 03133 } 03134 03135 // ---------------------------------------------------------------------------- 03136 template <typename T> 03137 inline vtkBoolType 03138 vtkStringOps::ParseBoolean (const T* const& aStr) 03139 { 03140 // If no string, or empty string, then it is a failure 03141 if (vtkStringOps::IsEmpty(aStr)) 03142 { 03143 errno = EINVAL; 03144 return VTK_TRUE; 03145 } 03146 03147 // WARNING: Could throw bad_alloc. 03148 T* trimmedStr = vtkStringOps::Duplicate(aStr); 03149 03150 // Ensure deletion of temporary storage. 03151 vtkStringOps::Janitor<T> jan1(trimmedStr); 03152 03153 // Lop any whitespace off the ends. 03154 vtkStringOps::Trim(trimmedStr); 03155 03156 // Remeasure. 03157 vtkSizeType trimmedLength = vtkStringOps::Length(trimmedStr); 03158 03159 if (trimmedLength == 0) 03160 { 03161 errno = EINVAL; 03162 return VTK_TRUE; 03163 } 03164 03165 // Any error set by a previous run is NOT automatically cleared. 03166 errno = 0; 03167 03168 T* p = trimmedStr; 03169 03170 switch (*p++) 03171 { 03172 03173 case '0': 03174 if (*p == 'x') ++p; // This might be a hexidecimal value. 03175 while (*p && *p == '0') ++p; // Anything other than '0' means "true". 03176 if (*p == '\0') { return VTK_FALSE; } 03177 while (*p && vtkStringOps::IsHexDigit(*p)) ++p; // checking validity 03178 if (*p == '\0') { return VTK_TRUE; } 03179 break; // Encountered an non-hexidecimal value. 03180 03181 case '1': 03182 while (*p && vtkStringOps::IsHexDigit(*p)) ++p; // checking validity 03183 if (*p == '\0') { return VTK_TRUE; } 03184 break; // Encountered an non-hexidecimal value. 03185 03186 case 'F': case 'f': 03187 switch (*p++) 03188 { 03189 case 'A': case 'a': 03190 switch (*p++) 03191 { 03192 case 'L': case 'l': 03193 switch (*p++) 03194 { 03195 case 'S': case 's': 03196 switch (*p++) 03197 { 03198 case 'E': case 'e': 03199 switch (*p++) 03200 { 03201 case '\0': 03202 return VTK_FALSE; // Reached expected terminal nul. 03203 } // 'E' or 'e' 03204 } // 'S' or 's' 03205 } // 'L' or 'l' 03206 } // 'A' or 'a' 03207 } // 'F' or 'f' 03208 break; // Getting here means an invalid string. 03209 03210 case 'T': case 't': 03211 switch (*p++) 03212 { 03213 case 'R': case 'r': 03214 switch (*p++) 03215 { 03216 case 'U': case 'u': 03217 switch (*p++) 03218 { 03219 case 'E': case 'e': 03220 switch (*p++) 03221 { 03222 case '\0': 03223 return VTK_TRUE; // Reached expected terminal nul. 03224 } // 'E' or 'e' 03225 } // 'U' or 'u' 03226 } // 'R' or 'r' 03227 } // 'T' or 't' 03228 break; 03229 03230 case 'N': case 'n': 03231 switch (*p++) 03232 { 03233 case 'O': case 'o': 03234 switch (*p++) 03235 { 03236 case '\0': 03237 return VTK_FALSE; // Reached expected terminal nul. 03238 } // 'O' or 'o' 03239 } // 'N' or 'n' 03240 break; // Getting here means an invalid string. 03241 03242 case 'Y': case 'y': 03243 switch (*p++) 03244 { 03245 case 'E': case 'e': 03246 switch (*p++) 03247 { 03248 case 'S': case 's': 03249 switch (*p++) 03250 { 03251 case '\0': 03252 return VTK_TRUE; // Reached expected terminal nul. 03253 } // 'S' or 's' 03254 } // 'E' or 'e' 03255 } // 'Y' or 'y' 03256 break; // Getting here means an invalid string. 03257 03258 case 'O': case 'o': 03259 switch (*p++) 03260 { 03261 case 'F': case 'f': 03262 switch (*p++) 03263 { 03264 case 'F': case 'f': 03265 switch (*p++) 03266 { 03267 case '\0': 03268 return VTK_FALSE; // Reached expected terminal nul. 03269 } // 'F' or 'f' 03270 } // 'F' or 'f' 03271 break; 03272 case 'N': case 'n': 03273 switch (*p++) 03274 { 03275 case '\0': 03276 return VTK_TRUE; // Reached expected terminal nul. 03277 } // 'N' or 'n' 03278 break; 03279 } // 'O' or 'o' 03280 break; // Getting here means an invalid string. 03281 03282 } // switch (*p++) 03283 03284 errno = EINVAL; 03285 03286 return VTK_TRUE; 03287 } 03288 03289 // ---------------------------------------------------------------------------- 03290 template <typename T> 03291 inline T** 03292 vtkStringOps::Tokenize (const T* const& aSrc, unsigned int aMaxTokens) 03293 { 03294 // WARNING: Could throw bad_alloc. 03295 T* original = vtkStringOps::Duplicate(aSrc); 03296 03297 // Ensure deletion of temporary storage. 03298 vtkStringOps::Janitor<T> janitor(original); 03299 03300 T* tokenizeStr = original; 03301 T** tokens = new T* [aMaxTokens + 1]; 03302 03303 unsigned int length = vtkStringOps::Length(tokenizeStr); 03304 unsigned int index = 0; 03305 unsigned int count = 0; 03306 unsigned int skip; 03307 03308 while ((index != length) && (count < aMaxTokens)) 03309 { 03310 // find the first non-whitespace character 03311 for (skip=index; skip<length; skip++) 03312 if (vtkStringOps::IsWhiteSpace(tokenizeStr[skip]) == VTK_FALSE) 03313 break; 03314 03315 // record the beginning index 03316 index = skip; 03317 03318 // find the delimiter (whitespace character) 03319 for (; skip<length; skip++) 03320 if (vtkStringOps::IsWhiteSpace(tokenizeStr[skip])) 03321 break; 03322 03323 // we reached the end of the string 03324 if (skip == index) 03325 break; 03326 03327 // These tokens are adopted in the RefVector and will be deleted 03328 // when the vector is deleted by the caller. 03329 tokens[count] = new T [skip + 1 - index]; 03330 // Copy the substring. 03331 vtkStringOps::SubString(tokens[count], tokenizeStr, index, skip); 03332 // increment for the next token 03333 index = skip; 03334 ++count; 03335 } 03336 03337 tokens[count] = (T *) 0/* NULL */; 03338 03339 return tokens; 03340 } 03341 03342 template <typename T> 03343 inline T** 03344 vtkStringOps::Tokenize (const T* const& aSrc, 03345 const T* const& aDelimiters, 03346 unsigned int aMaxTokens) 03347 { 03348 // WARNING: Could throw bad_alloc. 03349 T* original = vtkStringOps::Duplicate(aSrc); 03350 03351 // Ensure deletion of temporary storage. 03352 vtkStringOps::Janitor<T> janitor(original); 03353 03354 T* tokenizeStr = original; 03355 T** tokens = new T* [aMaxTokens + 1]; 03356 03357 unsigned int length = vtkStringOps::Length(tokenizeStr); 03358 unsigned int index = 0; 03359 unsigned int count = 0; 03360 unsigned int skip; 03361 03362 while ((index != length) && (count < aMaxTokens)) 03363 { 03364 // find the first non-delimiter character 03365 for (skip=index; skip<length; skip++) 03366 if (vtkStringOps::IsMemberOf(tokenizeStr[skip], aDelimiters) == VTK_FALSE) 03367 break; 03368 03369 // record the beginning index 03370 index = skip; 03371 03372 // find the delimiter. 03373 for (; skip<length; skip++) 03374 if (vtkStringOps::IsMemberOf(tokenizeStr[skip], aDelimiters)) 03375 break; 03376 03377 // we reached the end of the string 03378 if (skip == index) 03379 break; 03380 03381 // These tokens are adopted in the RefVector and will be deleted 03382 // when the vector is deleted by the caller. 03383 tokens[count] = new T [skip + 1 - index]; 03384 // Copy the substring. 03385 vtkStringOps::SubString(tokens[count], tokenizeStr, index, skip); 03386 // increment for the next token 03387 index = skip; 03388 ++count; 03389 } 03390 03391 tokens[count] = (T *) 0/* NULL */; 03392 03393 return tokens; 03394 } 03395 03396 // ---------------------------------------------------------------------------- 03397 template <typename T> 03398 inline vtkBoolType 03399 vtkStringOps::IsAbsoluteURI (const T* aURI) THROW_SPEC() 03400 { 03401 vtkBoolType result = VTK_FALSE; 03402 03403 /* 03404 * RFC 2396 3.1 Scheme Component 03405 * scheme = alpha *( alpha | digit | "+" | "-" | "." ) 03406 */ 03407 if ((*aURI != T(0)/*'<control> NUL'*/) && vtkStringOps::IsAlpha(*aURI)) 03408 { 03409 ++aURI; 03410 03411 while( (*aURI != T(0)/*'<control> NUL'*/) && 03412 ( vtkStringOps::IsAlnum(*aURI) || 03413 (*aURI == T(0x002B)/*ASCII_plus*/) || 03414 (*aURI == T(0x002D)/*ASCII_minus*/) || 03415 (*aURI == T(0x002E)/*ASCII_period*/) ) ) 03416 ++aURI; 03417 03418 result = vtkBoolType(*aURI == T(0x003A)/*ASCII_colon*/); 03419 } 03420 03421 return result; 03422 } 03423 03424 // ---------------------------------------------------------------------------- 03425 template <typename T> 03426 inline void 03427 vtkStringOps::ParseURI (const T* aURI, 03428 T* aBuffer, 03429 const vtkSizeType aBufferLength, 03430 T** aScheme, 03431 T** aAuthority, 03432 T** aPath, 03433 T** aQuery, 03434 T** aFragment) THROW_SPEC() 03435 { 03436 const T* s = aURI; 03437 T* d = aBuffer; 03438 03439 *aScheme = (T *) 0; 03440 *aAuthority = (T *) 0; 03441 *aPath = (T *) 0; 03442 *aQuery = (T *) 0; 03443 *aFragment = (T *) 0; 03444 03445 const T nulChar = T(0x0000)/*'<control> NUL'*/; // '\0' 03446 const T hashChar = T(0x0023)/*ASCII_octothorpe*/; // '#' 03447 const T slashChar = T(0x002F)/*ASCII_slash*/; // '/' 03448 const T colonChar = T(0x003A)/*ASCII_colon*/; // ':' 03449 const T questionChar = T(0x003F)/*ASCII_question*/; // '?' 03450 03451 /* Extract the scheme if present */ 03452 if (vtkStringOps::IsAbsoluteURI(aURI)) 03453 { 03454 *aScheme = d; 03455 03456 while (*s != colonChar) 03457 { 03458 *d++ = *s++; 03459 } 03460 03461 *d++ = nulChar; 03462 03463 /* Move to the char after the ':' */ 03464 ++s; 03465 } 03466 03467 /* Extract the authority (e.g. [user:pass@]hostname[:port] in http, etc.) */ 03468 if ( *s != nulChar && *(s + 1) != nulChar && 03469 *s == slashChar && *(s + 1) == slashChar ) 03470 { 03471 *aAuthority = d; 03472 03473 s += 2; /* skip after scheme */ 03474 03475 while ( *s != nulChar && 03476 *s != slashChar && 03477 *s != questionChar && 03478 *s != hashChar ) 03479 { 03480 *d++ = *s++; 03481 } 03482 03483 *d++ = nulChar; 03484 } 03485 03486 /* Extract the path (anything before query string or fragment) */ 03487 if (*s != nulChar && *s != questionChar && *s != hashChar) 03488 { 03489 *aPath = d; 03490 03491 while (*s != nulChar && *s != questionChar && *s != hashChar) 03492 { 03493 *d++ = *s++; 03494 } 03495 03496 *d++ = nulChar; 03497 } 03498 03499 /* Extract the query string if present */ 03500 if (*s != nulChar && *s == questionChar) 03501 { 03502 *aQuery = d; 03503 03504 ++s; 03505 03506 while (*s != nulChar && *s != hashChar) 03507 { 03508 *d++ = *s++; 03509 } 03510 03511 *d++ = nulChar; 03512 } 03513 03514 /* Extract the URI-ref fragment if present */ 03515 if (*s != nulChar && *s == hashChar) 03516 { 03517 *aFragment = d; 03518 03519 ++s; 03520 03521 while (*s != nulChar) 03522 { 03523 *d++ = *s++; 03524 } 03525 03526 *d = nulChar; 03527 } 03528 } 03529 03530 // ---------------------------------------------------------------------------- 03531 template <typename T> 03532 inline void 03533 vtkStringOps::ResolveURIReference (const T* aBaseURI, 03534 const T* aReferenceURI, 03535 T* aBuffer, 03536 const vtkSizeType aBufferLength) 03537 { 03538 T* pathBuffer = (T *) 0; 03539 T* baseBuffer = (T *) 0; 03540 T* referenceBuffer = (T *) 0; 03541 03542 int referenceLength; 03543 int baseURILength; 03544 03545 T* baseScheme; 03546 T* baseAuthority; 03547 T* basePath; 03548 T* baseQuery; 03549 T* baseFragment; 03550 03551 T* referenceScheme; 03552 T* referenceAuthority; 03553 T* referencePath; 03554 T* referenceQuery; 03555 T* referenceFragment; 03556 03557 T* resultScheme = (T *) 0; 03558 T* resultAuthority = (T *) 0; 03559 T* resultPath = (T *) 0; 03560 03561 const T nulChar = T(0x0000)/*'<control> NUL'*/; // '\0' 03562 const T hashChar = T(0x0023)/*ASCII_octothorpe*/; // '#' 03563 const T slashChar = T(0x002F)/*ASCII_slash*/; // '/' 03564 const T colonChar = T(0x003A)/*ASCII_colon*/; // ':' 03565 const T questionChar = T(0x003F)/*ASCII_question*/; // '?' 03566 const T periodChar = T(0x002E)/*ASCII_period*/; // '.' 03567 const T slashslashStr[] = { slashChar, slashChar, nulChar }; // "//" 03568 03569 *aBuffer = nulChar; 03570 03571 referenceLength = vtkStringOps::Length(aReferenceURI)+1; 03572 referenceBuffer = new T[referenceLength]; 03573 03574 vtkStringOps::Janitor<T> referenceJanitor(referenceBuffer); 03575 03576 if (vtkStringOps::IsNull(referenceBuffer)) 03577 { 03578 return; 03579 //goto resolve_tidy; 03580 } 03581 03582 vtkStringOps::ParseURI( aReferenceURI, 03583 referenceBuffer, 03584 referenceLength, 03585 &referenceScheme, 03586 &referenceAuthority, 03587 &referencePath, 03588 &referenceQuery, 03589 &referenceFragment ); 03590 03591 /* is reference URI "" or "#frag"? */ 03592 if ( vtkStringOps::IsNull(referenceScheme) && 03593 vtkStringOps::IsNull(referenceAuthority) && 03594 vtkStringOps::IsNull(referencePath) && 03595 vtkStringOps::IsNull(referenceQuery) ) 03596 { 03597 vtkStringOps::Copy(aBuffer, aBaseURI, aBufferLength); 03598 03599 if (vtkStringOps::IsNull(referenceFragment) == VTK_FALSE) 03600 { 03601 vtkStringOps::Concatenate(aBuffer, hashChar, aBufferLength); 03602 vtkStringOps::Concatenate(aBuffer, referenceFragment, aBufferLength); 03603 } 03604 return; 03605 //goto resolve_tidy; 03606 } 03607 03608 /* reference has a scheme - is an absolute URI */ 03609 if (vtkStringOps::IsNull(referenceScheme) == VTK_FALSE) 03610 { 03611 vtkStringOps::Copy(aBuffer, aReferenceURI, aBufferLength); 03612 return; 03613 //goto resolve_tidy; 03614 } 03615 03616 /* now the reference URI must be schemeless, i.e. relative */ 03617 baseURILength = vtkStringOps::Length(aBaseURI); 03618 baseBuffer = new T[baseURILength+1]; 03619 03620 vtkStringOps::Janitor<T> baseJanitor(baseBuffer); 03621 03622 if (vtkStringOps::IsNull(baseBuffer)) 03623 { 03624 return; 03625 //goto resolve_tidy; 03626 } 03627 03628 vtkStringOps::ParseURI( aBaseURI, 03629 baseBuffer, 03630 baseURILength, 03631 &baseScheme, 03632 &baseAuthority, 03633 &basePath, 03634 &baseQuery, 03635 &baseFragment ); 03636 03637 resultScheme = baseScheme; 03638 03639 /* an authority is given ( [user:pass@]hostname[:port] for http) 03640 * so the reference URI is like //authority 03641 */ 03642 if (vtkStringOps::IsNull(referenceAuthority) == VTK_FALSE) 03643 { 03644 resultAuthority = referenceAuthority; 03645 } 03646 else 03647 { // no - so now we have path (maybe with query, fragment) relative to base 03648 resultAuthority = baseAuthority; 03649 03650 if ( vtkStringOps::IsNull(referencePath) == VTK_FALSE && 03651 referencePath[0] == slashChar ) 03652 { /* reference path is absolute */ 03653 resultPath = referencePath; 03654 } 03655 else 03656 { /* need to resolve relative path */ 03657 T* p = (T *) 0; 03658 03659 /* Make result path be path buffer; initialise it to empty */ 03660 int pathBufferLength = vtkStringOps::Length(basePath) + 1; 03661 03662 if (vtkStringOps::IsNull(referencePath) == VTK_FALSE) 03663 pathBufferLength += vtkStringOps::Length(referencePath); 03664 03665 pathBuffer = new T[pathBufferLength]; 03666 03667 vtkStringOps::Janitor<T> pathJanitor(pathBuffer); 03668 03669 if (vtkStringOps::IsNull(pathBuffer)) 03670 { 03671 return; 03672 //goto resolve_tidy; 03673 } 03674 03675 resultPath = pathBuffer; 03676 pathBuffer[0] = nulChar; 03677 03678 int si = vtkStringOps::LastIndexOf(basePath, slashChar); 03679 if (si >= 0) 03680 { 03681 p = &basePath[si]; 03682 03683 /* Found a /, copy everything before that to pathBuffer */ 03684 T* s = basePath; 03685 T* d = pathBuffer; 03686 03687 while (s <= p) 03688 { 03689 *d++ = *s++; 03690 } 03691 03692 *d++ = nulChar; 03693 } 03694 03695 if (vtkStringOps::IsNull(referencePath) == VTK_FALSE) 03696 { 03697 vtkStringOps::Concatenate(pathBuffer, referencePath, pathBufferLength); 03698 } 03699 03700 /* NEW BLOCK - only ANSI C allows this */ 03701 { 03702 /* remove all occurrences of "./" */ 03703 T* p2 = pathBuffer; 03704 T* s = pathBuffer; 03705 03706 while (*s != nulChar) 03707 { 03708 if (*s == slashChar) 03709 { 03710 03711 if (p2 == (s - 1) && *p2 == periodChar) 03712 { 03713 T* d = p2; 03714 03715 ++s; 03716 03717 while (*s != nulChar) 03718 { 03719 *d++ = *s++; 03720 } 03721 03722 *d = nulChar; 03723 03724 s = p2; 03725 } 03726 else 03727 { 03728 p2 = s + 1; 03729 } 03730 } 03731 03732 ++s; 03733 } 03734 03735 /* if the path ends with ".", remove it */ 03736 if (p2 == (s - 1) && *p2 == periodChar) 03737 { 03738 *p2 = nulChar; 03739 } 03740 03741 } /* end BLOCK */ 03742 03743 /* NEW BLOCK - only ANSI C allows this */ 03744 { 03745 /* remove all occurrences of "<segment>/../" */ 03746 T* s = pathBuffer; 03747 /* These form a small stack of path components */ 03748 T* p3 = (T *) 0; /* current component */ 03749 T* p2 = (T *) 0; /* previous component */ 03750 T* p0 = (T *) 0; /* before p2 */ 03751 03752 for(; *s != nulChar; ++s) 03753 { 03754 if (*s != slashChar) 03755 { 03756 if (p3 == nulChar) 03757 { /* Empty stack; initialise */ 03758 p3 = s; 03759 } 03760 else if (p2 == nulChar) 03761 { /* Add 2nd component */ 03762 p2 = s; 03763 } 03764 continue; 03765 } 03766 03767 /* Found a '/' */ 03768 03769 /* Wait till there are two components */ 03770 if (p3 == nulChar || p2 == nulChar) 03771 continue; 03772 03773 /* Two components have been seen */ 03774 03775 /* If the previous one was '..' */ 03776 if (p2 == (s - 2) && *p2 == periodChar && *(p2 + 1) == periodChar) 03777 { 03778 /* If the current one isn't '..' */ 03779 if (*p3 != periodChar && *(p3 + 1) != periodChar) 03780 { 03781 T* d = p3; 03782 03783 ++s; 03784 03785 while (*s != nulChar) 03786 { 03787 *d++ = *s++; 03788 } 03789 03790 *d = nulChar; 03791 03792 if (p0 < p3) 03793 { 03794 s = p3 - 1; 03795 03796 p3 = p0; 03797 p2 = (T *) 0; 03798 } 03799 else 03800 { 03801 s = pathBuffer; 03802 p3 = (T *) 0; 03803 p2 = (T *) 0; 03804 p0 = (T *) 0; 03805 } 03806 } /* end if !.. */ 03807 03808 } 03809 else 03810 { 03811 /* shift the path components stack */ 03812 p0 = p3; 03813 p3 = p2; 03814 p2 = (T *) 0; 03815 } 03816 } /* end for */ 03817 03818 /* if the path ends with "<segment>/..", remove it */ 03819 if (p2 == (s - 2) && *p2 == periodChar && *(p2 + 1) == periodChar) 03820 { 03821 if (vtkStringOps::IsNull(p3) == VTK_FALSE) 03822 { 03823 *p3 = nulChar; 03824 } 03825 } 03826 03827 } /* end BLOCK */ 03828 03829 } /* end resolve relative path */ 03830 } 03831 03832 if (vtkStringOps::IsNull(resultScheme) == VTK_FALSE) 03833 { 03834 vtkStringOps::Copy(aBuffer, resultScheme, aBufferLength); 03835 vtkStringOps::Concatenate(aBuffer, colonChar, aBufferLength); 03836 } 03837 03838 if (vtkStringOps::IsNull(resultAuthority) == VTK_FALSE) 03839 { 03840 vtkStringOps::Concatenate(aBuffer, (T *) slashslashStr, aBufferLength); 03841 vtkStringOps::Concatenate(aBuffer, resultAuthority, aBufferLength); 03842 } 03843 03844 if (vtkStringOps::IsNull(resultPath) == VTK_FALSE) 03845 { 03846 vtkStringOps::Concatenate(aBuffer, resultPath, aBufferLength); 03847 } 03848 03849 if (vtkStringOps::IsNull(referenceQuery) == VTK_FALSE) 03850 { 03851 vtkStringOps::Concatenate(aBuffer, questionChar, aBufferLength); 03852 vtkStringOps::Concatenate(aBuffer, referenceQuery, aBufferLength); 03853 } 03854 03855 if (vtkStringOps::IsNull(referenceFragment) == VTK_FALSE) 03856 { 03857 vtkStringOps::Concatenate(aBuffer, hashChar, aBufferLength); 03858 vtkStringOps::Concatenate(aBuffer, referenceFragment, aBufferLength); 03859 } 03860 } 03861 03862 // ---------------------------------------------------------------------------- 03863 # if 1 03864 template <typename T> 03865 inline vtkUint32Type 03866 vtkStringOps::Hash (const T* const& a) THROW_SPEC() 03867 { 03868 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03869 03870 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03871 for (register const T* p=a; *p != T(0)/*'<control> NUL'*/; p++) 03872 h = 31 * h + vtkUint32Type(*p); 03873 03874 return h; 03875 } 03876 03877 template <typename T> 03878 inline vtkUint32Type 03879 vtkStringOps::HashN (const T* const& a, 03880 const vtkSizeType n) THROW_SPEC() 03881 { 03882 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03883 register vtkSSizeType i = vtkSSizeType(n); 03884 03885 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03886 for (register const T* p=a; i>0 && *p != T(0)/*'<control> NUL'*/; p++, i--) 03887 h = 31 * h + vtkUint32Type(*p); 03888 03889 return h; 03890 } 03891 # else 03892 template <typename T> 03893 inline vtkUint32Type 03894 vtkStringOps::Hash (const T* const& a) THROW_SPEC() 03895 { 03896 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03897 03898 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03899 for (register const T* p=a; *p != T(0)/*'<control> NUL'*/; p++) 03900 h = ((h>>28) ^ (h<<4) ^ vtkUint32Type(*p)); 03901 03902 return h; 03903 } 03904 03905 template <typename T> 03906 inline vtkUint32Type 03907 vtkStringOps::HashN (const T* const& a, const vtkSizeType n) THROW_SPEC() 03908 { 03909 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03910 register vtkSSizeType i = vtkSSizeType(n); 03911 03912 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03913 for (register const T* p=a; i>0 && *p != T(0)/*'<control> NUL'*/; p++, i--) 03914 h = ((h>>28) ^ (h<<4) ^ vtkUint32Type(*p)); 03915 03916 return h; 03917 } 03918 # endif /* 0 */ 03919 03920 // ---------------------------------------------------------------------------- 03921 template <typename T> 03922 inline vtkUint32Type 03923 vtkStringOps::Hash (const T* const& a, 03924 const vtkSizeType aModulus) THROW_SPEC() 03925 { 03926 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03927 03928 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03929 { 03930 register const T* p = a; 03931 03932 while (*p != T(0)/*'<control> NUL'*/) 03933 { 03934 h += (h * 37) + (h >> 24) + vtkUint32Type(*p); 03935 ++p; 03936 } 03937 } 03938 03939 // Divide by modulus 03940 return vtkUint32Type(h % (aModulus != 0 ? aModulus : 1)); 03941 } 03942 03943 template <typename T> 03944 inline vtkUint32Type 03945 vtkStringOps::HashN (const T* const& a, 03946 const vtkSizeType n, 03947 const vtkSizeType aModulus) THROW_SPEC() 03948 { 03949 register vtkUint32Type h = VTK_EXTENSIONS_UINT32(0); 03950 03951 if (vtkStringOps::IsNull(a) == VTK_FALSE) 03952 { 03953 register const T* p = a; 03954 register int i = n; 03955 03956 while ((i-- != 0) && (*p != T(0)/*'<control> NUL'*/)) 03957 { 03958 h += (h * 37) + (h >> 24) + vtkUint32Type(*p); 03959 ++p; 03960 } 03961 } 03962 03963 // Divide by modulus 03964 return vtkUint32Type(h % (aModulus != 0 ? aModulus : 1)); 03965 } 03966 03967 // ---------------------------------------------------------------------------- 03968 template <typename T> 03969 inline T* 03970 vtkStringOps::FileRootname (const T* const& aFileName) 03971 { 03972 if (vtkStringOps::IsEmpty(aFileName)) 03973 { 03974 return vtkStringOps::CreateEmptyString<T>(); 03975 } 03976 03977 int slash = vtkStringOps::LastIndexOf(aFileName, '/'); 03978 int dot; 03979 03980 if ((dot = vtkStringOps::LastIndexOf(aFileName,'.')) != -1 && (dot > slash)) 03981 return vtkStringOps::SubString(aFileName, 0, dot); 03982 03983 vtkSizeType size = vtkStringOps::Length(aFileName); 03984 03985 if (slash == (size - 1)) 03986 return vtkStringOps::SubString(aFileName, 0, slash); 03987 03988 return vtkStringOps::Duplicate(aFileName); 03989 } 03990 03991 template <typename T> 03992 inline const T* 03993 vtkStringOps::FileTailPointer (const T* const& aFileName) 03994 { 03995 if (!vtkStringOps::IsEmpty(aFileName)) 03996 { 03997 int slash = vtkStringOps::LastIndexOf(aFileName, '/'); 03998 03999 return (aFileName + slash + 1/* does not include '/'*/); 04000 } 04001 04002 return (T *) 0; 04003 } 04004 04005 template <typename T> 04006 inline const T* 04007 vtkStringOps::FileExtensionPointer (const T* const& aFileName) 04008 { 04009 const T* tail; 04010 04011 if ((tail = vtkStringOps::FileTailPointer(aFileName)) != (T *) 0) 04012 { 04013 int dot; 04014 04015 if ((dot = vtkStringOps::LastIndexOf(tail, '.')) != -1) 04016 { 04017 return (tail + dot + 1/* does not include '.'*/); 04018 } 04019 } 04020 04021 return (T *) 0; 04022 } 04023 04024 template <typename T> 04025 inline T* 04026 vtkStringOps::FileExtension (const T* const& aFileName) 04027 { 04028 if (!vtkStringOps::IsEmpty(aFileName)) 04029 { 04030 const T* tail = vtkStringOps::FileTailPointer(aFileName); 04031 int dot; 04032 04033 if ((dot = vtkStringOps::LastIndexOf(tail, '.')) != -1) 04034 { 04035 return vtkStringOps::SubString(tail, dot + 1/*does not include '.'*/); 04036 } 04037 } 04038 04039 return vtkStringOps::CreateEmptyString<T>(); 04040 } 04041 04042 template <typename T> 04043 inline T* 04044 vtkStringOps::FileDirname (const T* const& aFileName) 04045 { 04046 if (vtkStringOps::IsEmpty(aFileName)) 04047 { 04048 return vtkStringOps::CreateEmptyString<T>(); 04049 } 04050 04051 int slash; 04052 04053 if ((slash = vtkStringOps::LastIndexOf(aFileName, '/')) == -1) 04054 { 04055 T cwd[2] = { '.', '\0' }; 04056 return vtkStringOps::Duplicate((const T *) cwd); 04057 } 04058 else if (slash == 0) 04059 { 04060 T root[2] = { '/', '\0' }; 04061 return vtkStringOps::Duplicate((const T *) root); 04062 } 04063 04064 return vtkStringOps::SubString(aFileName, 0, slash); 04065 } 04066 04067 template <typename T> 04068 inline T* 04069 vtkStringOps::FileJoin (const T* const& aHead, 04070 const T* const& aTail) 04071 { 04072 if (vtkStringOps::IsEmpty(aHead) && vtkStringOps::IsEmpty(aTail)) 04073 { 04074 return vtkStringOps::CreateEmptyString<T>(); 04075 } 04076 04077 T* result = (T *) 0; 04078 T* head = (T *) 0; 04079 T* tail = (T *) 0; 04080 04081 try 04082 { 04083 head = vtkStringOps::Duplicate(aHead); 04084 // Lop any whitespace off the ends. 04085 vtkStringOps::Trim(head); 04086 // Remeasure. 04087 vtkSizeType headLength = vtkStringOps::Length(head); 04088 04089 tail = vtkStringOps::Duplicate(aTail); 04090 // Lop any whitespace off the ends. 04091 vtkStringOps::Trim(tail); 04092 // Remeasure. 04093 vtkSizeType tailLength = vtkStringOps::Length(tail); 04094 04095 if (headLength == 0 && tailLength == 0) 04096 { 04097 result = vtkStringOps::CreateEmptyString<T>(); 04098 } 04099 else 04100 { 04101 vtkSizeType resultLength = headLength + tailLength; 04102 04103 vtkBoolType appendSeparator = VTK_FALSE; 04104 04105 if ( (tailLength > 0) && 04106 (headLength > 0) && 04107 (head[headLength - 1] != '/') && 04108 (tail[0] != '/') ) 04109 { 04110 ++resultLength; 04111 appendSeparator = VTK_TRUE; 04112 } 04113 04114 result = new T [resultLength + 1/*for terminal nul*/]; 04115 result[0] = T(0)/*'<control> NUL'*/; 04116 04117 vtkStringOps::Concatenate(result, head); 04118 if (appendSeparator) vtkStringOps::Concatenate(result, '/'); 04119 vtkStringOps::Concatenate(result, tail); 04120 } 04121 } 04122 catch (...) 04123 { 04124 vtkStringOps::Release(&result); 04125 } 04126 04127 vtkStringOps::Release(&head); 04128 vtkStringOps::Release(&tail); 04129 04130 return result; 04131 } 04132 04133 template <typename T> 04134 inline T* 04135 vtkStringOps::FileJoin (const T** const& aList, 04136 vtkBoolType aAbsoluteFlag) 04137 { 04138 if (aList == (T **) 0 || aList[0] == (T *) 0 || aList[0][0] == T('\0')) 04139 { 04140 return vtkStringOps::CreateEmptyString<T>(); 04141 } 04142 04143 vtkSizeType jSize = 0; 04144 04145 for (T* jPtr = *aList; jPtr != (T *) 0; jPtr++) 04146 { 04147 T* iPtr = jPtr; 04148 vtkSizeType iSize = 0; 04149 04150 while (vtkStringOps::IsWhiteSpace(*iPtr)) 04151 iPtr++; // skip leading whitespaces 04152 while (*iPtr == T('/')) 04153 iPtr++; // skip leading slashes 04154 for ( ; vtkStringOps::IsWhiteSpace(*iPtr) == VTK_FALSE && 04155 *iPtr != T('/') && *iPtr != T('\0'); iPtr++ ) 04156 ++iSize; // count path component length (exclude spaces or trailing '/') 04157 if (iSize > 0) 04158 jSize += (iSize + 1/*for leading slash to be added*/); 04159 } 04160 04161 T* result = (T *) 0; 04162 04163 try 04164 { 04165 if (jSize == 0) 04166 { 04167 if (aAbsoluteFlag) 04168 { 04169 result = new T [2]; 04170 result[0] = T('/'); 04171 result[1] = T('\0'); 04172 } 04173 else 04174 { 04175 result = vtkStringOps::CreateEmptyString<T>(); 04176 } 04177 } 04178 else 04179 { 04180 jSize += (aAbsoluteFlag ? 1 : 0); 04181 04182 result = new T [jSize]; 04183 04184 // Initialize char array to nuls. 04185 for (int j=0; j<jSize; j++) result[j] = T('\0')/*'<control> NUL'*/; 04186 04187 T* resultPtr = result; 04188 04189 for (T* jPtr = *aList; jPtr != (T *) 0; jPtr++) 04190 { 04191 if (aAbsoluteFlag == VTK_TRUE || jPtr != *aList) 04192 *resultPtr++ = T('/'); // append path component separator 04193 04194 T* iPtr = jPtr; 04195 04196 while (vtkStringOps::IsWhiteSpace(*iPtr)) 04197 iPtr++; // skip leading whitespaces 04198 while (*iPtr == T('/')) 04199 iPtr++; // skip leading slashes 04200 for ( ; vtkStringOps::IsWhiteSpace(*iPtr) == VTK_FALSE && 04201 *iPtr != T('/') && *iPtr != T('\0'); iPtr++ ) 04202 *resultPtr++ = *iPtr; // append characters of path component. 04203 04204 // handle empty path components without obliterating absolute pathnames. 04205 if ( (resultPtr != result) && *(resultPtr - 1) == T('/') && 04206 (aAbsoluteFlag == VTK_FALSE || jPtr != *aList) ) 04207 *--resultPtr = T('\0'); 04208 } 04209 } 04210 } 04211 catch (...) 04212 { 04213 vtkStringOps::Release(&result); 04214 } 04215 04216 return result; 04217 } 04218 04219 // ---------------------------------------------------------------------------- 04220 template <typename T> 04221 inline vtkBoolType 04222 vtkStringOps::CreateDirectory (const T* const& aDirName, mode_t aMode) 04223 { 04224 if (vtkStringOps::IsEmpty(aDirName)) 04225 return VTK_FALSE; 04226 04227 char* dirName = (char *) 0; 04228 vtkBoolType result = VTK_FALSE; 04229 04230 try 04231 { 04232 dirName = 04233 vtkStringOps::FileDirname(vtkStringOps::ToLatin1(aDirName).data()); 04234 04235 result = vtkStringOps::Mkdir(dirName, aMode); 04236 } 04237 catch (...) 04238 { 04239 } 04240 04241 vtkStringOps::Release(&dirName); 04242 04243 return result; 04244 } 04245 04246 inline vtkBoolType 04247 vtkStringOps::CreateDirectory (const char* const& aDirName, mode_t aMode) 04248 { 04249 if (vtkStringOps::IsEmpty(aDirName)) 04250 return VTK_FALSE; 04251 04252 char* dirName = (char *) 0; 04253 vtkBoolType result = VTK_FALSE; 04254 04255 try 04256 { 04257 dirName = vtkStringOps::FileDirname(aDirName); 04258 result = vtkStringOps::Mkdir(dirName, aMode); 04259 } 04260 catch (...) 04261 { 04262 } 04263 04264 vtkStringOps::Release(&dirName); 04265 04266 return result; 04267 } 04268 04269 // ---------------------------------------------------------------------------- 04270 inline vtkBoolType 04271 vtkStringOps::GetCWD (char** aBuffer) 04272 { 04273 if (aBuffer == (char **) 0) 04274 return VTK_FALSE; 04275 04276 if (*aBuffer != (char *) 0) 04277 vtkStringOps::Release(aBuffer); 04278 04279 vtkSizeType size = 256; 04280 04281 try 04282 { 04283 *aBuffer = new char [size]; 04284 04285 while (!vtkStringOps::GetCWD(*aBuffer, size)) 04286 { 04287 vtkStringOps::Release(aBuffer); 04288 if ((size *= 2) > 8192) break; 04289 *aBuffer = new char [size]; 04290 } 04291 } 04292 catch (...) 04293 { 04294 vtkStringOps::Release(aBuffer); 04295 } 04296 04297 return *aBuffer != (char *) 0; 04298 } 04299 04300 inline char* 04301 vtkStringOps::GetCWD (void) 04302 { 04303 char* buffer = (char *) 0; 04304 04305 vtkStringOps::GetCWD(&buffer); 04306 04307 return buffer; 04308 } 04309 04310 04311 // ---------------------------------------------------------------------------- 04312 template <typename T> 04313 inline vtkBoolType 04314 vtkStringOps::CanReadDirectory (const T* const& aDirName) 04315 { 04316 if (vtkStringOps::IsEmpty(aDirName)) 04317 return VTK_FALSE; 04318 04319 vtkStringOps::ToLatin1 lat1(aDirName); // Doesn't need janitor. 04320 const char* ptr = lat1.data(); 04321 04322 if ( (vtkStringOps::FileIsDirectory(ptr) == VTK_FALSE) || 04323 (vtkStringOps::FileIsReadable(ptr) == VTK_FALSE) ) 04324 return VTK_FALSE; 04325 04326 return VTK_TRUE; 04327 } 04328 04329 template <typename T> 04330 inline vtkBoolType 04331 vtkStringOps::CanReadFile (const T* const& aFileName) 04332 { 04333 if (vtkStringOps::IsEmpty(aFileName)) 04334 return VTK_FALSE; 04335 04336 vtkStringOps::ToLatin1 lat1(aFileName); // Doesn't need janitor. 04337 const char* ptr = lat1.data(); 04338 04339 if ( (vtkStringOps::CanStatFile(ptr) == VTK_FALSE) || 04340 (vtkStringOps::FileIsDirectory(ptr) == VTK_TRUE) || 04341 (vtkStringOps::FileIsReadable(ptr) == VTK_FALSE) ) 04342 return VTK_FALSE; 04343 04344 return VTK_TRUE; 04345 } 04346 04347 template <typename T> 04348 inline vtkBoolType 04349 vtkStringOps::CanWriteDirectory (const T* const& aDirName) 04350 { 04351 if (vtkStringOps::IsEmpty(aDirName)) 04352 return VTK_FALSE; 04353 04354 vtkStringOps::ToLatin1 lat1(aDirName); // Doesn't need janitor. 04355 const char* ptr = lat1.data(); 04356 04357 if ( (vtkStringOps::FileIsDirectory(ptr) == VTK_FALSE) || 04358 (vtkStringOps::FileIsWritable(ptr) == VTK_FALSE) ) 04359 return VTK_FALSE; 04360 04361 return VTK_TRUE; 04362 } 04363 04364 template <typename T> 04365 inline vtkBoolType 04366 vtkStringOps::CanWriteFile (const T* const& aFileName) 04367 { 04368 if (vtkStringOps::IsEmpty(aFileName)) 04369 return VTK_FALSE; 04370 04371 vtkStringOps::ToLatin1 lat1(aFileName); // Doesn't need janitor. 04372 const char* ptr = lat1.data(); 04373 04374 if (vtkStringOps::CanStatFile(ptr) == VTK_FALSE) 04375 { 04376 T* dirName = (T *) 0; 04377 vtkBoolType result = VTK_FALSE; 04378 04379 if (vtkStringOps::FileExists(ptr) == VTK_FALSE) 04380 { 04381 dirName = vtkStringOps::FileDirname(aFileName); 04382 result = vtkStringOps::CanWriteDirectory(dirName); 04383 vtkStringOps::Release(&dirName); 04384 } 04385 04386 return result; 04387 } 04388 else if ( (vtkStringOps::FileIsDirectory(ptr) == VTK_TRUE) || 04389 (vtkStringOps::FileIsWritable(ptr) == VTK_FALSE) ) 04390 { 04391 return VTK_FALSE; 04392 } 04393 04394 return VTK_TRUE; 04395 } 04396 04397 inline vtkBoolType 04398 vtkStringOps::CanWriteFile (const char* const& aFileName) 04399 { 04400 if (vtkStringOps::IsEmpty(aFileName)) 04401 return VTK_FALSE; 04402 04403 const char* ptr = aFileName; 04404 04405 if (vtkStringOps::CanStatFile(ptr) == VTK_FALSE) 04406 { 04407 char* dirName = (char *) 0; 04408 vtkBoolType result = VTK_FALSE; 04409 04410 if (vtkStringOps::FileExists(ptr) == VTK_FALSE) 04411 { 04412 dirName = vtkStringOps::FileDirname(aFileName); 04413 result = vtkStringOps::CanWriteDirectory(dirName); 04414 vtkStringOps::Release(&dirName); 04415 } 04416 04417 return result; 04418 } 04419 else if ( (vtkStringOps::FileIsDirectory(ptr) == VTK_TRUE) || 04420 (vtkStringOps::FileIsWritable(ptr) == VTK_FALSE) ) 04421 { 04422 return VTK_FALSE; 04423 } 04424 04425 return VTK_TRUE; 04426 } 04427 04428 template <typename T> 04429 inline vtkBoolType 04430 vtkStringOps::CheckDirectoryExists (const T* const& aDirName) 04431 { 04432 if (vtkStringOps::IsEmpty(aDirName)) 04433 return VTK_FALSE; 04434 04435 vtkStringOps::ToLatin1 lat1(aDirName); // Doesn't need janitor. 04436 const char* ptr = lat1.data(); 04437 04438 if ( (vtkStringOps::FileIsDirectory(ptr) == VTK_FALSE) || 04439 (vtkStringOps::FileExists(ptr) == VTK_FALSE) ) 04440 return VTK_FALSE; 04441 04442 return VTK_TRUE; 04443 } 04444 04445 template <typename T> 04446 inline vtkBoolType 04447 vtkStringOps::CheckFileExists (const T* const& aFileName) 04448 { 04449 if (vtkStringOps::IsEmpty(aFileName)) 04450 return VTK_FALSE; 04451 04452 vtkStringOps::ToLatin1 lat1(aFileName); // Doesn't need janitor. 04453 const char* ptr = lat1.data(); 04454 04455 if ( (vtkStringOps::CanStatFile(ptr) == VTK_FALSE) || 04456 (vtkStringOps::FileIsDirectory(ptr) == VTK_TRUE) || 04457 (vtkStringOps::FileExists(ptr) == VTK_FALSE) ) 04458 return VTK_FALSE; 04459 04460 return VTK_TRUE; 04461 } 04462 04463 // ---------------------------------------------------------------------------- 04464 template <typename T> 04465 inline T* 04466 vtkStringOps::GetRelativePrefix (const T* const& aFileName, 04467 const T* const& aRootPath) THROW_SPEC() 04468 { 04469 T* pfx = (T *) 0; 04470 04471 try 04472 { 04473 // Returns the prefix (no extension) of filename relative to vtkMrml::Dir 04474 pfx = vtkStringOps::FileRootname(aFileName); 04475 04476 if (vtkStringOps::IsPrefix(pfx, aRootPath)) 04477 { 04478 vtkSSizeType pfxSize = vtkStringOps::Length(pfx); 04479 vtkSSizeType rootSize = vtkStringOps::Length(aRootPath); 04480 04481 if (aRootPath[rootSize - 1] == '/') 04482 vtkStringOps::Move(pfx, (const T *) (pfx+rootSize), 1+pfxSize-rootSize); 04483 else if (pfx[rootSize] == '/') 04484 vtkStringOps::Move(pfx, (const T *) (pfx+rootSize+1), pfxSize-rootSize); 04485 } 04486 } 04487 catch (...) 04488 { 04489 vtkStringOps::Release(&pfx); 04490 } 04491 04492 return pfx; 04493 } 04494 04495 // ---------------------------------------------------------------------------- 04496 template <typename T> 04497 inline T* 04498 vtkStringOps::GetRelativeDirPrefix (const T* const& aDirName, 04499 const T* const& aRootPath, 04500 T** const& aPfxResult) THROW_SPEC() 04501 { 04502 T* result = (T *) 0; 04503 T** rootList = (T **) 0; 04504 T** dirList = (T **) 0; 04505 T** pfxList = (T **) 0; 04506 04507 // Returns the prefix (no extension) of aDirName relative to aRootPath 04508 04509 try 04510 { 04511 if ( vtkStringOps::IsEmpty(aDirName) || 04512 vtkStringOps::IsEmpty(aRootPath) || 04513 (aRootPath[0] != aDirName[0]) ) 04514 { 04515 result = vtkStringOps::Duplicate(aDirName); 04516 } 04517 else 04518 { 04519 rootList = vtkStringOps::Tokenize(aRootPath, (const char *) "/"); 04520 dirList = vtkStringOps::Tokenize(aDirName, (const char *) "/"); 04521 04522 # if defined(VTK_EXTENSIONS_WIN32) 04523 T* tmp; 04524 04525 tmp = rootList[0]; 04526 rootList[0] = vtkStringOps::ToLower(tmp); 04527 vtkStringOps::Release(&tmp); 04528 04529 tmp = dirList[0]; 04530 dirList[0] = vtkStringOps::ToLower(tmp); 04531 vtkStringOps::Release(&tmp); 04532 # endif /* VTK_EXTENSIONS_WIN32 */ 04533 04534 vtkSizeType dirListSize = 0; 04535 04536 for (int i=0; dirList[i] != (T *) 0; i++) dirListSize++; 04537 04538 pfxList = new T * [dirListSize + 1]; 04539 for (int i=0; i<=dirListSize; i++) pfxList[i] = (T *) 0; 04540 04541 T* rootPtr = rootList[0]; 04542 T* dirPtr = dirList[0]; 04543 T* pfxPtr = pfxList[0]; 04544 04545 while ( vtkStringOps::IsNull(dirPtr) == VTK_FALSE && 04546 vtkStringOps::IsNull(rootPtr) == VTK_FALSE ) 04547 { 04548 if (vtkStringOps::Equals(dirPtr, rootPtr++) == VTK_FALSE) break; 04549 pfxPtr++ = dirPtr++; 04550 } 04551 04552 if (vtkStringOps::IsNull(pfxList[0]) == VTK_FALSE) 04553 { 04554 if (aPfxResult != (T **) 0) 04555 *aPfxResult = vtkStringOps::FileJoin(pfxList, aRootPath[0] == T('/')); 04556 result = vtkStringOps::FileJoin(dirList, VTK_FALSE/*not absolute*/); 04557 } 04558 else 04559 { 04560 if (aPfxResult != (T **) 0) 04561 *aPfxResult = (T *) 0; 04562 result = vtkStringOps::FileJoin(dirList, aDirName[0] == T('/')); 04563 } 04564 04565 } 04566 } 04567 catch (...) 04568 { 04569 vtkStringOps::Release(&result); 04570 //vtkStringOps::Release(aPfxResult); 04571 } 04572 04573 vtkStringOps::Release(&rootList); 04574 vtkStringOps::Release(&dirList); 04575 vtkStringOps::Release(&pfxList); 04576 04577 return result; 04578 } 04579 04580 // ---------------------------------------------------------------------------- 04581 template <typename T> 04582 inline void 04583 vtkStringOps::Release (T** const& a) 04584 { 04585 if (vtkStringOps::IsNull(*a) == VTK_FALSE) 04586 { 04587 delete [] *a; 04588 *a = (T *) 0; 04589 } 04590 } 04591 04592 template <typename T> 04593 inline void 04594 vtkStringOps::Release (T*** const& a) 04595 { 04596 if (*a != (T **) 0) 04597 { 04598 T** p = *a; 04599 04600 while (*p != (T *) 0) 04601 { 04602 delete [] *p; 04603 *p = (T *) 0; 04604 ++p; 04605 } 04606 04607 delete [] *a; 04608 *a = (T **) 0; 04609 } 04610 } 04611 04612 // ---------------------------------------------------------------------------- 04613 inline ostream& 04614 operator<< (ostream& aTarget, const vtkStringOps::ToLatin1& a) 04615 { 04616 if (a.data()) aTarget << a.data(); 04617 04618 return aTarget; 04619 } 04620 04621 inline ostream& 04622 operator<< (ostream& aTarget, const vtkStringOps::ToUTF8& a) 04623 { 04624 if (a.data()) aTarget << a.data(); 04625 04626 return aTarget; 04627 } 04628 04629 VTK_EXTENSIONS_NAMESPACE_END 04630 04631 #endif /* VTK_STRING_OPS_H_ */ 04632 /* 04633 * End of $Id: vtkStringOps.h,v 1.4 2004/08/10 07:37:21 xpxqx Exp $. 04634 * 04635 */

Generated on Tue Aug 10 03:38:41 2004 for vtkExtensions by doxygen 1.3.7