VTK
vtkUnicodeString.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkUnicodeString.h
5 
6 -------------------------------------------------------------------------
7  Copyright 2008 Sandia Corporation.
8  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9  the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11 
12  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13  All rights reserved.
14  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notice for more information.
19 
20 =========================================================================*/
21 
49 #ifndef __vtkUnicodeString_h
50 #define __vtkUnicodeString_h
51 
52 #include <vtkSystemIncludes.h>
53 #include <vtkstd/string>
54 #include <vtkstd/vector>
55 
57 
58 typedef vtkTypeUInt32 vtkUnicodeStringValueType;
59 
60 //
61 // The following should be eventually placed in vtkSetGet.h
62 //
63 
64 // This is same as extra extended template macro with an
65 // additional case for VTK_UNICODE_STRING
66 #define vtkSuperExtraExtendedTemplateMacro(call) \
67  vtkExtraExtendedTemplateMacro(call); \
68  vtkTemplateMacroCase(VTK_UNICODE_STRING, vtkUnicodeString, call)
69 
71 {
72 public:
74  typedef vtkstd::string::size_type size_type;
75 
77  {
78  public:
79  typedef vtkstd::bidirectional_iterator_tag iterator_category;
81  typedef vtkstd::string::difference_type difference_type;
82  typedef value_type* pointer;
84 
86 
87  value_type operator*() const;
88  bool operator==(const const_iterator&) const;
89  bool operator!=(const const_iterator&) const;
90  const_iterator& operator++();
91  const_iterator operator++(int);
92  const_iterator& operator--();
93  const_iterator operator--(int);
94 
95  private:
96  const_iterator(vtkstd::string::const_iterator);
97  friend class vtkUnicodeString;
98  vtkstd::string::const_iterator Position;
99  };
100 
102 
104  // Description:
105  // Makes a deep-copy of another sequence.
107  // Description:
108  // Constructs a sequence of repeated characters. Note: throws an exception if
109  // the character isn't a valid Unicode code point.
110  vtkUnicodeString(size_type count, value_type character);
111  // Description:
112  // Constructs a string from a sequence of Unicode characters.
115 
117 
119  static bool is_utf8(const char*);
120  static bool is_utf8(const vtkstd::string&);
122 
124 
126  static vtkUnicodeString from_utf8(const char*);
127  // Constructs a string from a half-open sequence of UTF-8 encoded characters.
128  static vtkUnicodeString from_utf8(const char* begin, const char* end);
129  // Constructs a string from a sequence of UTF-8 encoded characters.
130  static vtkUnicodeString from_utf8(const vtkstd::string&);
131  // Description:
132  // Constructs a string from a null-terminated sequence of UTF-16 encoded characters.
133  static vtkUnicodeString from_utf16(const vtkTypeUInt16*);
135 
138 
140 
142  const_iterator begin() const;
143  // Description:
144  // Returns a forward iterator that points just beyond the end of the sequence.
145  const_iterator end() const;
147 
149 
152  value_type at(size_type offset) const;
153  // Description:
154  // Returns the Unicode character at the given character offset within the sequence.
155  // Behavior is undefined if the position is invalid.
156  value_type operator[](size_type offset) const;
158 
160 
162  const char* utf8_str() const;
163  // Description:
164  // Inserts the sequence into the supplied storage as a collection of UTF-8 encoded
165  // characters.
166  void utf8_str(vtkstd::string& result) const;
167  // Description:
168  // Returns the sequence as a collection of UTF-16 encoded characters.
169  vtkstd::vector<vtkTypeUInt16> utf16_str() const;
170  // Description:
171  // Inserts the sequence into the supplied storage as a collection of UTF-16 encoded
172  // characters
173  void utf16_str(vtkstd::vector<vtkTypeUInt16>& result) const;
175 
177 
178  size_type byte_count() const;
179  // Description:
180  // Returns the number of characters (not bytes) in the sequence.
181  size_type character_count() const;
182  // Description:
183  // Returns true if the string contains an empty sequence.
184  bool empty() const;
186 
188  static const size_type npos;
189 
191 
193  // Description:
194  // Append a Unicode sequence to the end of the current sequence.
197 
199  void push_back(value_type);
200 
202 
203  void append(const vtkUnicodeString& value);
204  void append(size_type count, value_type character);
207 
209 
210  void assign(const vtkUnicodeString& value);
211  void assign(size_type count, value_type character);
214 
216  void clear();
217 
224  vtkUnicodeString fold_case() const;
225 
231  int compare(const vtkUnicodeString&) const;
232 
235  vtkUnicodeString substr(size_type offset = 0, size_type count = npos) const;
236 
238  void swap(vtkUnicodeString&);
239 
240 private:
241  vtkstd::string Storage;
242  class back_insert_iterator;
243 };
244 
247 VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
250 VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
251 
252 #endif
253 
static vtkUnicodeString from_utf16(const vtkTypeUInt16 *)
vtkstd::bidirectional_iterator_tag iterator_category
static bool is_utf8(const char *)
vtkUnicodeString & operator=(const vtkUnicodeString &)
vtkUnicodeString fold_case() const
value_type operator[](size_type offset) const
void append(const vtkUnicodeString &value)
void push_back(value_type)
vtkUnicodeStringValueType value_type
size_type byte_count() const
size_type character_count() const
int compare(const vtkUnicodeString &) const
vtkUnicodeString & operator+=(value_type)
vtkstd::vector< vtkTypeUInt16 > utf16_str() const
VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
static vtkUnicodeString from_utf8(const char *)
vtkstd::string::difference_type difference_type
const char * utf8_str() const
VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
#define VTK_COMMON_EXPORT
void swap(vtkUnicodeString &)
void assign(const vtkUnicodeString &value)
static const size_type npos
value_type at(size_type offset) const
const_iterator end() const
vtkUnicodeString substr(size_type offset=0, size_type count=npos) const
VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
bool empty() const
vtkTypeUInt32 vtkUnicodeStringValueType
vtkUnicodeStringValueType value_type
vtkstd::string::size_type size_type
String class that stores Unicode text.
const_iterator begin() const