26 #ifndef __Thea_BasicStringAlg_hpp_ 27 #define __Thea_BasicStringAlg_hpp_ 37 extern THEA_API
char const *
NEWLINE;
46 return std::string(s ? s :
"");
59 size_t pos = f.find_first_of(
"/\\", (
size_t)start);
60 return (pos == std::string::npos ? -1 : (
intx)pos);
75 start = (
intx)f.length() - 1;
77 size_t pos = f.find_last_of(
"/\\", (
size_t)start);
78 return (pos == std::string::npos ? -1 : (
intx)pos);
82 THEA_API
bool beginsWith(std::string
const & test, std::string
const & pattern);
85 THEA_API
bool endsWith(std::string
const & test, std::string
const & pattern);
92 THEA_API std::string
wordWrap(std::string
const & input,
intx num_cols,
char const * newline = NEWLINE);
95 THEA_API std::string
toUpper(std::string
const & s);
98 THEA_API std::string
toLower(std::string
const & s);
107 return std::isspace(c) != 0;
114 return (c ==
'\n') || (c ==
'\r');
121 return std::isdigit(c) != 0;
128 return std::isalpha(c) != 0;
135 return (c ==
'\\') || (c ==
'/');
142 return (c ==
'\'') || (c ==
'\"');
146 # define THEA_CHECK_PRINTF_ARGS __attribute__((__format__(__printf__, 1, 2))) 147 # define THEA_CHECK_VPRINTF_ARGS __attribute__((__format__(__printf__, 1, 0))) 148 # define THEA_CHECK_MEMBER_PRINTF_ARGS __attribute__((__format__(__printf__, 2, 3))) 149 # define THEA_CHECK_MEMBER_VPRINTF_ARGS __attribute__((__format__(__printf__, 2, 0))) 151 # define THEA_CHECK_PRINTF_ARGS 152 # define THEA_CHECK_VPRINTF_ARGS 153 # define THEA_CHECK_MEMBER_PRINTF_ARGS 154 # define THEA_CHECK_MEMBER_VPRINTF_ARGS 162 THEA_API std::string THEA_CDECL
format(
char const * fmt, ...) THEA_CHECK_PRINTF_ARGS;
170 THEA_API std::string
vformat(
char const * fmt, va_list arg_ptr) THEA_CHECK_VPRINTF_ARGS;
std::ptrdiff_t intx
A signed integer suitable for indexing a structure held in memory.
std::string toString(char const *s)
Convert a C-string to a std::string object, returning an empty string if the input is a null pointer...
bool beginsWith(std::string const &test, std::string const &pattern)
Check if the test string begins with the pattern string.
Root namespace for the Thea library.
bool isQuote(char c)
Check if a character is a quote (single or double).
bool isAlpha(char c)
Check if a character is a letter of the alphabet.
bool isWhitespace(char c)
Check if a character is a whitespace character.
bool endsWith(std::string const &test, std::string const &pattern)
Check if the test string ends with the pattern string.
std::string format(char const *fmt,...)
Produces a string from arguments in the style of printf.
std::string vformat(char const *fmt, va_list arg_ptr)
Produces a string from arguments in the style of printf, can be called with the argument list from a ...
std::string wordWrap(std::string const &input, intx num_cols, char const *newline=NEWLINE)
Produces a new string that is the input string wrapped at a certain number of columns (where the line...
intx findFirstSlash(std::string const &f, intx start=0)
Finds the index of the first '\' or '/' character, starting at index start.
std::string trimWhitespace(std::string const &s)
Strips whitespace from both ends of the string.
std::string toLower(std::string const &s)
Get the lowercase version of a string.
char const * NEWLINE
The newline character sequence for the current platform.
bool isNewline(char c)
Check if a character is a newline character.
std::string toUpper(std::string const &s)
Get the uppercase version of a string.
bool isSlash(char c)
Check if a character is a slash (forward or backward).
intx findLastSlash(std::string const &f, intx start=-1)
Finds the index of the last '\' or '/' character, starting at index start (starts at the end of the s...
bool isDigit(char c)
Check if a character is a digit.