libcyberradio  22.01.24
Pythonesque Class Reference

Provides string utility functions that mimic string methods from Python. More...

#include <Pythonesque.h>

Public Member Functions

virtual ~Pythonesque (void)
 Destructor.
 

Static Public Member Functions

static std::string Lstrip (const std::string &str, const std::string &chars=" \\\)
 Strips leading whitespace from the given string. More...
 
static std::string Rstrip (const std::string &str, const std::string &chars=" \\\)
 Strips trailing whitespace from the given string. More...
 
static std::string Strip (const std::string &str, const std::string &chars=" \\\)
 Strips both leading and trailing whitespace from the given string. More...
 
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. More...
 
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. More...
 
static std::string Join (const BasicStringList &vec, const std::string &sep)
 Joins a list of string tokens, concatenating them into a single string. More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Member Functions

 Pythonesque (void)
 Protected constructor; prevents class instantiation.
 

Detailed Description

Provides string utility functions that mimic string methods from Python.

Note
All methods of this class are static methods.

Definition at line 34 of file Pythonesque.h.

Member Function Documentation

◆ Basename()

std::string Basename ( const std::string &  path)
static

Gets the base name (the file name itself, without leading path components) from the given file path.

Parameters
pathThe full path name of the given file.
Returns
A string containing the base name.

Definition at line 133 of file Pythonesque.cpp.

◆ Endswith()

bool Endswith ( const std::string &  str,
const std::string &  suffix,
int  start = 0,
int  end = INT_MAX 
)
static

Determines if the given string ends with the specified suffix.

Parameters
strThe original string.
suffixThe suffix string to look for.
startThe position at which to start looking for the suffix. 0 indicates the beginning. If not given, 0 is assumed.
endThe position at which to stop looking for the suffix. If not given, the end of the string is assumed.
Returns
True if the suffix is found, false otherwise.

Definition at line 121 of file Pythonesque.cpp.

◆ Join()

std::string Join ( const BasicStringList vec,
const std::string &  sep 
)
static

Joins a list of string tokens, concatenating them into a single string.

Parameters
vecThe list of string tokens to concatenate.
sepThe separator that delimits tokens within the string.
Returns
A string with the tokens joined together.

Definition at line 98 of file Pythonesque.cpp.

◆ Lstrip()

std::string Lstrip ( const std::string &  str,
const std::string &  chars = " \r\n\t\v\f" 
)
static

Strips leading whitespace from the given string.

Parameters
strThe original string.
charsThe list of whitespace characters to strip. If not specified, strip all whitespace characters.
Returns
A string with the leading whitespace stripped.

Definition at line 25 of file Pythonesque.cpp.

◆ Replace()

std::string Replace ( const std::string &  str,
const std::string &  oldstr,
const std::string &  newstr,
int  count = INT_MAX 
)
static

Replaces occurrences of one substring with another within the given string.

Parameters
strThe original string.
oldstrThe substring to be replaced.
newstrThe substring doing the replacing.
countIf specified, only replace the first <count> occurrences. If not specified, replace all occurrences.
Returns
A string with the replacements made.

Definition at line 62 of file Pythonesque.cpp.

◆ Rstrip()

std::string Rstrip ( const std::string &  str,
const std::string &  chars = " \r\n\t\v\f" 
)
static

Strips trailing whitespace from the given string.

Parameters
strThe original string.
charsThe list of whitespace characters to strip. If not specified, strip all whitespace characters.
Returns
A string with the trailing whitespace stripped.

Definition at line 41 of file Pythonesque.cpp.

◆ Split()

BasicStringList Split ( const std::string &  str,
const std::string &  sep,
int  maxsplit = INT_MAX 
)
static

Splits the given string into a list of string tokens.

Parameters
strThe original string.
sepThe separator that delimits tokens within the string.
maxsplitIf specified, perform only <maxsplit> splits. In this case, the resulting token list will contain at most <maxsplit+1> elements; the last element will be the unsplit portion of the string. If not specified, perform all possible splits.
Returns
A vector of string tokens.

Definition at line 77 of file Pythonesque.cpp.

◆ Startswith()

bool Startswith ( const std::string &  str,
const std::string &  prefix,
int  start = 0,
int  end = INT_MAX 
)
static

Determines if the given string starts with the specified prefix.

Parameters
strThe original string.
prefixThe prefix string to look for.
startThe position at which to start looking for the prefix. 0 indicates the beginning. If not given, 0 is assumed.
endThe position at which to stop looking for the prefix. If not given, the end of the string is assumed.
Returns
True if the prefix is found, false otherwise.

Definition at line 109 of file Pythonesque.cpp.

◆ Strip()

std::string Strip ( const std::string &  str,
const std::string &  chars = " \r\n\t\v\f" 
)
static

Strips both leading and trailing whitespace from the given string.

Parameters
strThe original string.
charsThe list of whitespace characters to strip. If not specified, strip all whitespace characters.
Returns
A string with the leading and trailing whitespace stripped.

Definition at line 57 of file Pythonesque.cpp.


The documentation for this class was generated from the following files: