ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkStringTools.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 itkStringTools_h
20 #define itkStringTools_h
21 
22 #include <vector>
23 #include <map>
24 #include "itkArray.h"
25 #include "ITKIOXMLExport.h"
26 
27 namespace itk
28 {
29 
39 class ITKIOXML_EXPORT StringTools
40 {
41 public:
43  // helper functions for converting a string to/from a std::vector
45 
55  template < typename T >
56  static std::string& ToData( std::string& s, std::vector<T>& data, int count = -1 );
58 
63  template < typename T >
64  static std::string& FromData( std::string& s, const std::vector<T>& data );
65 
67  // helper functions for converting a string to/from a itk::Array
69 
79  template < typename T >
80  static std::string& ToData( std::string& s, Array<T>& data, int count = -1 );
82 
87  template < typename T >
88  static std::string& FromData( std::string& s, const Array<T>& data );
89 
91  // helper functions for converting a string to/from a basic data type
93 
98  template < typename T >
99  static std::string& ToData( std::string& s, T& data );
100 
105  template < typename T >
106  static std::string& FromData( std::string& s, const T& data );
107 
109  // helper functions for string manipulations
111 
113  static std::string& Trim( std::string& str, const std::string& dislike = " \t\n\r" );
114 
116  static std::string& TrimLeft( std::string& str, const std::string& dislike = " \t\n\r" );
117 
119  static std::string& TrimRight( std::string& str, const std::string& dislike = " \t\n\r" );
120 
122  static std::string& ToUpperCase( std::string& str );
123 
125  static std::string& ToLowerCase( std::string& str );
126 
128  static void Split( const std::string& s, std::string& lpart, std::string& rpart, const std::string& delims = "=:" );
129 
131  static void Split( const std::string& s, std::vector<std::string>& result, const std::string& delims = ";|" );
132 
137  static void Split( const std::string& s, std::map<std::string,std::string>& result, const std::string& delims = ";|" );
138 
140  static bool MatchWith( const std::string& s1, const std::string& s2, bool ignoreCase = true );
141 
143  static bool StartWith( const std::string& s1, const std::string& s2, bool ignoreCase = true );
144 
146  static bool EndWith( const std::string& s1, const std::string& s2, bool ignoreCase = true );
147 
149  static bool ContainSub( const std::string& s1, const std::string& s2, bool ignoreCase = true );
150 }; // class StringTools
151 
152 } // namespace itk
153 
154 #ifndef ITK_MANUAL_INSTANTIATION
155 #include "itkStringTools.hxx"
156 #endif
157 
158 #endif // itkStringTools_h
Array class with size defined at construction time.
Definition: itkArray.h:46
A set of tools to manipulate a string.