OpenMS
Loading...
Searching...
No Matches
StringListUtils.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg$
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13#include <OpenMS/OpenMSConfig.h>
14
15namespace OpenMS
16{
17
23 class OPENMS_DLLAPI StringListUtils
24 {
25public:
30 typedef std::vector<std::string>::iterator Iterator;
32 typedef std::vector<std::string>::const_iterator ConstIterator;
34 typedef std::vector<std::string>::reverse_iterator ReverseIterator;
36 typedef std::vector<std::string>::const_reverse_iterator ConstReverseIterator;
38
40
41
50 static Iterator searchPrefix(const Iterator& start, const Iterator& end, const std::string& text, bool trim = false);
51
61 static ConstIterator searchPrefix(const ConstIterator& start, const ConstIterator& end, const std::string& text, bool trim = false);
62
71 static ConstIterator searchPrefix(const StringList& container, const std::string& text, bool trim = false);
72
81 static Iterator searchPrefix(StringList& container, const std::string& text, bool trim = false);
82
92 static Iterator searchSuffix(const Iterator& start, const Iterator& end, const std::string& text, bool trim = false);
93
103 static ConstIterator searchSuffix(const ConstIterator& start, const ConstIterator& end, const std::string& text, bool trim = false);
104
113 static ConstIterator searchSuffix(const StringList& container, const std::string& text, bool trim = false);
114
123 static Iterator searchSuffix(StringList& container, const std::string& text, bool trim = false);
124
125
127
133 static void toUpper(StringList& sl);
134
140 static void toLower(StringList& sl);
141
142private:
144 struct TrimmableStringPredicate_
145 {
146 TrimmableStringPredicate_(const std::string& target, const bool trim) :
147 trim_(trim),
148 target_(target)
149 {
150 if (trim_) StringUtils::trim(target_);
151 }
152
153 inline std::string getValue(const std::string& value) const
154 {
155 if (trim_)
156 {
157 // trim is not a const function so we need to create a copy first
158 std::string cp = value;
159 return StringUtils::trim(cp);
160 }
161 else
162 {
163 return value;
164 }
165 }
166
167protected:
169 bool trim_;
171 std::string target_;
172 };
173
175 struct PrefixPredicate_ :
176 TrimmableStringPredicate_
177 {
178 PrefixPredicate_(const std::string& target, const bool trim) :
179 TrimmableStringPredicate_(target, trim)
180 {}
181
188 inline bool operator()(const std::string& value)
189 {
190 return StringUtils::hasPrefix(getValue(value), target_);
191 }
192
193 };
194
196 struct SuffixPredicate_ :
197 TrimmableStringPredicate_
198 {
199 SuffixPredicate_(const std::string& target, const bool trim) :
200 TrimmableStringPredicate_(target, trim)
201 {}
202
209 inline bool operator()(const std::string& value)
210 {
211 return StringUtils::hasSuffix(getValue(value), target_);
212 }
213
214 };
216
221 };
222
223} // namespace OPENMS
224
Utilities operating on lists of Strings.
Definition StringListUtils.h:24
static void toLower(StringList &sl)
Transforms all strings contained in the passed StringList to lower case.
static Iterator searchSuffix(const Iterator &start, const Iterator &end, const std::string &text, bool trim=false)
Searches for the first line that ends with text beginning at line start.
static Iterator searchPrefix(StringList &container, const std::string &text, bool trim=false)
Searches for the first line that starts with text in the StringList container.
static ConstIterator searchPrefix(const ConstIterator &start, const ConstIterator &end, const std::string &text, bool trim=false)
Searches for the first line that starts with text beginning at line start.
static ConstIterator searchSuffix(const ConstIterator &start, const ConstIterator &end, const std::string &text, bool trim=false)
Searches for the first line that ends with text beginning at line start.
static Iterator searchSuffix(StringList &container, const std::string &text, bool trim=false)
Searches for the first line that ends with text in the StringList container.
StringListUtils & operator=(StringListUtils &)
Definition StringListUtils.h:220
std::vector< std::string >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition StringListUtils.h:34
std::vector< std::string >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition StringListUtils.h:36
static void toUpper(StringList &sl)
Transforms all strings contained in the passed StringList to upper case.
static ConstIterator searchPrefix(const StringList &container, const std::string &text, bool trim=false)
Searches for the first line that starts with text in the StringList container.
std::vector< std::string >::const_iterator ConstIterator
Non-mutable iterator.
Definition StringListUtils.h:32
INTERNAL StringListUtils()
hide c'tors to avoid instantiation of utils class
Definition StringListUtils.h:218
StringListUtils(const StringListUtils &)
Definition StringListUtils.h:219
static ConstIterator searchSuffix(const StringList &container, const std::string &text, bool trim=false)
Searches for the first line that ends with text in the StringList container.
static Iterator searchPrefix(const Iterator &start, const Iterator &end, const std::string &text, bool trim=false)
Searches for the first line that starts with text beginning at line start.
std::vector< std::string >::iterator Iterator
Mutable iterator.
Definition StringListUtils.h:30
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
std::string & trim(std::string &s)
Definition StringUtils.h:560
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19