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
22namespace 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 Lstrip(const std::string &str, const std::string &chars=" \r\n\t\v\f")
Strips leading whitespace from the given string.
static std::string Strip(const std::string &str, const std::string &chars=" \r\n\t\v\f")
Strips both leading and trailing whitespace from the given string.
Pythonesque(void)
Protected constructor; prevents class instantiation.
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.
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.
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.
virtual ~Pythonesque(void)
Destructor.
static std::string Rstrip(const std::string &str, const std::string &chars=" \r\n\t\v\f")
Strips trailing whitespace from the given string.
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 std::string Join(const BasicStringList &vec, const std::string &sep)
Joins a list of string tokens, concatenating them into a single string.
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.
Defines functionality for LibCyberRadio applications.
Definition App.h:24
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition BasicList.h:25