ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkFancyString.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 : public std::string
46 {
47 public:
48  FancyString();
49  FancyString( const std::string& str );
50  FancyString( const char* s );
52 
53  FancyString& operator=( const std::string& str );
54  FancyString& operator=( const char* s );
55 
57  operator const char * () const;
58 
60  // helper functions for converting a string to/from a std::vector
62 
72  template < typename T >
73  FancyString& ToData( std::vector<T>& outputData, int count = -1 );
75 
80  template < typename T >
81  FancyString& FromData( const std::vector<T>& inputData );
82 
84  // helper functions for converting a string to/from a itk::Array
86 
96  template < typename T >
97  FancyString& ToData( Array<T>& outputData, int count = -1 );
99 
104  template < typename T >
105  FancyString& FromData( const Array<T>& inputData );
106 
108  // helper functions for converting a string to/from a basic data type
110 
115  template < typename T >
116  FancyString& ToData( T& outputData );
117 
122  template < typename T >
123  FancyString& FromData( const T& inputData );
124 
126  // helper functions for string manipulations
128 
130  FancyString& Trim( const std::string& dislike = " \t\n\r" );
131 
133  FancyString& TrimLeft( const std::string& dislike = " \t\n\r" );
134 
136  FancyString& TrimRight( const std::string& dislike = " \t\n\r" );
137 
139  FancyString& ToUpperCase();
140 
142  FancyString& ToLowerCase();
143 
145  void Split( std::string& lpart, std::string& rpart, const std::string& delims = "=:" ) const;
146 
148  void Split( std::vector<std::string>& result, const std::string& delims = ";|" ) const;
149 
154  void Split( std::map<std::string,std::string>& result, const std::string& delims = ";|" );
155 
157  bool MatchWith( const std::string& s2, bool ignoreCase = true );
158 
160  bool StartWith( const std::string& s2, bool ignoreCase = true );
161 
163  bool EndWith( const std::string& s2, bool ignoreCase = true );
164 
166  bool ContainSub( const std::string& s2, bool ignoreCase = true );
167 }; // class FancyString
168 
169 } // namespace itk
170 
171 namespace itk
172 {
173 
175 // manipulators for FancyString (currently only one is defined)
177 
181 FancyString& operator<<( FancyString& s, void (*mf)(FancyString&) );
182 
186 void ClearContent( FancyString& input );
187 
189 // helper functions for converting a string to/from a std::vector
191 
197 template < typename T >
198 FancyString& operator>>( FancyString& s, std::vector<T>& data );
199 
204 template < typename T >
205 FancyString& operator<<( FancyString& s, const std::vector<T>& data );
206 
208 // helper functions for converting a string to/from a itk::Array
210 
216 template < typename T >
217 FancyString& operator>>( FancyString& s, Array<T>& data );
218 
223 template < typename T >
224 FancyString& operator<<( FancyString& s, const Array<T>& data );
225 
227 // helper functions for converting a string to/from a basic data type
229 
234 template < typename T >
235 FancyString& operator>>( FancyString& s, T& data );
236 
241 template < typename T >
242 FancyString& operator<<( FancyString& s, const T& data );
243 
244 } // namespace itk
245 
246 #ifndef ITK_MANUAL_INSTANTIATION
247 #include "itkFancyString.hxx"
248 #endif
249 
250 #endif // itkFancyString_h
Array class with size defined at construction time.
Definition: itkArray.h:50
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
void ClearContent(FancyString &input)
A special string type that is used to aid I/O operations in DOM-based object readers/writers.