1 #include "yaml-cpp/conversion.h"
4 ////////////////////////////////////////////////////////////////
5 // Specializations for converting a string to specific types
9 // we're not gonna mess with the mess that is all the isupper/etc. functions
10 bool IsLower(char ch
) { return 'a' <= ch
&& ch
<= 'z'; }
11 bool IsUpper(char ch
) { return 'A' <= ch
&& ch
<= 'Z'; }
12 char ToLower(char ch
) { return IsUpper(ch
) ? ch
+ 'a' - 'A' : ch
; }
14 std::string
tolower(const std::string
& str
)
17 std::transform(s
.begin(), s
.end(), s
.begin(), ToLower
);
22 bool IsEntirely(const std::string
& str
, T func
)
24 for(std::size_t i
=0;i
<str
.size();i
++)
32 // . Returns true if 'str' is:
36 bool IsFlexibleCase(const std::string
& str
)
41 if(IsEntirely(str
, IsLower
))
44 bool firstcaps
= IsUpper(str
[0]);
45 std::string rest
= str
.substr(1);
46 return firstcaps
&& (IsEntirely(rest
, IsLower
) || IsEntirely(rest
, IsUpper
));
52 bool Convert(const std::string
& input
, bool& b
)
54 // we can't use iostream bool extraction operators as they don't
55 // recognize all possible values in the table below (taken from
56 // http://yaml.org/type/bool.html)
58 std::string truename
, falsename
;
66 if(!IsFlexibleCase(input
))
69 for(unsigned i
=0;i
<sizeof(names
)/sizeof(names
[0]);i
++) {
70 if(names
[i
].truename
== tolower(input
)) {
75 if(names
[i
].falsename
== tolower(input
)) {
84 bool Convert(const std::string
& input
, _Null
& /*output*/)
86 return input
.empty() || input
== "~" || input
== "null" || input
== "Null" || input
== "NULL";