Krotos Modules 3
Loading...
Searching...
No Matches
krotos::utils Namespace Reference

Functions

std::string HttpDateToISO8601 (const std::string &httpDate)
 Converts a date from HTTP-Date to ISO8601 format.
 
StringArray getVersionSegments (StringRef p)
 
int getVersionAsHexIntegerFromParts (const StringArray &segments)
 
int getVersionAsHexInteger (StringRef versionString)
 
static bool compareFloats (const float &a, const float &b)
 
String ellipsizeStringToWidth (const Font &font, const String &input, const int maxWidth)
 Cuts the center out of a String to make it fit a given pixel width.
 
String convertFilePathString (const String &path)
 Converts a file path passed as a raw string, to the current platform. Has no effect if the path is already valid for the current OS. (Win + Mac only)
 
void hexStringToByteArray (const std::string &input, std::vector< unsigned char > &byteArray)
 Converts a hex string to a byte array.
 
template<class... Args>
String StringsIntoPath (Args... args)
 Joins multiple string arguments into a path string.
 

Function Documentation

◆ compareFloats()

static bool krotos::utils::compareFloats ( const float & a,
const float & b )
static

◆ convertFilePathString()

String krotos::utils::convertFilePathString ( const String & path)

Converts a file path passed as a raw string, to the current platform. Has no effect if the path is already valid for the current OS. (Win + Mac only)

Parameters
pathThe file path as a string.
Returns
The converted path.

◆ ellipsizeStringToWidth()

String krotos::utils::ellipsizeStringToWidth ( const Font & font,
const String & input,
const int maxWidth )

Cuts the center out of a String to make it fit a given pixel width.

Taking into account the kerning and character widths of the supplied Font, if the calculated input string width in pixels exceeds the supplied maxWidth, then enough characters are removed from the center of the string (and replaced with an ellipsis) to make it fit within maxWidth. The fit may be slightly short of the given max, depending on the exact width of the characters at the breaks. It will never be wider.

Parameters
fontReference to the font which will be used to render the string
inputReference to the string to be fitted
maxWidthMaximum width in pixels for the string to occupy
Returns
Reduced size string with center ellipsis.

◆ getVersionAsHexInteger()

int krotos::utils::getVersionAsHexInteger ( StringRef versionString)

Get integer version number from version string. Useful for comparing version numbers

Parameters
versionStringthe whole version string with period or comma separators e.g. 1.0.0 or 1.0
Returns
A hex int of the version number e.g. 0x65536

◆ getVersionAsHexIntegerFromParts()

int krotos::utils::getVersionAsHexIntegerFromParts ( const StringArray & versionString)

Get an integer version number from an array of version numbers

Parameters
Arrayof the version string numbers without separators e.g. "1", "0", "0"
Returns
A hex int of the version number e.g. 0x65536
See also
getVersionAsHexInteger

◆ getVersionSegments()

StringArray krotos::utils::getVersionSegments ( StringRef versionString)

Get an array of version numbers from a joined version string

Parameters
versionStringthe whole version string with period or comma separators e.g. 1.0.0
Returns
Array of the version string numbers without separators e.g. "1", "0", "0"
See also
getVersionAsHexInteger

◆ hexStringToByteArray()

void krotos::utils::hexStringToByteArray ( const std::string & input,
std::vector< unsigned char > & byteArray )

Converts a hex string to a byte array.

Parameters
inputThe hex string to convert
byteArrayA reference to the vector to write the bytes into. This is resized to the input.size() / 2.

◆ HttpDateToISO8601()

std::string krotos::utils::HttpDateToISO8601 ( const std::string & httpDate)

Converts a date from HTTP-Date to ISO8601 format.

Parameters
httpDateThe date string in http-date format
Returns
ISO8601 date string

◆ StringsIntoPath()

template<class... Args>
String krotos::utils::StringsIntoPath ( Args... args)

Joins multiple string arguments into a path string.

Takes a variable number of string arguments and joins them into a single path string, using the platform's file separator.

Template Parameters
ArgsType of the string arguments.
Parameters
argsVariable number of string arguments to join.
Returns
Joined path string.