philsupertramp/game-math
Loading...
Searching...
No Matches
Functions
format.h File Reference
#include <cstdarg>
#include <regex>
#include <sstream>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

std::string format (const char *fmt,...)
 
std::string strip (const std::string &in)
 
template<typename Out >
void split (const std::string &s, char delim, Out result)
 
std::vector< std::string > split (const std::string &s, char delim)
 
template<typename Out >
void split (const std::string &s, Out result)
 
std::vector< std::string > split (const std::string &s)
 
std::vector< std::string > split_by_regex (const std::string &s, const std::regex &regex)
 

Detailed Description

Missing string manipulations.

This header file contains essential methods to manipulate strings.

Function Documentation

◆ format()

std::string format ( const char *  fmt,
  ... 
)
inline

missing string printf this is safe and convenient but not exactly efficient

Parameters
fmtstring to be formatted
...variable amount of parameters
Returns
formatted string
Examples
TestFormat.cpp.

◆ split() [1/4]

std::vector< std::string > split ( const std::string &  s)

Helper method to simplify call to split

Parameters
sstring to split
Returns
split vector of strings

◆ split() [2/4]

std::vector< std::string > split ( const std::string &  s,
char  delim 
)

Helper method to simplify call to split

Parameters
sstring to split
delimcharacter to split by
Returns
vector of strings split' by delim

◆ split() [3/4]

template<typename Out >
void split ( const std::string &  s,
char  delim,
Out  result 
)

from https://stackoverflow.com/a/236803

splits s into result by delim

Template Parameters
Out
Parameters
s
delim
result
Examples
TestFormat.cpp.

◆ split() [4/4]

template<typename Out >
void split ( const std::string &  s,
Out  result 
)

Split after each character

Template Parameters
Outcontainer type to write to
Parameters
sstring to split
resultcontainer to write results in

◆ split_by_regex()

std::vector< std::string > split_by_regex ( const std::string &  s,
const std::regex &  regex 
)

◆ strip()

std::string strip ( const std::string &  in)

Strips whitespaces of a string

Parameters
instring which may contain whitespaces
Returns
input string without whitespaces
Examples
TestFormat.cpp.