ModelViewer 0.1
Template for CPP projects
Loading...
Searching...
No Matches
model_viewer::string_helpers Namespace Reference

Functions

bool isNotSpace (const unsigned char ch) noexcept
 
void ltrim (std::string &s)
 Trim from the start (in place)
 
void rtrim (std::string &s)
 Trim from the end (in place)
 
void trim (std::string &s)
 Trim from both ends (in place)
 
std::string ltrim_copy (std::string s)
 Trim from the start (copying)
 
std::string rtrim_copy (std::string s)
 Trim from the end (copying)
 
std::string trim_copy (std::string s)
 Trim from both ends (copying)
 
std::string normalizePath (std::string p)
 Normalize a file path by removing "file://" scheme and leading slash on Windows paths.
 

Function Documentation

◆ isNotSpace()

bool model_viewer::string_helpers::isNotSpace ( const unsigned char ch)
inlinenoexcept
21 {
22 return std::isspace(ch) == 0;
23}

Referenced by ltrim().

Here is the caller graph for this function:

◆ ltrim()

void model_viewer::string_helpers::ltrim ( std::string & s)
inline

Trim from the start (in place)

Parameters
sString to trim
29 {
30 s.erase(s.begin(), std::ranges::find_if(s, isNotSpace));
31}

References isNotSpace().

Referenced by ltrim_copy(), and trim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ltrim_copy()

std::string model_viewer::string_helpers::ltrim_copy ( std::string s)
inline

Trim from the start (copying)

Parameters
sString to trim
Returns
Trimmed string
58 {
59 ltrim(s);
60 return s;
61}
void ltrim(std::string &s)
Trim from the start (in place)
Definition StringHelpers.hpp:29

References ltrim().

Here is the call graph for this function:

◆ normalizePath()

std::string model_viewer::string_helpers::normalizePath ( std::string p)
inline

Normalize a file path by removing "file://" scheme and leading slash on Windows paths.

Parameters
pPath to normalize
Returns
Normalized path
89 {
90 const std::string fileScheme = "file://";
91 if (p.rfind(fileScheme, 0) == 0) {
92 p.erase(0, fileScheme.size());
93 }
94 if (p.size() >= 3 && p[0] == '/' &&
95 std::isalpha(static_cast<unsigned char>(p[1])) && p[2] == ':') {
96 p.erase(0, 1);
97 }
98 return p;
99}

Referenced by model_viewer::loaders::ObjLoader::loadModel().

Here is the caller graph for this function:

◆ rtrim()

void model_viewer::string_helpers::rtrim ( std::string & s)
inline

Trim from the end (in place)

Parameters
sString to trim
37 {
38 s.erase(std::find_if(s.rbegin(), s.rend(),
39 [](unsigned char ch) { return !std::isspace(ch); })
40 .base(),
41 s.end());
42}

Referenced by rtrim_copy(), and trim().

Here is the caller graph for this function:

◆ rtrim_copy()

std::string model_viewer::string_helpers::rtrim_copy ( std::string s)
inline

Trim from the end (copying)

Parameters
sString to trim
Returns
Trimmed string
68 {
69 rtrim(s);
70 return s;
71}
void rtrim(std::string &s)
Trim from the end (in place)
Definition StringHelpers.hpp:37

References rtrim().

Here is the call graph for this function:

◆ trim()

void model_viewer::string_helpers::trim ( std::string & s)
inline

Trim from both ends (in place)

Parameters
sString to trim
48 {
49 rtrim(s);
50 ltrim(s);
51}

References ltrim(), and rtrim().

Referenced by trim_copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim_copy()

std::string model_viewer::string_helpers::trim_copy ( std::string s)
inline

Trim from both ends (copying)

Parameters
sString to trim
Returns
Trimmed string
78 {
79 trim(s);
80 return s;
81}
void trim(std::string &s)
Trim from both ends (in place)
Definition StringHelpers.hpp:48

References trim().

Referenced by model_viewer::material::MTLMaterial::parseColor(), model_viewer::material::MTLMaterial::parseMap(), model_viewer::material::MTLMaterial::parseMaterial(), model_viewer::loaders::ObjLoader::parseModel(), model_viewer::material::MTLMaterial::parseScalar(), and model_viewer::loaders::ObjLoader::retrieveMaterial().

Here is the call graph for this function:
Here is the caller graph for this function: