m8

A general-purpose preprocessor for metaprogramming.


m8

/

src

/

ob

/

string.hh

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#ifndef OB_STRING_HH
#define OB_STRING_HH

#include <cstddef>

#include <string>
#include <vector>
#include <unordered_map>
#include <optional>
#include <regex>
#include <limits>
#include <utility>
#include <map>

namespace OB
{

namespace String
{

std::vector<std::string> split(std::string const& str, std::string const& delim, std::size_t size = std::numeric_limits<std::size_t>::max());

std::string plural(std::string const& str, std::size_t num);

std::string plural(std::string const& str, std::string const& end, std::size_t num);

bool assert_rx(std::string str, std::regex rx);

std::optional<std::vector<std::string>> match(std::string const& str, std::regex rx);

std::string repeat(std::string const& str, std::size_t num);

std::size_t count(std::string const& str, std::string const& val);

std::string escape(std::string str);

std::string unescape(std::string str);

std::string replace_first(std::string str, std::string const& key, std::string const& val);

std::string replace_last(std::string str, std::string const& key, std::string const& val);

std::string replace_all(std::string str, std::string const& key, std::string const& val);

std::vector<std::string> delimit(std::string const& str, std::string const& delim);

std::vector<std::string> delimit_first(std::string const& str, std::string const& delim);

std::pair<std::string, std::string> delimit_pair(std::string const& str, std::string const& delim);

std::string format(std::string str, std::unordered_map<std::string, std::string> args);

std::string xformat(std::string str, std::unordered_map<std::string, std::string> args);

std::string trim(std::string str);

std::string sanitize_html(std::string str);

std::string sanitize_sql(std::string str);

std::string sanitize_query(std::string str);

std::string file(std::string const& str);

std::string uppercase(std::string const& str);

std::string lowercase(std::string const& str);

bool starts_with(std::string const& str, std::string const& val);

bool ends_with(std::string const& str, std::string const& val);

std::vector<std::string> correct(std::string const& str, std::vector<std::string> const& lst);

std::vector<std::string> bayes(std::vector<std::string> const& list, std::string str);

std::size_t levenshtein(std::string const& lhs, std::string const& rhs,
  std::size_t const weight_insert = 1, std::size_t const weight_substitute = 1,
  std::size_t const weight_delete = 1);

std::size_t damerau_levenshtein(std::string const& lhs, std::string const& rhs,
  std::size_t const weight_insert = 1, std::size_t const weight_substitute = 1,
  std::size_t const weight_delete = 1, std::size_t const weight_transpose = 1);

std::string hex_encode(char const c);

char hex_decode(std::string const& s);

std::string url_encode(std::string const& str, bool form = false);

std::string url_decode(std::string const& str, bool form = false);

std::pair<std::string, std::string> fuzzy_time(long int const sec);

} // namespace String

} // namespace OB

#endif // OB_STRING_HH
Back to Top