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
b650bc82
Commit
b650bc82
authored
Oct 05, 2019
by
Andy Maloney
Committed by
Jesse Beder
Oct 05, 2019
Browse files
Modernize: Use range-based for loops for readability (#762)
Also run clang-format on these files as requested
parent
21d75fa4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
37 deletions
+37
-37
include/yaml-cpp/node/detail/node.h
include/yaml-cpp/node/detail/node.h
+3
-4
src/convert.cpp
src/convert.cpp
+11
-8
src/emitterutils.cpp
src/emitterutils.cpp
+5
-5
src/exp.cpp
src/exp.cpp
+3
-4
src/ostream_wrapper.cpp
src/ostream_wrapper.cpp
+2
-2
src/regeximpl.h
src/regeximpl.h
+11
-12
src/token.h
src/token.h
+2
-2
No files found.
include/yaml-cpp/node/detail/node.h
View file @
b650bc82
...
...
@@ -42,9 +42,8 @@ class node {
return
;
m_pRef
->
mark_defined
();
for
(
nodes
::
iterator
it
=
m_dependencies
.
begin
();
it
!=
m_dependencies
.
end
();
++
it
)
(
*
it
)
->
mark_defined
();
for
(
node
*
dependency
:
m_dependencies
)
dependency
->
mark_defined
();
m_dependencies
.
clear
();
}
...
...
@@ -160,7 +159,7 @@ class node {
private:
shared_node_ref
m_pRef
;
using
nodes
=
std
::
set
<
node
*>
;
using
nodes
=
std
::
set
<
node
*>
;
nodes
m_dependencies
;
};
}
// namespace detail
...
...
src/convert.cpp
View file @
b650bc82
...
...
@@ -16,8 +16,8 @@ std::string tolower(const std::string& str) {
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
if
(
!
func
(
str
[
i
]
))
for
(
char
ch
:
str
)
if
(
!
func
(
ch
))
return
false
;
return
true
;
...
...
@@ -39,7 +39,7 @@ bool IsFlexibleCase(const std::string& str) {
std
::
string
rest
=
str
.
substr
(
1
);
return
firstcaps
&&
(
IsEntirely
(
rest
,
IsLower
)
||
IsEntirely
(
rest
,
IsUpper
));
}
}
}
// namespace
namespace
YAML
{
bool
convert
<
bool
>::
decode
(
const
Node
&
node
,
bool
&
rhs
)
{
...
...
@@ -52,19 +52,22 @@ bool convert<bool>::decode(const Node& node, bool& rhs) {
static
const
struct
{
std
::
string
truename
,
falsename
;
}
names
[]
=
{
{
"y"
,
"n"
},
{
"yes"
,
"no"
},
{
"true"
,
"false"
},
{
"on"
,
"off"
},
{
"y"
,
"n"
},
{
"yes"
,
"no"
},
{
"true"
,
"false"
},
{
"on"
,
"off"
},
};
if
(
!
IsFlexibleCase
(
node
.
Scalar
()))
return
false
;
for
(
unsigned
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
]);
i
++
)
{
if
(
name
s
[
i
]
.
truename
==
tolower
(
node
.
Scalar
()))
{
for
(
const
auto
&
name
:
names
)
{
if
(
name
.
truename
==
tolower
(
node
.
Scalar
()))
{
rhs
=
true
;
return
true
;
}
if
(
name
s
[
i
]
.
falsename
==
tolower
(
node
.
Scalar
()))
{
if
(
name
.
falsename
==
tolower
(
node
.
Scalar
()))
{
rhs
=
false
;
return
true
;
}
...
...
@@ -72,4 +75,4 @@ bool convert<bool>::decode(const Node& node, bool& rhs) {
return
false
;
}
}
}
// namespace YAML
src/emitterutils.cpp
View file @
b650bc82
...
...
@@ -199,11 +199,11 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
bool
IsValidSingleQuotedScalar
(
const
std
::
string
&
str
,
bool
escapeNonAscii
)
{
// TODO: check for non-printable characters?
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
str
[
i
]
)))
{
for
(
char
ch
:
str
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
false
;
}
if
(
str
[
i
]
==
'\n'
)
{
if
(
ch
==
'\n'
)
{
return
false
;
}
}
...
...
@@ -217,8 +217,8 @@ bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
}
// TODO: check for non-printable characters?
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
str
[
i
]
)))
{
for
(
char
ch
:
str
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
false
;
}
}
...
...
src/exp.cpp
View file @
b650bc82
...
...
@@ -12,8 +12,7 @@ namespace YAML {
namespace
Exp
{
unsigned
ParseHex
(
const
std
::
string
&
str
,
const
Mark
&
mark
)
{
unsigned
value
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
{
char
ch
=
str
[
i
];
for
(
char
ch
:
str
)
{
int
digit
=
0
;
if
(
'a'
<=
ch
&&
ch
<=
'f'
)
digit
=
ch
-
'a'
+
10
;
...
...
@@ -132,5 +131,5 @@ std::string Escape(Stream& in) {
std
::
stringstream
msg
;
throw
ParserException
(
in
.
mark
(),
std
::
string
(
ErrorMsg
::
INVALID_ESCAPE
)
+
ch
);
}
}
}
}
// namespace Exp
}
// namespace YAML
src/ostream_wrapper.cpp
View file @
b650bc82
...
...
@@ -31,8 +31,8 @@ void ostream_wrapper::write(const std::string& str) {
std
::
copy
(
str
.
begin
(),
str
.
end
(),
m_buffer
.
begin
()
+
m_pos
);
}
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
{
update_pos
(
str
[
i
]
);
for
(
char
ch
:
str
)
{
update_pos
(
ch
);
}
}
...
...
src/regeximpl.h
View file @
b650bc82
...
...
@@ -8,8 +8,8 @@
#endif
#include "stream.h"
#include "stringsource.h"
#include "streamcharsource.h"
#include "stringsource.h"
namespace
YAML
{
// query matches
...
...
@@ -106,9 +106,8 @@ inline int RegEx::MatchOpEmpty(const Source& source) const {
template
<
>
inline
int
RegEx
::
MatchOpEmpty
<
StringCharSource
>
(
const
StringCharSource
&
source
)
const
{
return
!
source
?
0
:
-
1
;
// the empty regex only is successful on the empty string
return
!
source
?
0
:
-
1
;
// the empty regex only is successful on the empty
// string
}
// MatchOperator
...
...
@@ -130,8 +129,8 @@ inline int RegEx::MatchOpRange(const Source& source) const {
// OrOperator
template
<
typename
Source
>
inline
int
RegEx
::
MatchOpOr
(
const
Source
&
source
)
const
{
for
(
std
::
size_t
i
=
0
;
i
<
m_params
.
size
();
i
++
)
{
int
n
=
m_
param
s
[
i
]
.
MatchUnchecked
(
source
);
for
(
const
RegEx
&
param
:
m_params
)
{
int
n
=
param
.
MatchUnchecked
(
source
);
if
(
n
>=
0
)
return
n
;
}
...
...
@@ -169,11 +168,11 @@ inline int RegEx::MatchOpNot(const Source& source) const {
template
<
typename
Source
>
inline
int
RegEx
::
MatchOpSeq
(
const
Source
&
source
)
const
{
int
offset
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
m_params
.
size
();
i
++
)
{
int
n
=
m_
param
s
[
i
]
.
Match
(
source
+
offset
);
// note Match, not
// MatchUnchecked because we
// need to check validity after
// the offset
for
(
const
RegEx
&
param
:
m_params
)
{
int
n
=
param
.
Match
(
source
+
offset
);
// note Match, not
// MatchUnchecked because we
// need to check validity after
// the offset
if
(
n
==
-
1
)
return
-
1
;
offset
+=
n
;
...
...
@@ -181,6 +180,6 @@ inline int RegEx::MatchOpSeq(const Source& source) const {
return
offset
;
}
}
}
// namespace YAML
#endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/token.h
View file @
b650bc82
...
...
@@ -53,8 +53,8 @@ struct Token {
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Token
&
token
)
{
out
<<
TokenNames
[
token
.
type
]
<<
std
::
string
(
": "
)
<<
token
.
value
;
for
(
std
::
size_t
i
=
0
;
i
<
token
.
params
.
size
();
i
++
)
out
<<
std
::
string
(
" "
)
<<
token
.
param
s
[
i
]
;
for
(
const
std
::
string
&
param
:
token
.
params
)
out
<<
std
::
string
(
" "
)
<<
param
;
return
out
;
}
...
...
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