AutoPas  3.0.0
Loading...
Searching...
No Matches
Functions | Variables
autopas::utils::StringUtils Namespace Reference

Some functions to parse enums from (input-) strings. More...

Functions

std::string matchStrings (const std::vector< std::string > &haystack, std::string needle)
 Finds best match of needle in haystack.
 
std::vector< std::string > tokenize (const std::string &searchString, const std::string &delimiters)
 Splits a string by multiple delimiters.
 
std::array< double, 3 > parseArrayD3 (const std::string &string)
 Converts a string to std::array<double,3>.
 
bool parseBoolOption (const std::string &booleanOption)
 Converts a string to bool.
 
std::set< double > parseDoubles (const std::string &doubleString)
 Converts a string to a set of doubles.
 
std::unique_ptr< autopas::NumberSet< double > > parseNumberSet (const std::string &setString)
 Converts a string to a NumberSet<double>.
 

Variables

constexpr char delimiters [] = " ,;|/"
 All accepted delimiters to split input strings.
 
constexpr char delimitersRgx [] = "[\\s,;|/]"
 Regex for all delimiters to split input strings.
 
constexpr char delimitersRgxInv [] = "[^\\s,;|/]"
 Regex for all but delimiters to split input strings as regex.
 
static const std::string regexDoubleStr
 Regex for a double e.g.
 

Detailed Description

Some functions to parse enums from (input-) strings.

Function Documentation

◆ matchStrings()

std::string autopas::utils::StringUtils::matchStrings ( const std::vector< std::string > &  haystack,
std::string  needle 
)
inline

Finds best match of needle in haystack.

Needle is compared to every option in haystack and the Needleman-Wunsch score calculated. If the result is ambiguous an exception is thrown.

Parameters
haystackVector of string to match to.
needle
Returns
Best matching string.

◆ parseArrayD3()

std::array< double, 3 > autopas::utils::StringUtils::parseArrayD3 ( const std::string &  string)
inline

Converts a string to std::array<double,3>.

Allowed delimiters can be found in autopas::utils::StringUtils::delimiters.

String format: 3 doubles(or ints) separated by delimiters (examples: 10.,10.,10.)

Parameters
stringString to parse.
Returns

◆ parseBoolOption()

bool autopas::utils::StringUtils::parseBoolOption ( const std::string &  booleanOption)
inline

Converts a string to bool.

String format: on || off || enabled || disabled || true || false

Parameters
booleanOption
Returns

◆ parseDoubles()

std::set< double > autopas::utils::StringUtils::parseDoubles ( const std::string &  doubleString)
inline

Converts a string to a set of doubles.

Parameters
doubleStringString containing doubles.
Returns
Set of doubles. If no valid double was found the empty set is returned.

◆ parseNumberSet()

std::unique_ptr< autopas::NumberSet< double > > autopas::utils::StringUtils::parseNumberSet ( const std::string &  setString)
inline

Converts a string to a NumberSet<double>.

Note
Formats: NumberSetFinite [x,y,z] NumberInterval x-y
Parameters
setStringString containing the set.
Returns
NumberSet<double>. If no valid double was found the empty set is returned.

◆ tokenize()

std::vector< std::string > autopas::utils::StringUtils::tokenize ( const std::string &  searchString,
const std::string &  delimiters 
)
inline

Splits a string by multiple delimiters.

Parameters
searchString
delimiters
Returns
Set of substrings.

Variable Documentation

◆ regexDoubleStr

const std::string autopas::utils::StringUtils::regexDoubleStr
static
Initial value:
{
"[0-9]+"
"\\.?"
"[0-9]*"
"(?:"
"e"
"-?"
"[0-9]+"
")?"
}

Regex for a double e.g.

1 | 1.2 | 1.2e-3