ArkScript
A small, fast, functional and scripting language for video games
Ark::Utils Namespace Reference

Functions

bool fileExists (const std::string &name) noexcept
 Checks if a file exists.
 
std::string readFile (const std::string &name)
 Helper to read a file.
 
std::string getDirectoryFromPath (const std::string &path)
 Get the directory from a path.
 
std::string getFilenameFromPath (const std::string &path)
 Get the filename from a path.
 
std::string canonicalRelPath (const std::string &path)
 Get the canonical relative path from a path.
 
std::vector< std::string > splitString (const std::string &source, char sep)
 Cut a string into pieces, given a character separator.
 
bool isDouble (const std::string &s, double *output=nullptr)
 Checks if a string is a valid double.
 
int decPlaces (double d)
 Count the number of decimals for a double.
 
int digPlaces (double d)
 Count the number of digits for a double.
 
int levenshteinDistance (const std::string &str1, const std::string &str2)
 Calculate the Levenshtein distance between two strings.
 

Function Documentation

◆ canonicalRelPath()

std::string Ark::Utils::canonicalRelPath ( const std::string &  path)
inline

Get the canonical relative path from a path.

Parameters
path
Returns
std::string

Definition at line 85 of file Files.hpp.

Referenced by Ark::internal::Parser::checkForInclude(), Ark::internal::Parser::feed(), and Ark::State::State().

◆ decPlaces()

int Ark::Utils::decPlaces ( double  d)

Count the number of decimals for a double.

Parameters
d
Returns
int

Definition at line 5 of file Utils.cpp.

Referenced by Ark::Value::toString().

◆ digPlaces()

int Ark::Utils::digPlaces ( double  d)

Count the number of digits for a double.

Parameters
d
Returns
int

Definition at line 21 of file Utils.cpp.

Referenced by Ark::Value::toString().

◆ fileExists()

bool Ark::Utils::fileExists ( const std::string &  name)
inlinenoexcept

Checks if a file exists.

Parameters
namethe file name
Returns
true on success
false on failure

Definition at line 29 of file Files.hpp.

Referenced by Ark::State::doFile(), Ark::VM::loadPlugin(), Ark::internal::Parser::seekFile(), and Ark::State::State().

◆ getDirectoryFromPath()

std::string Ark::Utils::getDirectoryFromPath ( const std::string &  path)
inline

Get the directory from a path.

Parameters
path
Returns
std::string

Definition at line 63 of file Files.hpp.

Referenced by Ark::internal::Parser::seekFile().

◆ getFilenameFromPath()

std::string Ark::Utils::getFilenameFromPath ( const std::string &  path)
inline

Get the filename from a path.

Parameters
path
Returns
std::string

Definition at line 74 of file Files.hpp.

Referenced by Ark::State::doFile(), and Ark::internal::Parser::seekFile().

◆ isDouble()

bool Ark::Utils::isDouble ( const std::string &  s,
double *  output = nullptr 
)
inline

Checks if a string is a valid double.

Parameters
sthe string
outputoptional pointer to the output to avoid 2 conversions
Returns
true on success
false on failure

Definition at line 58 of file Utils.hpp.

Referenced by Ark::internal::Lexer::guessType(), and Ark::VM::safeRun().

◆ levenshteinDistance()

int Ark::Utils::levenshteinDistance ( const std::string &  str1,
const std::string &  str2 
)

Calculate the Levenshtein distance between two strings.

Parameters
str1
str2
Returns
int

Definition at line 33 of file Utils.cpp.

Referenced by Ark::Compiler::offerSuggestion().

◆ readFile()

std::string Ark::Utils::readFile ( const std::string &  name)
inline

Helper to read a file.

Parameters
namethe file name
Returns
std::string

Definition at line 48 of file Files.hpp.

Referenced by Ark::internal::Parser::checkForInclude(), Ark::State::compile(), main(), and Ark::internal::makeNodeBasedErrorCtx().

◆ splitString()

std::vector< std::string > Ark::Utils::splitString ( const std::string &  source,
char  sep 
)
inline

Cut a string into pieces, given a character separator.

Parameters
source
sep
Returns
std::vector<std::string>

Definition at line 34 of file Utils.hpp.

Referenced by Ark::internal::makeContext(), Ark::Compiler::mayBeFromPlugin(), Ark::State::State(), and Ark::internal::Lexer::throwTokenizingError().