CARLA
StringUtil.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <boost/algorithm/string.hpp>
10 
11 namespace carla {
12 
13  class StringUtil {
14  public:
15 
16  static const char *ToConstCharPtr(const char *str) {
17  return str;
18  }
19 
20  template <typename StringT>
21  static const char *ToConstCharPtr(const StringT &str) {
22  return str.c_str();
23  }
24 
25  template <typename Range1T, typename Range2T>
26  static bool StartsWith(const Range1T &input, const Range2T &test) {
27  return boost::algorithm::istarts_with(input, test);
28  }
29 
30  template <typename Range1T, typename Range2T>
31  static bool EndsWith(const Range1T &input, const Range2T &test) {
32  return boost::algorithm::iends_with(input, test);
33  }
34 
35  template <typename WritableRangeT>
36  static void ToLower(WritableRangeT &str) {
37  boost::algorithm::to_lower(str);
38  }
39 
40  template <typename SequenceT>
41  static auto ToLowerCopy(const SequenceT &str) {
42  return boost::algorithm::to_lower_copy(str);
43  }
44 
45  template <typename WritableRangeT>
46  static void ToUpper(WritableRangeT &str) {
47  boost::algorithm::to_upper(str);
48  }
49 
50  template <typename SequenceT>
51  static auto ToUpperCopy(const SequenceT &str) {
52  return boost::algorithm::to_upper_copy(str);
53  }
54 
55  template <typename WritableRangeT>
56  static void Trim(WritableRangeT &str) {
57  boost::algorithm::trim(str);
58  }
59 
60  template <typename SequenceT>
61  static auto TrimCopy(const SequenceT &str) {
62  return boost::algorithm::trim_copy(str);
63  }
64 
65  template<typename Container, typename Range1T, typename Range2T>
66  static void Split(Container &destination, const Range1T &str, const Range2T &separators) {
67  boost::split(destination, str, boost::is_any_of(separators));
68  }
69 
70  /// Match @a str with the Unix shell-style @a wildcard_pattern.
71  static bool Match(const char *str, const char *wildcard_pattern);
72 
73  /// Match @a str with the Unix shell-style @a wildcard_pattern.
74  template <typename String1T, typename String2T>
75  static bool Match(const String1T &str, const String2T &wildcard_pattern) {
76  return Match(ToConstCharPtr(str), ToConstCharPtr(wildcard_pattern));
77  }
78  };
79 
80 } // namespace carla
static bool EndsWith(const Range1T &input, const Range2T &test)
Definition: StringUtil.h:31
static auto ToLowerCopy(const SequenceT &str)
Definition: StringUtil.h:41
static bool Match(const String1T &str, const String2T &wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
Definition: StringUtil.h:75
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
static auto TrimCopy(const SequenceT &str)
Definition: StringUtil.h:61
static void Trim(WritableRangeT &str)
Definition: StringUtil.h:56
static bool Match(const char *str, const char *wildcard_pattern)
Match str with the Unix shell-style wildcard_pattern.
Definition: StringUtil.cpp:17
static void Split(Container &destination, const Range1T &str, const Range2T &separators)
Definition: StringUtil.h:66
static const char * ToConstCharPtr(const char *str)
Definition: StringUtil.h:16
static void ToLower(WritableRangeT &str)
Definition: StringUtil.h:36
static const char * ToConstCharPtr(const StringT &str)
Definition: StringUtil.h:21
static void ToUpper(WritableRangeT &str)
Definition: StringUtil.h:46
static bool StartsWith(const Range1T &input, const Range2T &test)
Definition: StringUtil.h:26
static auto ToUpperCopy(const SequenceT &str)
Definition: StringUtil.h:51