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)
 Helper to read the bytes of a file.
 
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.
 
ARK_API std::size_t levenshteinDistance (const std::string &str1, const std::string &str2)
 Calculate the Levenshtein distance between two strings.
 

Function Documentation

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

Referenced by Ark::VM::safeRun().

◆ levenshteinDistance()

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

Calculate the Levenshtein distance between two strings.

Parameters
str1
str2
Returns
std::size_t

Definition at line 5 of file Utils.cpp.

Referenced by Ark::internal::NameResolutionPass::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

Helper to read the bytes of a file.

Parameters
namefilename
Returns
std::vector<uint8_t>

Definition at line 63 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 32 of file Utils.hpp.

Referenced by Ark::Diagnostics::helper(), Ark::Diagnostics::makeContext(), and Ark::internal::NameResolutionPass::mayBeFromPlugin().