ITK  5.2.0
Insight Toolkit
itkFancyString.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkFancyString_h
20 #define itkFancyString_h
21 
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include "itkArray.h"
26 #include "ITKIOXMLExport.h"
27 
28 namespace itk
29 {
30 
45 class ITKIOXML_EXPORT FancyString
46 {
47 public:
48  FancyString();
49  FancyString(const std::string & str);
50  FancyString(const char * s);
52 
53  FancyString &
54  operator=(const std::string & str);
55  FancyString &
56  operator=(const char * s);
57 
59  operator const char *() const;
60 
62  // helper functions for converting a string to/from a std::vector
64 
74  template <typename T>
75  FancyString &
76  ToData(std::vector<T> & outputData, int count = -1);
78 
83  template <typename T>
84  FancyString &
85  FromData(const std::vector<T> & inputData);
86 
88  // helper functions for converting a string to/from a itk::Array
90 
100  template <typename T>
101  FancyString &
102  ToData(Array<T> & outputData, int count = -1);
104 
109  template <typename T>
110  FancyString &
111  FromData(const Array<T> & inputData);
112 
114  // helper functions for converting a string to/from a basic data type
116 
120  operator const std::string &() const;
121 
125  const std::string &
126  ToString() const;
127 
132  template <typename T>
133  FancyString &
134  ToData(T & outputData);
135 
140  template <typename T>
141  FancyString &
142  FromData(const T & inputData);
143 
145  // helper functions for string manipulations
147 
149  void
150  ClearContent();
151 
153  void
154  Append(const FancyString & str);
155 
157  FancyString &
158  Trim(const std::string & dislike = " \t\n\r");
159 
161  FancyString &
162  TrimLeft(const std::string & dislike = " \t\n\r");
163 
165  FancyString &
166  TrimRight(const std::string & dislike = " \t\n\r");
167 
169  FancyString &
170  ToUpperCase();
171 
173  FancyString &
174  ToLowerCase();
175 
177  void
178  Split(std::string & lpart, std::string & rpart, const std::string & delims = "=:") const;
179 
181  void
182  Split(std::vector<std::string> & result, const std::string & delims = ";|") const;
183 
188  void
189  Split(std::map<std::string, std::string> & result, const std::string & delims = ";|");
190 
192  bool
193  MatchWith(const std::string & s2, bool ignoreCase = true);
194 
196  bool
197  StartWith(const std::string & s2, bool ignoreCase = true);
198 
200  bool
201  EndWith(const std::string & s2, bool ignoreCase = true);
202 
204  bool
205  ContainSub(const std::string & s2, bool ignoreCase = true);
206 
207 private:
208  std::string m_Value;
209 
210 }; // class FancyString
211 
212 } // namespace itk
213 
215 // helper function to compare FancyString with std::string and char*
217 
218 bool ITKIOXML_EXPORT
219  operator!=(itk::FancyString & s, const std::string &);
220 bool ITKIOXML_EXPORT
221  operator!=(itk::FancyString & s, const char *);
222 bool ITKIOXML_EXPORT
224 
225 bool ITKIOXML_EXPORT
226  operator==(itk::FancyString & s, const std::string &);
227 bool ITKIOXML_EXPORT
228  operator==(itk::FancyString & s, const char *);
229 bool ITKIOXML_EXPORT
231 
232 namespace itk
233 {
235 // manipulators for FancyString (currently only one is defined)
237 
241 FancyString &
242 operator<<(FancyString & s, void (*mf)(FancyString &));
243 
247 void
248 ClearContent(FancyString & input);
249 
251 // helper functions for converting a string to/from a std::vector
253 
259 template <typename T>
260 FancyString &
261 operator>>(FancyString & s, std::vector<T> & data);
262 
267 template <typename T>
268 FancyString &
269 operator<<(FancyString & s, const std::vector<T> & data);
270 
272 // helper functions for converting a string to/from a itk::Array
274 
280 template <typename T>
281 FancyString &
282 operator>>(FancyString & s, Array<T> & data);
283 
288 template <typename T>
289 FancyString &
290 operator<<(FancyString & s, const Array<T> & data);
291 
293 // helper functions for converting a string to/from a basic data type
295 
300 template <typename T>
301 FancyString &
302 operator>>(FancyString & s, T & data);
303 
308 template <typename T>
309 FancyString &
310 operator<<(FancyString & s, const T & data);
311 
312 } // namespace itk
313 
314 #ifndef ITK_MANUAL_INSTANTIATION
315 # include "itkFancyString.hxx"
316 #endif
317 
318 #endif // itkFancyString_h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::ClearContent
void ClearContent(FancyString &input)
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &vct)
itk::FancyString::m_Value
std::string m_Value
Definition: itkFancyString.h:208
operator==
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
operator!=
bool ITKIOXML_EXPORT operator!=(itk::FancyString &s, const std::string &)
itkArray.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::FancyString
A special string type that is used to aid I/O operations in DOM-based object readers/writers.
Definition: itkFancyString.h:45