VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkUnicodeString.h 00005 00006 ------------------------------------------------------------------------- 00007 Copyright 2008 Sandia Corporation. 00008 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 the U.S. Government retains certain rights in this software. 00010 ------------------------------------------------------------------------- 00011 00012 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00013 All rights reserved. 00014 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00015 00016 This software is distributed WITHOUT ANY WARRANTY; without even 00017 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00018 PURPOSE. See the above copyright notice for more information. 00019 00020 =========================================================================*/ 00021 00049 #ifndef __vtkUnicodeString_h 00050 #define __vtkUnicodeString_h 00051 00052 #include <vtkSystemIncludes.h> 00053 #include <vtkstd/string> 00054 #include <vtkstd/vector> 00055 00056 class vtkUnicodeString; 00057 00058 typedef vtkTypeUInt32 vtkUnicodeStringValueType; 00059 00060 // 00061 // The following should be eventually placed in vtkSetGet.h 00062 // 00063 00064 // This is same as extra extended template macro with an 00065 // additional case for VTK_UNICODE_STRING 00066 #define vtkSuperExtraExtendedTemplateMacro(call) \ 00067 vtkExtraExtendedTemplateMacro(call); \ 00068 vtkTemplateMacroCase(VTK_UNICODE_STRING, vtkUnicodeString, call) 00069 00070 class VTK_COMMON_EXPORT vtkUnicodeString 00071 { 00072 public: 00073 typedef vtkUnicodeStringValueType value_type; 00074 typedef vtkstd::string::size_type size_type; 00075 00076 class VTK_COMMON_EXPORT const_iterator 00077 { 00078 public: 00079 typedef vtkstd::bidirectional_iterator_tag iterator_category; 00080 typedef vtkUnicodeStringValueType value_type; 00081 typedef vtkstd::string::difference_type difference_type; 00082 typedef value_type* pointer; 00083 typedef value_type& reference; 00084 00085 const_iterator(); 00086 00087 value_type operator*() const; 00088 bool operator==(const const_iterator&) const; 00089 bool operator!=(const const_iterator&) const; 00090 const_iterator& operator++(); 00091 const_iterator operator++(int); 00092 const_iterator& operator--(); 00093 const_iterator operator--(int); 00094 00095 private: 00096 const_iterator(vtkstd::string::const_iterator); 00097 friend class vtkUnicodeString; 00098 vtkstd::string::const_iterator Position; 00099 }; 00100 00102 00103 vtkUnicodeString(); 00104 // Description: 00105 // Makes a deep-copy of another sequence. 00106 vtkUnicodeString(const vtkUnicodeString&); 00107 // Description: 00108 // Constructs a sequence of repeated characters. Note: throws an exception if 00109 // the character isn't a valid Unicode code point. 00110 vtkUnicodeString(size_type count, value_type character); 00111 // Description: 00112 // Constructs a string from a sequence of Unicode characters. 00113 vtkUnicodeString(const_iterator begin, const_iterator end); 00115 00117 00119 static bool is_utf8(const char*); 00120 static bool is_utf8(const vtkstd::string&); 00122 00124 00126 static vtkUnicodeString from_utf8(const char*); 00127 // Constructs a string from a half-open sequence of UTF-8 encoded characters. 00128 static vtkUnicodeString from_utf8(const char* begin, const char* end); 00129 // Constructs a string from a sequence of UTF-8 encoded characters. 00130 static vtkUnicodeString from_utf8(const vtkstd::string&); 00131 // Description: 00132 // Constructs a string from a null-terminated sequence of UTF-16 encoded characters. 00133 static vtkUnicodeString from_utf16(const vtkTypeUInt16*); 00135 00137 vtkUnicodeString& operator=(const vtkUnicodeString&); 00138 00140 00142 const_iterator begin() const; 00143 // Description: 00144 // Returns a forward iterator that points just beyond the end of the sequence. 00145 const_iterator end() const; 00147 00149 00152 value_type at(size_type offset) const; 00153 // Description: 00154 // Returns the Unicode character at the given character offset within the sequence. 00155 // Behavior is undefined if the position is invalid. 00156 value_type operator[](size_type offset) const; 00158 00160 00162 const char* utf8_str() const; 00163 // Description: 00164 // Inserts the sequence into the supplied storage as a collection of UTF-8 encoded 00165 // characters. 00166 void utf8_str(vtkstd::string& result) const; 00167 // Description: 00168 // Returns the sequence as a collection of UTF-16 encoded characters. 00169 vtkstd::vector<vtkTypeUInt16> utf16_str() const; 00170 // Description: 00171 // Inserts the sequence into the supplied storage as a collection of UTF-16 encoded 00172 // characters 00173 void utf16_str(vtkstd::vector<vtkTypeUInt16>& result) const; 00175 00177 00178 size_type byte_count() const; 00179 // Description: 00180 // Returns the number of characters (not bytes) in the sequence. 00181 size_type character_count() const; 00182 // Description: 00183 // Returns true if the string contains an empty sequence. 00184 bool empty() const; 00186 00188 static const size_type npos; 00189 00191 00192 vtkUnicodeString& operator+=(value_type); 00193 // Description: 00194 // Append a Unicode sequence to the end of the current sequence. 00195 vtkUnicodeString& operator+=(const vtkUnicodeString& rhs); 00197 00199 void push_back(value_type); 00200 00202 00203 void append(const vtkUnicodeString& value); 00204 void append(size_type count, value_type character); 00205 void append(const_iterator begin, const_iterator end); 00207 00209 00210 void assign(const vtkUnicodeString& value); 00211 void assign(size_type count, value_type character); 00212 void assign(const_iterator begin, const_iterator end); 00214 00216 void clear(); 00217 00224 vtkUnicodeString fold_case() const; 00225 00231 int compare(const vtkUnicodeString&) const; 00232 00235 vtkUnicodeString substr(size_type offset = 0, size_type count = npos) const; 00236 00238 void swap(vtkUnicodeString&); 00239 00240 private: 00241 vtkstd::string Storage; 00242 class back_insert_iterator; 00243 }; 00244 00245 VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00246 VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00247 VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00248 VTK_COMMON_EXPORT bool operator<=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00249 VTK_COMMON_EXPORT bool operator>=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00250 VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs); 00251 00252 #endif 00253