LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::StringHelper Class Reference

#include <string_helper.h>

Classes

struct  cmpCaseInsensetive
 

Static Public Member Functions

template<typename... Args>
static std::string dim_value (std::string explicitValue, const std::string format, const Args...args)
 
template<typename... Args>
static std::string string_format (const std::string &format, Args...args)
 
static bool isBlank (const std::string str)
 
static std::string tolower (std::string data)
 

Detailed Description

Definition at line 8 of file string_helper.h.

Member Function Documentation

template<typename... Args>
static std::string lc::StringHelper::dim_value ( std::string  explicitValue,
const std::string  format,
const Args...  args 
)
inlinestatic

::string formater for dim values

Parameters
explicitValue"coord: <>" would be coord: 10.3
formatpassed to sprintf
argspassed to snprinf
Returns
std::string

Definition at line 20 of file string_helper.h.

20  {
21  /* assume we always have "<>" somewhere */
22  size_t pos = explicitValue.find("<>");
23  if (pos !=std::string::npos)
24  return explicitValue.replace(pos, 2, StringHelper::string_format(format, args...));
25 
26  /* "" */
27  if (explicitValue.empty())
28  return StringHelper::string_format(format, args...);
29 
30  if (explicitValue == " ")
31  return "";
32 
33  return explicitValue;
34  }
static std::string string_format(const std::string &format, Args...args)
Definition: string_helper.h:39
static bool lc::StringHelper::isBlank ( const std::string  str)
inlinestatic

Test if astd::string is blank, c

Definition at line 49 of file string_helper.h.

49  {
50  std::regex r("[\\s]");
51  std::string result = regex_replace(str, r, "");
52  return result.length()==0;
53  }
template<typename... Args>
static std::string lc::StringHelper::string_format ( const std::string &  format,
Args...  args 
)
inlinestatic

Copied the function from http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf

Definition at line 39 of file string_helper.h.

39  {
40  size_t size = 1 + snprintf(nullptr, 0, format.c_str(), args ...);
41  std::unique_ptr<char[]> buf(new char[size]);
42  snprintf(buf.get(), size, format.c_str(), args ...);
43  return std::string(buf.get(), buf.get() + size);
44  }
static std::string lc::StringHelper::tolower ( std::string  data)
inlinestatic

To lowercase std::string

Definition at line 78 of file string_helper.h.

78  {
79  std::transform(data.begin(), data.end(), data.begin(), ::tolower);
80  return data;
81  };
static std::string tolower(std::string data)
Definition: string_helper.h:78

The documentation for this class was generated from the following file: