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
a6afaabc
Commit
a6afaabc
authored
Oct 28, 2010
by
Jesse Beder
Browse files
Refactored tags so we can emit secondary tags (and named local tags)
parent
d508203e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
27 deletions
+70
-27
include/yaml-cpp/emittermanip.h
include/yaml-cpp/emittermanip.h
+21
-13
src/emitter.cpp
src/emitter.cpp
+18
-14
src/emitterutils.cpp
src/emitterutils.cpp
+30
-0
src/emitterutils.h
src/emitterutils.h
+1
-0
No files found.
include/yaml-cpp/emittermanip.h
View file @
a6afaabc
...
@@ -84,24 +84,32 @@ namespace YAML
...
@@ -84,24 +84,32 @@ namespace YAML
}
}
struct
_Tag
{
struct
_Tag
{
explicit
_Tag
(
const
std
::
string
&
content_
)
struct
Type
{
enum
value
{
Verbatim
,
PrimaryHandle
,
NamedHandle
};
};
:
content
(
content_
),
verbatim
(
true
)
explicit
_Tag
(
const
std
::
string
&
prefix_
,
const
std
::
string
&
content_
,
Type
::
value
type_
)
:
prefix
(
prefix_
),
content
(
content_
),
type
(
type_
)
{
{
}
}
std
::
string
prefix
;
std
::
string
content
;
std
::
string
content
;
bool
verbatim
;
Type
::
value
type
;
};
};
typedef
_Tag
VerbatimTag
;
inline
_Tag
VerbatimTag
(
const
std
::
string
content
)
{
return
_Tag
(
""
,
content
,
_Tag
::
Type
::
Verbatim
);
struct
LocalTag
:
public
_Tag
}
{
explicit
LocalTag
(
const
std
::
string
&
content_
)
inline
_Tag
LocalTag
(
const
std
::
string
content
)
{
:
_Tag
(
content_
)
return
_Tag
(
""
,
content
,
_Tag
::
Type
::
PrimaryHandle
);
{
}
verbatim
=
false
;
}
inline
_Tag
LocalTag
(
const
std
::
string
&
prefix
,
const
std
::
string
content
)
{
};
return
_Tag
(
prefix
,
content
,
_Tag
::
Type
::
NamedHandle
);
}
inline
_Tag
SecondaryTag
(
const
std
::
string
content
)
{
return
_Tag
(
""
,
content
,
_Tag
::
Type
::
NamedHandle
);
}
struct
_Comment
{
struct
_Comment
{
_Comment
(
const
std
::
string
&
content_
)
:
content
(
content_
)
{}
_Comment
(
const
std
::
string
&
content_
)
:
content
(
content_
)
{}
...
...
src/emitter.cpp
View file @
a6afaabc
...
@@ -680,27 +680,31 @@ namespace YAML
...
@@ -680,27 +680,31 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
EmitTag
(
tag
.
verbatim
,
tag
);
return
*
this
;
}
void
Emitter
::
EmitTag
(
bool
verbatim
,
const
_Tag
&
tag
)
{
PreAtomicWrite
();
PreAtomicWrite
();
EmitSeparationIfNecessary
();
EmitSeparationIfNecessary
();
if
(
!
Utils
::
WriteTag
(
m_stream
,
tag
.
content
,
verbatim
))
{
bool
success
=
false
;
if
(
tag
.
type
==
_Tag
::
Type
::
Verbatim
)
success
=
Utils
::
WriteTag
(
m_stream
,
tag
.
content
,
true
);
else
if
(
tag
.
type
==
_Tag
::
Type
::
PrimaryHandle
)
success
=
Utils
::
WriteTag
(
m_stream
,
tag
.
content
,
false
);
else
success
=
Utils
::
WriteTagWithPrefix
(
m_stream
,
tag
.
prefix
,
tag
.
content
);
if
(
!
success
)
{
m_pState
->
SetError
(
ErrorMsg
::
INVALID_TAG
);
m_pState
->
SetError
(
ErrorMsg
::
INVALID_TAG
);
return
;
return
*
this
;
}
}
m_pState
->
RequireSeparation
();
m_pState
->
RequireSeparation
();
// Note: no PostAtomicWrite() because we need another value for this node
// Note: no PostAtomicWrite() because we need another value for this node
return
*
this
;
}
}
void
Emitter
::
EmitKindTag
()
void
Emitter
::
EmitKindTag
()
{
{
_Tag
tag
(
""
);
Write
(
LocalTag
(
""
));
EmitTag
(
false
,
tag
);
}
}
Emitter
&
Emitter
::
Write
(
const
_Comment
&
comment
)
Emitter
&
Emitter
::
Write
(
const
_Comment
&
comment
)
...
@@ -727,10 +731,10 @@ namespace YAML
...
@@ -727,10 +731,10 @@ namespace YAML
Emitter
&
Emitter
::
Write
(
const
_Binary
&
binary
)
Emitter
&
Emitter
::
Write
(
const
_Binary
&
binary
)
{
{
Write
(
SecondaryTag
(
"binary"
));
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
// TODO: write tag !!binary
PreAtomicWrite
();
PreAtomicWrite
();
EmitSeparationIfNecessary
();
EmitSeparationIfNecessary
();
...
...
src/emitterutils.cpp
View file @
a6afaabc
...
@@ -314,6 +314,36 @@ namespace YAML
...
@@ -314,6 +314,36 @@ namespace YAML
return
true
;
return
true
;
}
}
bool
WriteTagWithPrefix
(
ostream
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
)
{
out
<<
"!"
;
StringCharSource
prefixBuffer
(
prefix
.
c_str
(),
prefix
.
size
());
while
(
prefixBuffer
)
{
int
n
=
Exp
::
URI
().
Match
(
prefixBuffer
);
if
(
n
<=
0
)
return
false
;
while
(
--
n
>=
0
)
{
out
<<
prefixBuffer
[
0
];
++
prefixBuffer
;
}
}
out
<<
"!"
;
StringCharSource
tagBuffer
(
tag
.
c_str
(),
tag
.
size
());
while
(
tagBuffer
)
{
int
n
=
Exp
::
Tag
().
Match
(
tagBuffer
);
if
(
n
<=
0
)
return
false
;
while
(
--
n
>=
0
)
{
out
<<
tagBuffer
[
0
];
++
tagBuffer
;
}
}
return
true
;
}
bool
WriteBinary
(
ostream
&
out
,
const
char
*
data
,
std
::
size_t
size
)
bool
WriteBinary
(
ostream
&
out
,
const
char
*
data
,
std
::
size_t
size
)
{
{
static
const
char
encoding
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
static
const
char
encoding
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
...
...
src/emitterutils.h
View file @
a6afaabc
...
@@ -19,6 +19,7 @@ namespace YAML
...
@@ -19,6 +19,7 @@ namespace YAML
bool
WriteAlias
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteAlias
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteAnchor
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteAnchor
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteTag
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
verbatim
);
bool
WriteTag
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
verbatim
);
bool
WriteTagWithPrefix
(
ostream
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
);
bool
WriteBinary
(
ostream
&
out
,
const
char
*
data
,
std
::
size_t
size
);
bool
WriteBinary
(
ostream
&
out
,
const
char
*
data
,
std
::
size_t
size
);
}
}
}
}
...
...
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