Empirical
|
Simple functions to manipulate strings. More...
#include <functional>
#include <initializer_list>
#include <iostream>
#include <sstream>
#include <string>
#include "../base/vector.h"
#include "../meta/reflection.h"
Go to the source code of this file.
Namespaces | |
emp | |
If we are in emscripten, make sure to include the header. | |
emp::internal | |
Functions | |
static const std::string & | emp::empty_string () |
static std::string | emp::to_escaped_string (char value) |
Convert a single chararcter to one that uses a proper escape sequence (in a string) if needed. More... | |
static std::string | emp::to_escaped_string (const std::string &value) |
Convert a full string to one that uses proper escape sequences, as needed. More... | |
template<typename LIT_TYPE > | |
std::string | emp::to_literal (const LIT_TYPE &value) |
Take a value and convert it to a C++-style literal. More... | |
static std::string | emp::to_literal (char value) |
Take a char and convert it to a C++-style literal. More... | |
static std::string | emp::to_literal (const std::string &value) |
Take a string and convert it to a C++-style literal. More... | |
static std::string | emp::to_upper (std::string value) |
Convert a string to all uppercase. More... | |
static std::string | emp::to_lower (std::string value) |
Convert a string to all lowercase. More... | |
static std::string | emp::to_roman_numeral (int val, const std::string &prefix="") |
bool | emp::is_whitespace (char test_char) |
Determine if a character is whitespace. More... | |
bool | emp::is_upper_letter (char test_char) |
Determine if a character is an uppercase letter. More... | |
bool | emp::is_lower_letter (char test_char) |
Determine if a character is a lowercase letter. More... | |
bool | emp::is_letter (char test_char) |
Determine if a character is a letter of any kind. More... | |
bool | emp::is_digit (char test_char) |
Determine if a character is a digit. More... | |
bool | emp::is_alphanumeric (char test_char) |
Determine if a character is a letter or digit. More... | |
bool | emp::is_idchar (char test_char) |
Determine if a character is a letter, digit, or underscore. More... | |
static bool | emp::is_one_of (char test_char, const std::string &char_set) |
Determine if a character is in a set of characters (represented as a string) More... | |
static bool | emp::is_composed_of (const std::string &test_str, const std::string &char_set) |
Determine if a string is composed only of a set of characters (represented as a string) More... | |
bool | emp::has_whitespace (const std::string &test_str) |
Determine if there is whitespace anywhere in a string. More... | |
bool | emp::has_upper_letter (const std::string &test_str) |
Determine if there are any uppercase letters in a string. More... | |
bool | emp::has_lower_letter (const std::string &test_str) |
Determine if there are any lowercase letters in a string. More... | |
bool | emp::has_letter (const std::string &test_str) |
Determine if there are any letters in a string. More... | |
bool | emp::has_digit (const std::string &test_str) |
Determine if there are any digits in a string. More... | |
bool | emp::has_alphanumeric (const std::string &test_str) |
Determine if there are any letters or digits anywhere in a string. More... | |
bool | emp::has_idchar (const std::string &test_str) |
Determine if there are any letters, digit, or underscores anywhere in a string. More... | |
static bool | emp::has_one_of (const std::string &test_str, const std::string &char_set) |
Determine if a specified set of characters appears anywhere in a string. More... | |
bool | emp::is_valid (char test_char) |
If no functions are provided to is_valid(), always return false as base case. More... | |
template<typename... FUNS> | |
bool | emp::is_valid (char test_char, std::function< bool(char)> fun1, FUNS...funs) |
Determine if a character passes any of the test functions provided. More... | |
template<typename... FUNS> | |
static bool | emp::is_valid (const std::string &test_str, FUNS...funs) |
For a string to be valid, each character must pass at least one provided function. More... | |
static std::string | emp::string_pop_fixed (std::string &in_string, std::size_t end_pos, size_t delim_size=0) |
Pop a segment from the beginning of a string as another string, shortening original. More... | |
static std::string | emp::string_get_range (const std::string &in_string, std::size_t start_pos, std::size_t end_pos) |
Get a segment from the beginning of a string as another string, leaving original untouched. More... | |
std::string | emp::string_pop (std::string &in_string, const char delim=' ') |
std::string | emp::string_get (const std::string &in_string, const char delim, size_t start_pos=0) |
std::string | emp::string_pop (std::string &in_string, const std::string &delim_set) |
std::string | emp::string_get (const std::string &in_string, const std::string &delim_set, size_t start_pos=0) |
std::string | emp::string_pop_word (std::string &in_string) |
Remove a prefix of a string, up to the first whitespace, and return it. More... | |
std::string | emp::string_get_word (const std::string &in_string, size_t start_pos=0) |
Return a prefix of a string, up to the first whitespace (do not modify the original string) More... | |
std::string | emp::string_pop_line (std::string &in_string) |
Remove a prefix of a string, up to the first newline, and return it. More... | |
std::string | emp::string_get_line (const std::string &in_string, size_t start_pos=0) |
Return a prefix of a string, up to the first newline (do not modify the original string) More... | |
std::string | emp::left_justify (std::string &in_string) |
Remove all whitespace at the beginning of a string. Return the whitespace removed. More... | |
void | emp::right_justify (std::string &in_string) |
Remove all whitespace at the end of a string. More... | |
static void | emp::remove_chars (std::string &in_string, std::string chars) |
Remove instances of characters from file. More... | |
static void | emp::compress_whitespace (std::string &in_string) |
Every time one or more whitespace characters appear replace them with a single space. More... | |
static void | emp::remove_whitespace (std::string &in_string) |
Remove all whitespace from anywhere within a string. More... | |
static void | emp::remove_punctuation (std::string &in_string) |
Remove all characters from a string except letters, numbers, and whitespace. More... | |
static void | emp::slice (const std::string &in_string, emp::vector< std::string > &out_set, char delim='\n') |
Cut up a string based on the provided delimitor; fill them in to the provided vector. More... | |
static emp::vector< std::string > | emp::slice (const std::string &in_string, char delim='\n') |
Slice a string without passing in result vector (may be less efficient). More... | |
template<typename... ALL_TYPES> | |
std::string | emp::to_string (ALL_TYPES &&...all_values) |
template<typename T > | |
T | emp::from_string (const std::string &str) |
static void | emp::internal::_from_string (std::stringstream &) |
template<typename T , typename... Ts> | |
void | emp::internal::_from_string (std::stringstream &ss, T &arg1, Ts...extra_args) |
template<typename... Ts> | |
void | emp::from_string (const std::string &str, Ts &...args) |
The from_string() function can also take multiple args instead of a return. More... | |
template<typename T > | |
emp::vector< T > | emp::from_strings (const emp::vector< std::string > &string_v) |
Simple functions to manipulate strings.