Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
f09e4497
"configs/vscode:/vscode.git/clone" did not exist on "cb080fa7debfdbc60d4f0d133b121b941260f16b"
Commit
f09e4497
authored
May 30, 2009
by
jbeder
Browse files
Set eol-style to native on all of the new files
parent
2fdf2475
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
156 deletions
+156
-156
include/conversion.h
include/conversion.h
+35
-35
src/alias.h
src/alias.h
+35
-35
src/conversion.cpp
src/conversion.cpp
+86
-86
No files found.
include/conversion.h
View file @
f09e4497
#pragma once
#include <string>
#include <sstream>
namespace
YAML
{
template
<
typename
T
>
struct
Converter
{
static
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
);
};
template
<
typename
T
>
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
)
{
return
Converter
<
T
>::
Convert
(
input
,
output
);
}
// this is the one to specialize
template
<
typename
T
>
inline
bool
Converter
<
T
>::
Convert
(
const
std
::
string
&
input
,
T
&
output
)
{
std
::
stringstream
stream
(
input
);
stream
>>
output
;
return
!
stream
.
fail
();
}
// specializations
template
<
>
inline
bool
Converter
<
std
::
string
>::
Convert
(
const
std
::
string
&
input
,
std
::
string
&
output
)
{
output
=
input
;
return
true
;
}
template
<
>
bool
Converter
<
bool
>::
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
}
#pragma once
#include <string>
#include <sstream>
namespace
YAML
{
template
<
typename
T
>
struct
Converter
{
static
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
);
};
template
<
typename
T
>
bool
Convert
(
const
std
::
string
&
input
,
T
&
output
)
{
return
Converter
<
T
>::
Convert
(
input
,
output
);
}
// this is the one to specialize
template
<
typename
T
>
inline
bool
Converter
<
T
>::
Convert
(
const
std
::
string
&
input
,
T
&
output
)
{
std
::
stringstream
stream
(
input
);
stream
>>
output
;
return
!
stream
.
fail
();
}
// specializations
template
<
>
inline
bool
Converter
<
std
::
string
>::
Convert
(
const
std
::
string
&
input
,
std
::
string
&
output
)
{
output
=
input
;
return
true
;
}
template
<
>
bool
Converter
<
bool
>::
Convert
(
const
std
::
string
&
input
,
bool
&
output
);
}
src/alias.h
View file @
f09e4497
#pragma once
#include "content.h"
namespace
YAML
{
class
Alias
:
public
Content
{
public:
Alias
(
Content
*
pNodeContent
);
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
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
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
)
const
;
virtual
bool
GetEnd
(
std
::
vector
<
Node
*>::
const_iterator
&
)
const
;
virtual
bool
GetEnd
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
)
const
;
virtual
Node
*
GetNode
(
unsigned
)
const
;
virtual
unsigned
GetSize
()
const
;
virtual
bool
IsScalar
()
const
;
virtual
bool
IsMap
()
const
;
virtual
bool
IsSequence
()
const
;
virtual
bool
GetScalar
(
std
::
string
&
s
)
const
;
virtual
int
Compare
(
Content
*
);
virtual
int
Compare
(
Scalar
*
);
virtual
int
Compare
(
Sequence
*
);
virtual
int
Compare
(
Map
*
);
private:
Content
*
m_pRef
;
};
}
#pragma once
#include "content.h"
namespace
YAML
{
class
Alias
:
public
Content
{
public:
Alias
(
Content
*
pNodeContent
);
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
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
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
)
const
;
virtual
bool
GetEnd
(
std
::
vector
<
Node
*>::
const_iterator
&
)
const
;
virtual
bool
GetEnd
(
std
::
map
<
Node
*
,
Node
*
,
ltnode
>::
const_iterator
&
)
const
;
virtual
Node
*
GetNode
(
unsigned
)
const
;
virtual
unsigned
GetSize
()
const
;
virtual
bool
IsScalar
()
const
;
virtual
bool
IsMap
()
const
;
virtual
bool
IsSequence
()
const
;
virtual
bool
GetScalar
(
std
::
string
&
s
)
const
;
virtual
int
Compare
(
Content
*
);
virtual
int
Compare
(
Scalar
*
);
virtual
int
Compare
(
Sequence
*
);
virtual
int
Compare
(
Map
*
);
private:
Content
*
m_pRef
;
};
}
src/conversion.cpp
View file @
f09e4497
#include "conversion.h"
#include <algorithm>
////////////////////////////////////////////////////////////////
// Specializations for converting a string to specific types
namespace
{
// 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
IsUpper
(
char
ch
)
{
return
'A'
<=
ch
&&
ch
<=
'Z'
;
}
char
ToLower
(
char
ch
)
{
return
IsUpper
(
ch
)
?
ch
+
'a'
-
'A'
:
ch
;
}
std
::
string
tolower
(
const
std
::
string
&
str
)
{
std
::
string
s
(
str
);
std
::
transform
(
s
.
begin
(),
s
.
end
(),
s
.
begin
(),
ToLower
);
return
s
;
}
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
unsigned
i
=
0
;
i
<
str
.
size
();
i
++
)
if
(
!
func
(
str
[
i
]))
return
false
;
return
true
;
}
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool
IsFlexibleCase
(
const
std
::
string
&
str
)
{
if
(
str
.
empty
())
return
true
;
if
(
IsEntirely
(
str
,
IsLower
))
return
true
;
bool
firstcaps
=
IsUpper
(
str
[
0
]);
std
::
string
rest
=
str
.
substr
(
1
);
return
firstcaps
&&
(
IsEntirely
(
rest
,
IsLower
)
||
IsEntirely
(
rest
,
IsUpper
));
}
}
namespace
YAML
{
template
<
>
bool
Converter
<
bool
>::
Convert
(
const
std
::
string
&
input
,
bool
&
b
)
{
// we can't use iostream bool extraction operators as they don't
// recognize all possible values in the table below (taken from
// http://yaml.org/type/bool.html)
static
const
struct
{
std
::
string
truename
,
falsename
;
}
names
[]
=
{
{
"y"
,
"n"
},
{
"yes"
,
"no"
},
{
"true"
,
"false"
},
{
"on"
,
"off"
},
};
if
(
!
IsFlexibleCase
(
input
))
return
false
;
for
(
unsigned
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
]);
i
++
)
{
if
(
names
[
i
].
truename
==
tolower
(
input
))
{
b
=
true
;
return
true
;
}
if
(
names
[
i
].
falsename
==
tolower
(
input
))
{
b
=
false
;
return
true
;
}
}
return
false
;
}
}
#include "conversion.h"
#include <algorithm>
////////////////////////////////////////////////////////////////
// Specializations for converting a string to specific types
namespace
{
// 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
IsUpper
(
char
ch
)
{
return
'A'
<=
ch
&&
ch
<=
'Z'
;
}
char
ToLower
(
char
ch
)
{
return
IsUpper
(
ch
)
?
ch
+
'a'
-
'A'
:
ch
;
}
std
::
string
tolower
(
const
std
::
string
&
str
)
{
std
::
string
s
(
str
);
std
::
transform
(
s
.
begin
(),
s
.
end
(),
s
.
begin
(),
ToLower
);
return
s
;
}
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
unsigned
i
=
0
;
i
<
str
.
size
();
i
++
)
if
(
!
func
(
str
[
i
]))
return
false
;
return
true
;
}
// IsFlexibleCase
// . Returns true if 'str' is:
// . UPPERCASE
// . lowercase
// . Capitalized
bool
IsFlexibleCase
(
const
std
::
string
&
str
)
{
if
(
str
.
empty
())
return
true
;
if
(
IsEntirely
(
str
,
IsLower
))
return
true
;
bool
firstcaps
=
IsUpper
(
str
[
0
]);
std
::
string
rest
=
str
.
substr
(
1
);
return
firstcaps
&&
(
IsEntirely
(
rest
,
IsLower
)
||
IsEntirely
(
rest
,
IsUpper
));
}
}
namespace
YAML
{
template
<
>
bool
Converter
<
bool
>::
Convert
(
const
std
::
string
&
input
,
bool
&
b
)
{
// we can't use iostream bool extraction operators as they don't
// recognize all possible values in the table below (taken from
// http://yaml.org/type/bool.html)
static
const
struct
{
std
::
string
truename
,
falsename
;
}
names
[]
=
{
{
"y"
,
"n"
},
{
"yes"
,
"no"
},
{
"true"
,
"false"
},
{
"on"
,
"off"
},
};
if
(
!
IsFlexibleCase
(
input
))
return
false
;
for
(
unsigned
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
]);
i
++
)
{
if
(
names
[
i
].
truename
==
tolower
(
input
))
{
b
=
true
;
return
true
;
}
if
(
names
[
i
].
falsename
==
tolower
(
input
))
{
b
=
false
;
return
true
;
}
}
return
false
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment