Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
StringListUtils.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_DATASTRUCTURES_STRINGLISTUTILS_H
36 #define OPENMS_DATASTRUCTURES_STRINGLISTUTILS_H
37 
40 #include <OpenMS/OpenMSConfig.h>
41 
42 class QStringList;
43 
44 namespace OpenMS
45 {
46 
52  class OPENMS_DLLAPI StringListUtils
53  {
54 public:
58  typedef std::vector<String>::iterator Iterator;
61  typedef std::vector<String>::const_iterator ConstIterator;
63  typedef std::vector<String>::reverse_iterator ReverseIterator;
65  typedef std::vector<String>::const_reverse_iterator ConstReverseIterator;
67 
69  static StringList fromQStringList(const QStringList& rhs);
70 
72 
73 
82  static Iterator searchPrefix(const Iterator& start, const Iterator& end, const String& text, bool trim = false);
83 
93  static ConstIterator searchPrefix(const ConstIterator& start, const ConstIterator& end, const String& text, bool trim = false);
94 
103  static ConstIterator searchPrefix(const StringList& container, const String& text, bool trim = false);
104 
113  static Iterator searchPrefix(StringList& container, const String& text, bool trim = false);
114 
124  static Iterator searchSuffix(const Iterator& start, const Iterator& end, const String& text, bool trim = false);
125 
135  static ConstIterator searchSuffix(const ConstIterator& start, const ConstIterator& end, const String& text, bool trim = false);
136 
145  static ConstIterator searchSuffix(const StringList& container, const String& text, bool trim = false);
146 
155  static Iterator searchSuffix(StringList& container, const String& text, bool trim = false);
156 
157 
159 
165  static void toUpper(StringList& sl);
166 
172  static void toLower(StringList& sl);
173 
174 private:
176  struct TrimmableStringPredicate_
177  {
178  TrimmableStringPredicate_(const String& target, const bool trim) :
179  trim_(trim),
180  target_(target)
181  {
182  if (trim_) target_.trim();
183  }
184 
185  inline String getValue(const String& value)
186  {
187  if (trim_)
188  {
189  // trim is not a const function so we need to create a copy first
190  String cp = value;
191  return cp.trim();
192  }
193  else
194  {
195  return value;
196  }
197  }
198 
199 protected:
201  bool trim_;
203  String target_;
204  };
205 
207  struct PrefixPredicate_ :
208  TrimmableStringPredicate_
209  {
210  PrefixPredicate_(const String& target, const bool trim) :
211  TrimmableStringPredicate_(target, trim)
212  {}
213 
220  inline bool operator()(const String& value)
221  {
222  return getValue(value).hasPrefix(target_);
223  }
224 
225  };
226 
228  struct SuffixPredicate_ :
229  TrimmableStringPredicate_
230  {
231  SuffixPredicate_(const String& target, const bool trim) :
232  TrimmableStringPredicate_(target, trim)
233  {}
234 
241  inline bool operator()(const String& value)
242  {
243  return getValue(value).hasSuffix(target_);
244  }
245 
246  };
248 
253  };
254 
255 } // namespace OPENMS
256 
257 #endif // OPENMS_DATASTRUCTURES_STRINGLISTUTILS_H
A more convenient string class.
Definition: String.h:57
StringListUtils(const StringListUtils &)
Definition: StringListUtils.h:251
std::vector< String >::iterator Iterator
Mutable iterator.
Definition: StringListUtils.h:59
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: StringListUtils.h:61
std::vector< String >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: StringListUtils.h:63
Utilities operating on lists of Strings.
Definition: StringListUtils.h:52
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
StringListUtils & operator=(StringListUtils &)
Definition: StringListUtils.h:252
INTERNAL StringListUtils()
hide c&#39;tors to avoid instantiation of utils class
Definition: StringListUtils.h:250
std::vector< String >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: StringListUtils.h:65

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:04 using doxygen 1.8.13