CppTools
Loading...
Searching...
No Matches
StrTools.hpp File Reference

Contains useful set of functions to work with std::string and to convert various types in std::string. More...

#include <string>
#include <sstream>
#include <iomanip>

Go to the source code of this file.

Functions

int CppTools::utf8_strlen (const std::string &str)
 Returns the length of the std::string type variable.
std::string CppTools::DtoStr (const double val, const int precision=2)
 Converts double to std::string with the given precision.
std::string CppTools::RemoveObsoletePrecision (std::string str)
 Removes every 0 until first non-zero value from right to left after the dot.
std::string CppTools::RemoveObsoletePrecision (const double value)
 Converts to std::string and removes every 0 until first non-zero value from right to left after the dot.
std::string CppTools::BtoStr (const bool val)
 Converts bool into std::string.

Detailed Description

Contains useful set of functions to work with std::string and to convert various types in std::string.

In order to use functions from this file libStrTools.so must be loaded

This file is a part of a project CppTools (https://github.com/Sergeyir/CppTools).

Author
Sergei Antsupov (antsu.nosp@m.pov0.nosp@m.124@g.nosp@m.mail.nosp@m..com)

Function Documentation

◆ BtoStr()

std::string CppTools::BtoStr ( const bool val)

Converts bool into std::string.

Parameters
[in]valbool variable
[out]boolalphastring variable that is either "true" or "false"

◆ DtoStr()

std::string CppTools::DtoStr ( const double val,
const int precision = 2 )

Converts double to std::string with the given precision.

Parameters
[in]valvalue to be converted
[in]precisionfloating point precision
[out]stringconverted into string value

◆ RemoveObsoletePrecision() [1/2]

std::string CppTools::RemoveObsoletePrecision ( const double value)

Converts to std::string and removes every 0 until first non-zero value from right to left after the dot.

Example: if the value is 5.240100 the function will return "5.2401"

Parameters
[in]valuevariable to be converted and "trimmed" of the obsolete precision
[out]strinput variable with obsolete precision removed

◆ RemoveObsoletePrecision() [2/2]

std::string CppTools::RemoveObsoletePrecision ( std::string str)

Removes every 0 until first non-zero value from right to left after the dot.

Example: if the value is "5.240100" the function will return "5.2401"

Parameters
[in]strstring representation of floating point variable
[out]strinput variable with obsolete precision removed

◆ utf8_strlen()

int CppTools::utf8_strlen ( const std::string & str)

Returns the length of the std::string type variable.

Parameters
[in]strstringh the length of which will be returned
[out]lengththe length of the passed string