ITK  4.4.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 
27 namespace itk
28 {
29 
44 class FancyString : public std::string
45 {
46 public:
47  FancyString();
48  FancyString( const std::string& str );
49  FancyString( const char* s );
51 
52  FancyString& operator=( const std::string& str );
53  FancyString& operator=( const char* s );
54 
56  operator const char * () const;
57 
59  // helper functions for converting a string to/from a std::vector
61 
71  template < class T >
72  FancyString& ToData( std::vector<T>& outputData, int count = -1 );
74 
79  template < class T >
80  FancyString& FromData( const std::vector<T>& inputData );
81 
83  // helper functions for converting a string to/from a itk::Array
85 
95  template < class T >
96  FancyString& ToData( Array<T>& outputData, int count = -1 );
98 
103  template < class T >
104  FancyString& FromData( const Array<T>& inputData );
105 
107  // helper functions for converting a string to/from a basic data type
109 
114  template < class T >
115  FancyString& ToData( T& outputData );
116 
121  template < class T >
122  FancyString& FromData( const T& inputData );
123 
125  // helper functions for string manipulations
127 
129  FancyString& Trim( const std::string& dislike = " \t\n\r" );
130 
132  FancyString& TrimLeft( const std::string& dislike = " \t\n\r" );
133 
135  FancyString& TrimRight( const std::string& dislike = " \t\n\r" );
136 
139 
142 
144  void Split( std::string& lpart, std::string& rpart, const std::string& delims = "=:" ) const;
145 
147  void Split( std::vector<std::string>& result, const std::string& delims = ";|" ) const;
148 
153  void Split( std::map<std::string,std::string>& result, const std::string& delims = ";|" );
154 
156  bool MatchWith( const std::string& s2, bool ignoreCase = true );
157 
159  bool StartWith( const std::string& s2, bool ignoreCase = true );
160 
162  bool EndWith( const std::string& s2, bool ignoreCase = true );
163 
165  bool ContainSub( const std::string& s2, bool ignoreCase = true );
166 }; // class FancyString
167 
168 } // namespace itk
169 
170 namespace itk
171 {
172 
174 // manipulators for FancyString (currently only one is defined)
176 
180 FancyString& operator<<( FancyString& s, void (*mf)(FancyString&) );
181 
185 void ClearContent( FancyString& input );
186 
188 // helper functions for converting a string to/from a std::vector
190 
196 template < class T >
197 FancyString& operator>>( FancyString& s, std::vector<T>& data );
198 
203 template < class T >
204 FancyString& operator<<( FancyString& s, const std::vector<T>& data );
205 
207 // helper functions for converting a string to/from a itk::Array
209 
215 template < class T >
216 FancyString& operator>>( FancyString& s, Array<T>& data );
217 
222 template < class T >
223 FancyString& operator<<( FancyString& s, const Array<T>& data );
224 
226 // helper functions for converting a string to/from a basic data type
228 
233 template < class T >
234 FancyString& operator>>( FancyString& s, T& data );
235 
240 template < class T >
241 FancyString& operator<<( FancyString& s, const T& data );
242 
243 } // namespace itk
244 
245 #ifndef ITK_MANUAL_INSTANTIATION
246 #include "itkFancyString.hxx"
247 #endif
248 
249 #endif // __itkFancyString_h
250