mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Set eol-style to native on all of the new files
This commit is contained in:
@@ -1,35 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Converter {
|
struct Converter {
|
||||||
static bool Convert(const std::string& input, T& output);
|
static bool Convert(const std::string& input, T& output);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Convert(const std::string& input, T& output) {
|
bool Convert(const std::string& input, T& output) {
|
||||||
return Converter<T>::Convert(input, output);
|
return Converter<T>::Convert(input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the one to specialize
|
// this is the one to specialize
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool Converter<T>::Convert(const std::string& input, T& output) {
|
inline bool Converter<T>::Convert(const std::string& input, T& output) {
|
||||||
std::stringstream stream(input);
|
std::stringstream stream(input);
|
||||||
stream >> output;
|
stream >> output;
|
||||||
return !stream.fail();
|
return !stream.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
// specializations
|
// specializations
|
||||||
template <>
|
template <>
|
||||||
inline bool Converter<std::string>::Convert(const std::string& input, std::string& output) {
|
inline bool Converter<std::string>::Convert(const std::string& input, std::string& output) {
|
||||||
output = input;
|
output = input;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool Converter<bool>::Convert(const std::string& input, bool& output);
|
bool Converter<bool>::Convert(const std::string& input, bool& output);
|
||||||
}
|
}
|
||||||
|
70
src/alias.h
70
src/alias.h
@@ -1,35 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "content.h"
|
#include "content.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
class Alias : public Content
|
class Alias : public Content
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Alias(Content *pNodeContent);
|
Alias(Content *pNodeContent);
|
||||||
|
|
||||||
virtual void Parse(Scanner* pScanner, const ParserState& state);
|
virtual void Parse(Scanner* pScanner, const ParserState& state);
|
||||||
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
virtual void Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine);
|
||||||
|
|
||||||
virtual bool GetBegin(std::vector <Node *>::const_iterator&) const;
|
virtual bool GetBegin(std::vector <Node *>::const_iterator&) const;
|
||||||
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
||||||
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const;
|
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const;
|
||||||
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const;
|
||||||
virtual Node* GetNode(unsigned) const;
|
virtual Node* GetNode(unsigned) const;
|
||||||
virtual unsigned GetSize() const;
|
virtual unsigned GetSize() const;
|
||||||
virtual bool IsScalar() const;
|
virtual bool IsScalar() const;
|
||||||
virtual bool IsMap() const;
|
virtual bool IsMap() const;
|
||||||
virtual bool IsSequence() const;
|
virtual bool IsSequence() const;
|
||||||
|
|
||||||
virtual bool GetScalar(std::string& s) const;
|
virtual bool GetScalar(std::string& s) const;
|
||||||
|
|
||||||
virtual int Compare(Content *);
|
virtual int Compare(Content *);
|
||||||
virtual int Compare(Scalar *);
|
virtual int Compare(Scalar *);
|
||||||
virtual int Compare(Sequence *);
|
virtual int Compare(Sequence *);
|
||||||
virtual int Compare(Map *);
|
virtual int Compare(Map *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Content* m_pRef;
|
Content* m_pRef;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,86 +1,86 @@
|
|||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// Specializations for converting a string to specific types
|
// Specializations for converting a string to specific types
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// we're not gonna mess with the mess that is all the isupper/etc. functions
|
// we're not gonna mess with the mess that is all the isupper/etc. functions
|
||||||
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
|
bool IsLower(char ch) { return 'a' <= ch && ch <= 'z'; }
|
||||||
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
|
bool IsUpper(char ch) { return 'A' <= ch && ch <= 'Z'; }
|
||||||
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
|
char ToLower(char ch) { return IsUpper(ch) ? ch + 'a' - 'A' : ch; }
|
||||||
|
|
||||||
std::string tolower(const std::string& str)
|
std::string tolower(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string s(str);
|
std::string s(str);
|
||||||
std::transform(s.begin(), s.end(), s.begin(), ToLower);
|
std::transform(s.begin(), s.end(), s.begin(), ToLower);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool IsEntirely(const std::string& str, T func)
|
bool IsEntirely(const std::string& str, T func)
|
||||||
{
|
{
|
||||||
for(unsigned i=0;i<str.size();i++)
|
for(unsigned i=0;i<str.size();i++)
|
||||||
if(!func(str[i]))
|
if(!func(str[i]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFlexibleCase
|
// IsFlexibleCase
|
||||||
// . Returns true if 'str' is:
|
// . Returns true if 'str' is:
|
||||||
// . UPPERCASE
|
// . UPPERCASE
|
||||||
// . lowercase
|
// . lowercase
|
||||||
// . Capitalized
|
// . Capitalized
|
||||||
bool IsFlexibleCase(const std::string& str)
|
bool IsFlexibleCase(const std::string& str)
|
||||||
{
|
{
|
||||||
if(str.empty())
|
if(str.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(IsEntirely(str, IsLower))
|
if(IsEntirely(str, IsLower))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool firstcaps = IsUpper(str[0]);
|
bool firstcaps = IsUpper(str[0]);
|
||||||
std::string rest = str.substr(1);
|
std::string rest = str.substr(1);
|
||||||
return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
|
return firstcaps && (IsEntirely(rest, IsLower) || IsEntirely(rest, IsUpper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
bool Converter<bool>::Convert(const std::string& input, bool& b)
|
bool Converter<bool>::Convert(const std::string& input, bool& b)
|
||||||
{
|
{
|
||||||
// we can't use iostream bool extraction operators as they don't
|
// we can't use iostream bool extraction operators as they don't
|
||||||
// recognize all possible values in the table below (taken from
|
// recognize all possible values in the table below (taken from
|
||||||
// http://yaml.org/type/bool.html)
|
// http://yaml.org/type/bool.html)
|
||||||
static const struct {
|
static const struct {
|
||||||
std::string truename, falsename;
|
std::string truename, falsename;
|
||||||
} names[] = {
|
} names[] = {
|
||||||
{ "y", "n" },
|
{ "y", "n" },
|
||||||
{ "yes", "no" },
|
{ "yes", "no" },
|
||||||
{ "true", "false" },
|
{ "true", "false" },
|
||||||
{ "on", "off" },
|
{ "on", "off" },
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!IsFlexibleCase(input))
|
if(!IsFlexibleCase(input))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) {
|
for(unsigned i=0;i<sizeof(names)/sizeof(names[0]);i++) {
|
||||||
if(names[i].truename == tolower(input)) {
|
if(names[i].truename == tolower(input)) {
|
||||||
b = true;
|
b = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(names[i].falsename == tolower(input)) {
|
if(names[i].falsename == tolower(input)) {
|
||||||
b = false;
|
b = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user