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 <string>
54 #include <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 std::string::size_type size_type;
75 
77  {
78  public:
79  typedef std::bidirectional_iterator_tag iterator_category;
81  typedef std::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(std::string::const_iterator);
97  friend class vtkUnicodeString;
98  std::string::const_iterator Position;
99  };
100 
107  vtkUnicodeString(size_type count, value_type character);
110 
112 
114  static bool is_utf8(const char*);
115  static bool is_utf8(const std::string&);
117 
119 
121  static vtkUnicodeString from_utf8(const char*);
122  // Constructs a string from a half-open sequence of UTF-8 encoded characters.
123  static vtkUnicodeString from_utf8(const char* begin, const char* end);
124  // Constructs a string from a sequence of UTF-8 encoded characters.
125  static vtkUnicodeString from_utf8(const std::string&);
127 
129  static vtkUnicodeString from_utf16(const vtkTypeUInt16*);
130 
133 
136  const_iterator begin() const;
139  const_iterator end() const;
140 
143  value_type at(size_type offset) const;
147 
150  const char* utf8_str() const;
153  void utf8_str(std::string& result) const;
155  std::vector<vtkTypeUInt16> utf16_str() const;
158  void utf16_str(std::vector<vtkTypeUInt16>& result) const;
159 
161  size_type byte_count() const;
163  size_type character_count() const;
165  bool empty() const;
166 
168  static const size_type npos;
169 
174 
176  void push_back(value_type);
177 
179 
180  void append(const vtkUnicodeString& value);
181  void append(size_type count, value_type character);
184 
186 
187  void assign(const vtkUnicodeString& value);
188  void assign(size_type count, value_type character);
191 
193  void clear();
194 
201  vtkUnicodeString fold_case() const;
202 
208  int compare(const vtkUnicodeString&) const;
209 
213 
215  void swap(vtkUnicodeString&);
216 
217 private:
218  std::string Storage;
219  class back_insert_iterator;
220 };
221 
224 VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
227 VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
228 
229 #endif
230