Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
41001d1b
Unverified
Commit
41001d1b
authored
Jun 15, 2020
by
Rosen Penev
Committed by
GitHub
Jun 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manual algorithm conversions (#891)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
parent
a808c1f4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
62 deletions
+54
-62
include/yaml-cpp/node/convert.h
+14
-21
include/yaml-cpp/node/detail/impl.h
+22
-16
src/convert.cpp
+1
-5
src/emitterutils.cpp
+8
-15
src/node_data.cpp
+9
-5
No files found.
include/yaml-cpp/node/convert.h
View file @
41001d1b
...
...
@@ -225,9 +225,8 @@ template <typename K, typename V, typename C, typename A>
struct
convert
<
std
::
map
<
K
,
V
,
C
,
A
>>
{
static
Node
encode
(
const
std
::
map
<
K
,
V
,
C
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Map
);
for
(
typename
std
::
map
<
K
,
V
,
C
,
A
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
node
.
force_insert
(
it
->
first
,
it
->
second
);
for
(
const
auto
&
it
:
rhs
)
node
.
force_insert
(
it
.
first
,
it
.
second
);
return
node
;
}
...
...
@@ -236,12 +235,12 @@ struct convert<std::map<K, V, C, A>> {
return
false
;
rhs
.
clear
();
for
(
const
_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
auto
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs
[
it
->
first
.
template
as
<
K
>
()]
=
it
->
second
.
template
as
<
V
>
();
rhs
[
it
.
first
.
template
as
<
K
>
()]
=
it
.
second
.
template
as
<
V
>
();
#else
rhs
[
it
->
first
.
as
<
K
>
()]
=
it
->
second
.
as
<
V
>
();
rhs
[
it
.
first
.
as
<
K
>
()]
=
it
.
second
.
as
<
V
>
();
#endif
return
true
;
}
...
...
@@ -252,9 +251,7 @@ template <typename T, typename A>
struct
convert
<
std
::
vector
<
T
,
A
>>
{
static
Node
encode
(
const
std
::
vector
<
T
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
for
(
typename
std
::
vector
<
T
,
A
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
node
.
push_back
(
*
it
);
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
return
node
;
}
...
...
@@ -263,12 +260,12 @@ struct convert<std::vector<T, A>> {
return
false
;
rhs
.
clear
();
for
(
const
_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
auto
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs
.
push_back
(
it
->
template
as
<
T
>
());
rhs
.
push_back
(
it
.
template
as
<
T
>
());
#else
rhs
.
push_back
(
it
->
as
<
T
>
());
rhs
.
push_back
(
it
.
as
<
T
>
());
#endif
return
true
;
}
...
...
@@ -279,9 +276,7 @@ template <typename T, typename A>
struct
convert
<
std
::
list
<
T
,
A
>>
{
static
Node
encode
(
const
std
::
list
<
T
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
for
(
typename
std
::
list
<
T
,
A
>::
const_iterator
it
=
rhs
.
begin
();
it
!=
rhs
.
end
();
++
it
)
node
.
push_back
(
*
it
);
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
return
node
;
}
...
...
@@ -290,12 +285,12 @@ struct convert<std::list<T,A>> {
return
false
;
rhs
.
clear
();
for
(
const
_iterator
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
auto
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs
.
push_back
(
it
->
template
as
<
T
>
());
rhs
.
push_back
(
it
.
template
as
<
T
>
());
#else
rhs
.
push_back
(
it
->
as
<
T
>
());
rhs
.
push_back
(
it
.
as
<
T
>
());
#endif
return
true
;
}
...
...
@@ -306,9 +301,7 @@ template <typename T, std::size_t N>
struct
convert
<
std
::
array
<
T
,
N
>>
{
static
Node
encode
(
const
std
::
array
<
T
,
N
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
for
(
const
auto
&
element
:
rhs
)
{
node
.
push_back
(
element
);
}
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
return
node
;
}
...
...
include/yaml-cpp/node/detail/impl.h
View file @
41001d1b
...
...
@@ -9,6 +9,8 @@
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/node/detail/node_data.h"
#include <algorithm>
#include <type_traits>
namespace
YAML
{
...
...
@@ -125,13 +127,11 @@ inline node* node_data::get(const Key& key,
throw
BadSubscript
(
m_mark
,
key
);
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
it
->
first
->
equals
(
key
,
pMemory
))
{
return
it
->
second
;
}
}
auto
it
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
return
m
.
first
->
equals
(
key
,
pMemory
);
});
return
nullptr
;
return
it
!=
m_map
.
end
()
?
it
->
second
:
nullptr
;
}
template
<
typename
Key
>
...
...
@@ -153,10 +153,12 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
throw
BadSubscript
(
m_mark
,
key
);
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
it
->
first
->
equals
(
key
,
pMemory
))
{
return
*
it
->
second
;
}
auto
it
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
return
m
.
first
->
equals
(
key
,
pMemory
);
});
if
(
it
!=
m_map
.
end
())
{
return
it
->
second
;
}
node
&
k
=
convert_to_node
(
key
,
pMemory
);
...
...
@@ -169,7 +171,9 @@ template <typename Key>
inline
bool
node_data
::
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
if
(
m_type
==
NodeType
::
Sequence
)
{
return
remove_idx
<
Key
>::
remove
(
m_sequence
,
key
,
m_seqSize
);
}
else
if
(
m_type
==
NodeType
::
Map
)
{
}
if
(
m_type
==
NodeType
::
Map
)
{
kv_pairs
::
iterator
it
=
m_undefinedPairs
.
begin
();
while
(
it
!=
m_undefinedPairs
.
end
())
{
kv_pairs
::
iterator
jt
=
std
::
next
(
it
);
...
...
@@ -179,11 +183,13 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
it
=
jt
;
}
for
(
node_map
::
iterator
iter
=
m_map
.
begin
();
iter
!=
m_map
.
end
();
++
iter
)
{
if
(
iter
->
first
->
equals
(
key
,
pMemory
))
{
m_map
.
erase
(
iter
);
return
true
;
}
auto
iter
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
return
m
.
first
->
equals
(
key
,
pMemory
);
});
if
(
iter
!=
m_map
.
end
())
{
m_map
.
erase
(
iter
);
return
true
;
}
}
...
...
src/convert.cpp
View file @
41001d1b
...
...
@@ -16,11 +16,7 @@ std::string tolower(const std::string& str) {
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
char
ch
:
str
)
if
(
!
func
(
ch
))
return
false
;
return
true
;
return
std
::
all_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
return
func
(
ch
);
});
}
// IsFlexibleCase
...
...
src/emitterutils.cpp
View file @
41001d1b
#include <algorithm>
#include <iomanip>
#include <sstream>
...
...
@@ -199,15 +200,10 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
bool
IsValidSingleQuotedScalar
(
const
std
::
string
&
str
,
bool
escapeNonAscii
)
{
// TODO: check for non-printable characters?
for
(
char
ch
:
str
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
false
;
}
if
(
ch
==
'\n'
)
{
return
false
;
}
}
return
true
;
return
std
::
none_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
return
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
||
(
ch
==
'\n'
);
});
}
bool
IsValidLiteralScalar
(
const
std
::
string
&
str
,
FlowType
::
value
flowType
,
...
...
@@ -217,12 +213,9 @@ bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
}
// TODO: check for non-printable characters?
for
(
char
ch
:
str
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
false
;
}
}
return
true
;
return
std
::
none_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
return
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)));
});
}
void
WriteDoubleQuoteEscapeSequence
(
ostream_wrapper
&
out
,
int
codePoint
)
{
...
...
src/node_data.cpp
View file @
41001d1b
...
...
@@ -252,11 +252,15 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
it
=
jt
;
}
for
(
node_map
::
iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
if
(
it
->
first
->
is
(
key
))
{
m_map
.
erase
(
it
);
return
true
;
}
auto
it
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
std
::
pair
<
YAML
::
detail
::
node
*
,
YAML
::
detail
::
node
*>
j
)
{
return
(
j
.
first
->
is
(
key
));
});
if
(
it
!=
m_map
.
end
())
{
m_map
.
erase
(
it
);
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