tue_config
loader_functions.cpp
Go to the documentation of this file.
1 #include "loader_functions.h"
2 
3 #include <algorithm>
4 
5 namespace tue
6 {
7 namespace config
8 {
9 
10 bool strToBool(std::string s, bool& rhs)
11 {
12  static const struct {
13  std::string truename, falsename;
14  } names[] = {
15  {"y", "n"}, {"yes", "no"}, {"true", "false"}, {"on", "off"},
16  };
17 
18  std::transform(s.begin(), s.end(), s.begin(), ::tolower);
19  for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
20  if (names[i].truename == s) {
21  rhs = true;
22  return true;
23  }
24 
25  if (names[i].falsename == s) {
26  rhs = false;
27  return true;
28  }
29  }
30 
31  return false;
32 }
33 
34 }
35 
36 }
37 
std::string
tue::config::strToBool
bool strToBool(std::string s, bool &rhs)
strToBool Converts a string to a boolean of matches one of the following: y, n, yes,...
Definition: loader_functions.cpp:10
algorithm
loader_functions.h
std::transform
T transform(T... args)
std::string::begin
T begin(T... args)
std::string::end
T end(T... args)
tue
config
tue::config::ReaderWriter config
Definition: sdf_gtest.cpp:9