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::vector< uint8_t > readFileAsBytes (const std::string &name)
 
std::string canonicalRelPath (const std::string &path)
 Get the canonical relative path from a path.
 
std::vector< std::string > splitString (const std::string &source, const 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 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.

◆ 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::State::feed(), and Ark::VM::loadPlugin().

◆ 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 54 of file Utils.hpp.

Referenced by 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 5 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::Welder::computeASTFromFile(), Ark::Diagnostics::generate(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::ImportSolver::parseImport(), and Formatter::run().

◆ readFileAsBytes()

std::vector< uint8_t > Ark::Utils::readFileAsBytes ( const std::string &  name)
inline

Definition at line 58 of file Files.hpp.

Referenced by Ark::State::doFile(), and Ark::State::feed().

◆ splitString()

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

Cut a string into pieces, given a character separator.

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

Definition at line 30 of file Utils.hpp.

Referenced by Ark::Diagnostics::makeContext(), and Ark::Compiler::mayBeFromPlugin().