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 
50 #ifndef vtkUnicodeString_h
51 #define vtkUnicodeString_h
52 
53 #include "vtkCommonCoreModule.h" // For export macro
54 #include "vtkSystemIncludes.h"
55 #include <string>
56 #include <vector>
57 
59 
60 typedef vtkTypeUInt32 vtkUnicodeStringValueType;
61 
62 //
63 // The following should be eventually placed in vtkSetGet.h
64 //
65 
66 // This is same as extra extended template macro with an
67 // additional case for VTK_UNICODE_STRING
68 #define vtkSuperExtraExtendedTemplateMacro(call) \
69  vtkExtraExtendedTemplateMacro(call); \
70  vtkTemplateMacroCase(VTK_UNICODE_STRING, vtkUnicodeString, call)
71 
72 class VTKCOMMONCORE_EXPORT vtkUnicodeString
73 {
74 public:
76  typedef std::string::size_type size_type;
77 
78  class VTKCOMMONCORE_EXPORT const_iterator
79  {
80  public:
81  typedef std::bidirectional_iterator_tag iterator_category;
83  typedef std::string::difference_type difference_type;
84  typedef value_type* pointer;
86 
88 
89  value_type operator*() const;
90  bool operator==(const const_iterator&) const;
91  bool operator!=(const const_iterator&) const;
92  const_iterator& operator++();
93  const_iterator operator++(int);
94  const_iterator& operator--();
95  const_iterator operator--(int);
96 
97  private:
98  const_iterator(std::string::const_iterator);
99  friend class vtkUnicodeString;
100  std::string::const_iterator Position;
101  };
102 
115  vtkUnicodeString(size_type count, value_type character);
120 
122 
125  static bool is_utf8(const char*);
126  static bool is_utf8(const std::string&);
128 
130 
133  static vtkUnicodeString from_utf8(const char*);
134  // Constructs a string from a half-open sequence of UTF-8 encoded characters.
135  static vtkUnicodeString from_utf8(const char* begin, const char* end);
136  // Constructs a string from a sequence of UTF-8 encoded characters.
137  static vtkUnicodeString from_utf8(const std::string&);
139 
142  static vtkUnicodeString from_utf16(const vtkTypeUInt16*);
143 
148 
153  const_iterator begin() const;
157  const_iterator end() const;
158 
163  value_type at(size_type offset) const;
169 
173  const char* utf8_str() const;
178  void utf8_str(std::string& result) const;
182  std::vector<vtkTypeUInt16> utf16_str() const;
187  void utf16_str(std::vector<vtkTypeUInt16>& result) const;
188 
192  size_type byte_count() const;
196  size_type character_count() const;
200  bool empty() const;
201 
205  static const size_type npos;
206 
215 
219  void push_back(value_type);
220 
222 
225  void append(const vtkUnicodeString& value);
226  void append(size_type count, value_type character);
229 
231 
234  void assign(const vtkUnicodeString& value);
235  void assign(size_type count, value_type character);
238 
242  void clear();
243 
252  vtkUnicodeString fold_case() const;
253 
261  int compare(const vtkUnicodeString&) const;
262 
268 
272  void swap(vtkUnicodeString&);
273 
274 private:
275  std::string Storage;
276  class back_insert_iterator;
277 };
278 
279 VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
280 VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
281 VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
282 VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
283 VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
284 VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
285 
286 #endif
287 
288 // VTK-HeaderTest-Exclude: vtkUnicodeString.h
vtkUnicodeString::const_iterator::difference_type
std::string::difference_type difference_type
Definition: vtkUnicodeString.h:83
vtkUnicodeString::from_utf16
static vtkUnicodeString from_utf16(const vtkTypeUInt16 *)
Constructs a string from a null-terminated sequence of UTF-16 encoded characters.
vtkUnicodeString::compare
int compare(const vtkUnicodeString &) const
Returns a negative value if the sequence compares less-than the operand sequence, zero if the two seq...
vtkX3D::value
Definition: vtkX3D.h:220
vtkUnicodeString::value_type
vtkUnicodeStringValueType value_type
Definition: vtkUnicodeString.h:75
vtkUnicodeString::operator=
vtkUnicodeString & operator=(const vtkUnicodeString &)
Replaces the current sequence with a deep copy of another.
vtkUnicodeString::push_back
void push_back(value_type)
Append a Unicode character to the end of the sequence.
operator*
vtkVector< A, Size > operator*(const vtkVector< A, Size > &v1, const vtkVector< A, Size > &v2)
Definition: vtkVectorOperators.h:67
vtkUnicodeString::fold_case
vtkUnicodeString fold_case() const
Returns a copy of the current sequence, modified so that differences in case are eliminated.
operator<
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::from_utf8
static vtkUnicodeString from_utf8(const char *)
Constructs a string from a null-terminated sequence of UTF-8 encoded characters.
vtkUnicodeString::character_count
size_type character_count() const
Returns the number of characters (not bytes) in the sequence.
vtkUnicodeString::swap
void swap(vtkUnicodeString &)
Swap the sequences stored by two strings.
vtkX3D::offset
Definition: vtkX3D.h:438
vtkUnicodeString::operator+=
vtkUnicodeString & operator+=(value_type)
Append a Unicode character to the end of the sequence.
vtkUnicodeString::substr
vtkUnicodeString substr(size_type offset=0, size_type count=npos) const
Returns a subset of the current sequence that up-to 'count' characters in length, starting at charact...
vtkUnicodeString::const_iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: vtkUnicodeString.h:81
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkUnicodeString::at
value_type at(size_type offset) const
Returns the Unicode character at the given character offset within the sequence, or throws std::out_o...
vtkUnicodeString::end
const_iterator end() const
Returns a forward iterator that points just beyond the end of the sequence.
vtkUnicodeStringValueType
vtkTypeUInt32 vtkUnicodeStringValueType
Definition: vtkUnicodeString.h:58
vtkUnicodeString::utf8_str
const char * utf8_str() const
Returns the sequence as a null-terminated sequence of UTF-8 encoded characters.
vtkUnicodeString::npos
static const size_type npos
The largest representable value of size_type, used as a special-code.
Definition: vtkUnicodeString.h:205
vtkUnicodeString::utf16_str
std::vector< vtkTypeUInt16 > utf16_str() const
Returns the sequence as a collection of UTF-16 encoded characters.
operator==
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::const_iterator::reference
value_type & reference
Definition: vtkUnicodeString.h:85
vtkUnicodeString::empty
bool empty() const
Returns true if the string contains an empty sequence.
vtkX3D::string
Definition: vtkX3D.h:490
vtkUnicodeString::const_iterator
Definition: vtkUnicodeString.h:78
vtkUnicodeString::operator[]
value_type operator[](size_type offset) const
Returns the Unicode character at the given character offset within the sequence.
operator>=
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::assign
void assign(const vtkUnicodeString &value)
Replace the current sequence with another.
vtkUnicodeString::byte_count
size_type byte_count() const
Returns the number of bytes (not characters) in the sequence.
operator!=
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::size_type
std::string::size_type size_type
Definition: vtkUnicodeString.h:76
operator>
VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::append
void append(const vtkUnicodeString &value)
Append Unicode to the current sequence.
operator<=
VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkUnicodeString::is_utf8
static bool is_utf8(const char *)
Tests a sequence of bytes, returning true iff they are a valid UTF-8 sequence.
vtkSystemIncludes.h
vtkUnicodeString::begin
const_iterator begin() const
Returns a forward iterator that points at the first element of the sequence (or just beyond the end o...
vtkUnicodeString::vtkUnicodeString
vtkUnicodeString()
Constructs an empty string.
vtkUnicodeString::const_iterator::pointer
value_type * pointer
Definition: vtkUnicodeString.h:84
vtkUnicodeString::const_iterator::value_type
vtkUnicodeStringValueType value_type
Definition: vtkUnicodeString.h:82
vtkUnicodeString::clear
void clear()
Resets the string to an empty sequence.