libcyberradio  22.01.24
Pythonesque.h
1 /***************************************************************************
2  * \file Pythonesque.h
3  *
4  * \brief Provides string utility functions that mimic string methods from
5  * Python.
6  *
7  * \author DA
8  * \copyright Copyright (c) 2015-2021 CyberRadio Solutions, Inc.
9  *
10  */
11 
12 #ifndef INCLUDED_LIBCYBERRADIO_PYTHONESQUE_H
13 #define INCLUDED_LIBCYBERRADIO_PYTHONESQUE_H
14 
15 #include <string>
16 #include <limits.h>
17 #include <LibCyberRadio/Common/BasicList.h>
18 
22 namespace LibCyberRadio
23 {
24  // Define an iterator for such a list
25  typedef BasicStringList::iterator BasicStringListIterator;
26 
27 
35  {
36  protected:
40  Pythonesque(void);
41 
42  public:
46  virtual ~Pythonesque(void);
47 
57  static std::string Lstrip(const std::string& str, const std::string& chars = " \r\n\t\v\f");
58 
68  static std::string Rstrip(const std::string& str, const std::string& chars = " \r\n\t\v\f");
69 
79  static std::string Strip(const std::string& str, const std::string& chars = " \r\n\t\v\f");
80 
94  static std::string Replace(const std::string& str, const std::string &oldstr, const std::string& newstr,
95  int count = INT_MAX);
96 
110  static BasicStringList Split(const std::string& str, const std::string& sep,
111  int maxsplit = INT_MAX);
112 
122  static std::string Join(const BasicStringList& vec, const std::string& sep);
123 
137  static bool Startswith(const std::string& str, const std::string& prefix, int start = 0, int end = INT_MAX);
138 
152  static bool Endswith(const std::string& str, const std::string& suffix, int start = 0, int end = INT_MAX);
153 
162  static std::string Basename(const std::string& path);
163 
164  };
165 
166 }
167 
168 #endif /* INCLUDED_LIBCYBERRADIO_PYTHONESQUE_H */
static std::string Rstrip(const std::string &str, const std::string &chars=" \\\)
Strips trailing whitespace from the given string.
Definition: Pythonesque.cpp:41
static std::string Strip(const std::string &str, const std::string &chars=" \\\)
Strips both leading and trailing whitespace from the given string.
Definition: Pythonesque.cpp:57
virtual ~Pythonesque(void)
Destructor.
Definition: Pythonesque.cpp:21
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
Definition: Pythonesque.cpp:62
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
Definition: Pythonesque.cpp:77
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition: BasicList.h:25
Pythonesque(void)
Protected constructor; prevents class instantiation.
Definition: Pythonesque.cpp:17
static bool Startswith(const std::string &str, const std::string &prefix, int start=0, int end=INT_MAX)
Determines if the given string starts with the specified prefix.
static bool Endswith(const std::string &str, const std::string &suffix, int start=0, int end=INT_MAX)
Determines if the given string ends with the specified suffix.
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
static std::string Lstrip(const std::string &str, const std::string &chars=" \\\)
Strips leading whitespace from the given string.
Definition: Pythonesque.cpp:25
static std::string Basename(const std::string &path)
Gets the base name (the file name itself, without leading path components) from the given file path...
Provides string utility functions that mimic string methods from Python.
Definition: Pythonesque.h:34
static std::string Join(const BasicStringList &vec, const std::string &sep)
Joins a list of string tokens, concatenating them into a single string.
Definition: Pythonesque.cpp:98