Elaztek Developer Hub
Blamite Game Engine - Strings  00390.07.02.23.1947.blamite
A library containing general purpose utilities and classes for use in multiple projects.
BlamStrings::Converters Namespace Reference

Namespace containing functions to convert between various types of variables. More...

Functions

STRINGS_API std::wstring ConvertStringToWstring (std::string string)
 Converts a String to a Wide String. More...
 
STRINGS_API std::string WstringToString (std::wstring wide_string)
 Converts a Wide String to a String. More...
 
STRINGS_API bool StringToBool (std::string string)
 Converts a string to a boolean. More...
 
STRINGS_API bool HexStringToChar (std::string hex, char *character)
 Converts a hexadecimal code to its respective character. More...
 
STRINGS_API float StringToFloat (std::string string)
 Converts a string representation of a float to a float. More...
 
STRINGS_API int StringToInt (std::string string)
 Converts a string representation of an integer to an int. More...
 
STRINGS_API int64_t StringToInt64 (std::string string)
 Converts a string representation of an integer to an int64_t. More...
 
STRINGS_API double StringToDouble (std::string string)
 Converts a string representation of a double to a double. More...
 
STRINGS_API std::string BytesToString (void *bytes, int bytes_length, bool uppercase=false)
 Converts a series of bytes to a string. More...
 
STRINGS_API bool IsStringInt (std::string string)
 Checks whether or not a string is a valid representation of an integer. More...
 
STRINGS_API bool IsStringFloat (std::string string)
 Checks whether or not a string is a valid representation of a float. More...
 
STRINGS_API std::string BoolToString (bool value)
 Converts a boolean value to a string. More...
 
STRINGS_API std::string FloatToString (float value, int max_decimals=-1)
 Converts a floating-point number to a string. More...
 
STRINGS_API BlamVector2 StringToVector2 (std::string string, bool *result=nullptr)
 Converts a string to a 2D vector. More...
 
STRINGS_API BlamVector3 StringToVector3 (std::string string, bool *result=nullptr)
 Converts a string to a 3D vector. More...
 
STRINGS_API BlamVector4 StringToVector4 (std::string string, bool *result=nullptr)
 Converts a string to a 4D vector. More...
 
STRINGS_API bool HexStringToBytes (std::string hex_string, void **data, int *data_size, bool remove_terminator=true)
 Converts a hexadecimal string representation to bytes in memory. More...
 

Detailed Description

Namespace containing functions to convert between various types of variables.

Function Documentation

◆ BoolToString()

std::string BlamStrings::Converters::BoolToString ( bool  value)

Converts a boolean value to a string.

Parameters
value- The boolean value to convert.
Returns
The boolean value represented as a string. Will always be lowercase true or false.

◆ BytesToString()

std::string BlamStrings::Converters::BytesToString ( void *  bytes,
int  bytes_length,
bool  uppercase = false 
)

Converts a series of bytes to a string.

Parameters
bytes- Start address of the bytes to read.
bytes_length- The number of bytes to read.
uppercase- Whether or not any hexadecmial letters (A-F) should be uppercase or lowercase.
Returns
The string representation of the bytes.
+ Here is the caller graph for this function:

◆ ConvertStringToWstring()

std::wstring BlamStrings::Converters::ConvertStringToWstring ( std::string  string)

Converts a String to a Wide String.

Parameters
string- The string to convert.
Returns
The string as a wstring.

◆ FloatToString()

std::string BlamStrings::Converters::FloatToString ( float  value,
int  max_decimals = -1 
)

Converts a floating-point number to a string.

Parameters
value- The value to convert.
max_decimals- The amount of decimal places to display. Anything below 0 will show all decimal places, and if the amount is larger than the actual decimal value, then zeroes will be added to the end of the string to match the provided value.
Returns
The floating-point number converted to a string.
+ Here is the call graph for this function:

◆ HexStringToBytes()

bool BlamStrings::Converters::HexStringToBytes ( std::string  hex_string,
void **  data,
int *  data_size,
bool  remove_terminator = true 
)

Converts a hexadecimal string representation to bytes in memory.

This is intended to be used to convert a string representation of hexadecmial data, such as 626C616D21, into bytes in memory. In this example, the resulting data would contain the ascii text blam!.

Parameters
hex_string- The string containing the hexadecimal data representation.
data- Output parameter. This will be set to the memory address of the loaded data if the string was parsed successfully.
data_size- Output parameter. This will be set to the size of the allocated memory if the string was parsed successfully.
remove_terminator- Whether or not to automatically remove the null-terminator.
Returns
true if the data was allocated and converted successfully, otherwise returns false.
Note
If this returns true, then the calling code must handle memory deletion - as this allocates a new block of memory to load the parsed data.

◆ HexStringToChar()

bool BlamStrings::Converters::HexStringToChar ( std::string  hex,
char *  character 
)

Converts a hexadecimal code to its respective character.

This is used to evaluate a hex code representing a byte to its equivalent char.

Parameters
hex- The string containing the hexadecimal representation of a character.
character- Pointer to the char to set to the evaluated character.
Returns
true if the character was converted successfully, false if an error occurred.
+ Here is the call graph for this function:

◆ IsStringFloat()

bool BlamStrings::Converters::IsStringFloat ( std::string  string)

Checks whether or not a string is a valid representation of a float.

Parameters
string- The string to check.
Returns
true if the string represents a valid float, otherwise returns `false.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsStringInt()

bool BlamStrings::Converters::IsStringInt ( std::string  string)

Checks whether or not a string is a valid representation of an integer.

Parameters
string- The string to check.
Returns
true if the string represents a valid integer, otherwise returns `false.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StringToBool()

bool BlamStrings::Converters::StringToBool ( std::string  string)

Converts a string to a boolean.

The following will be interpreted as true:

true, t, 1, on, yes, y

The following will be interpreted as false:

false, f, 0, off, no, n

Any other value will return false and add a message to console.

Parameters
string- The string to convert.
Returns
The string evaluated to a bool.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StringToDouble()

double BlamStrings::Converters::StringToDouble ( std::string  string)

Converts a string representation of a double to a double.

Parameters
string- The string containing the double value representation.
Returns
The evaluated double value, or 0 if the value failed to convert.
+ Here is the call graph for this function:

◆ StringToFloat()

float BlamStrings::Converters::StringToFloat ( std::string  string)

Converts a string representation of a float to a float.

Parameters
string- The string containing the float value representation.
Returns
The evaluated float value, or 0.0f if the value failed to convert.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StringToInt()

int BlamStrings::Converters::StringToInt ( std::string  string)

Converts a string representation of an integer to an int.

Parameters
string- The string containing the integer value representation.
Returns
The evaluated integer value, or 0 if the value failed to convert.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StringToInt64()

int64_t BlamStrings::Converters::StringToInt64 ( std::string  string)

Converts a string representation of an integer to an int64_t.

Parameters
string- The string containing the integer value representation.
Returns
The evaluated integer value, or 0 if the value failed to convert.
+ Here is the call graph for this function:

◆ StringToVector2()

BlamVector2 BlamStrings::Converters::StringToVector2 ( std::string  string,
bool *  result = nullptr 
)

Converts a string to a 2D vector.

Parameters
string- The string to parse. Should contain all values of the vector, separated by commas.
result- If provided, this will be set to true or false depending on whether the conversion was successful. true indicates a successful conversion, whereas false indicates a failed conversion.
Returns
The converted 2D vector.
+ Here is the call graph for this function:

◆ StringToVector3()

BlamVector3 BlamStrings::Converters::StringToVector3 ( std::string  string,
bool *  result = nullptr 
)

Converts a string to a 3D vector.

Parameters
string- The string to parse. Should contain all values of the vector, separated by commas.
result- If provided, this will be set to true or false depending on whether the conversion was successful. true indicates a successful conversion, whereas false indicates a failed conversion.
Returns
The converted 3D vector.
+ Here is the call graph for this function:

◆ StringToVector4()

BlamVector4 BlamStrings::Converters::StringToVector4 ( std::string  string,
bool *  result = nullptr 
)

Converts a string to a 4D vector.

Parameters
string- The string to parse. Should contain all values of the vector, separated by commas.
result- If provided, this will be set to true or false depending on whether the conversion was successful. true indicates a successful conversion, whereas false indicates a failed conversion.
Returns
The converted 4D vector.
+ Here is the call graph for this function:

◆ WstringToString()

std::string BlamStrings::Converters::WstringToString ( std::wstring  wide_string)

Converts a Wide String to a String.

Parameters
wide_string- The wide string to convert.
Returns
The wide string as a string.
Note
If the wide string contains multi-byte characters, data loss will occur.