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
0d5a97bf
Commit
0d5a97bf
authored
Jun 29, 2008
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored common scalar scanning code (from plain, quoted, and block) to one function.
parent
6c193d6f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
25 deletions
+63
-25
exp.cpp
+8
-2
regex.cpp
+41
-8
regex.h
+7
-1
scanner.h
+2
-0
scanscalar.cpp
+0
-0
test.yaml
+5
-14
No files found.
exp.cpp
View file @
0d5a97bf
...
...
@@ -62,7 +62,7 @@ namespace YAML
}
// Escape
// . Escapes the sequence starting 'in' (it must begin with a '\')
// . Escapes the sequence starting 'in' (it must begin with a '\'
or single quote
)
// and returns the result.
// . Fills 'length' with how many characters we ate.
// . Throws if it's an unknown escape character.
...
...
@@ -72,10 +72,16 @@ namespace YAML
length
=
2
;
// eat slash
in
.
get
();
char
escape
=
in
.
get
();
// switch on escape character
char
ch
=
in
.
get
();
// first do single quote, since it's easier
if
(
escape
==
'\''
&&
ch
==
'\''
)
return
"
\'
"
;
// now do the slash (we're not gonna check if it's a slash - you better pass one!)
switch
(
ch
)
{
case
'0'
:
return
"
\0
"
;
case
'a'
:
return
"
\x07
"
;
...
...
regex.cpp
View file @
0d5a97bf
...
...
@@ -53,6 +53,7 @@ namespace YAML
case
REGEX_MATCH
:
m_pOp
=
new
MatchOperator
;
break
;
case
REGEX_RANGE
:
m_pOp
=
new
RangeOperator
;
break
;
case
REGEX_OR
:
m_pOp
=
new
OrOperator
;
break
;
case
REGEX_AND
:
m_pOp
=
new
AndOperator
;
break
;
case
REGEX_NOT
:
m_pOp
=
new
NotOperator
;
break
;
case
REGEX_SEQ
:
m_pOp
=
new
SeqOperator
;
break
;
}
...
...
@@ -80,19 +81,13 @@ namespace YAML
// . Returns the number of characters matched.
// . Returns -1 if no characters were matched (the reason for
// not returning zero is that we may have an empty regex
// which SHOULD be considered successfully matching nothing,
// but that of course matches zero characters).
// which is ALWAYS successful at matching zero characters).
int
RegEx
::
Match
(
const
std
::
string
&
str
)
const
{
if
(
!
m_pOp
)
return
-
1
;
return
0
;
return
m_pOp
->
Match
(
str
,
*
this
);
//case REGEX_EMPTY:
// if(str.empty())
// return 0;
// return -1;
}
// Match
...
...
@@ -131,6 +126,14 @@ namespace YAML
return
ret
;
}
RegEx
operator
&&
(
const
RegEx
&
ex1
,
const
RegEx
&
ex2
)
{
RegEx
ret
(
REGEX_AND
);
ret
.
m_params
.
push_back
(
ex1
);
ret
.
m_params
.
push_back
(
ex2
);
return
ret
;
}
RegEx
operator
+
(
const
RegEx
&
ex1
,
const
RegEx
&
ex2
)
{
RegEx
ret
(
REGEX_SEQ
);
...
...
@@ -194,6 +197,36 @@ namespace YAML
return
-
1
;
}
// AndOperator
// Note: 'AND' is a little funny, since we may be required to match things
// of different lengths. If we find a match, we return the length of
// the FIRST entry on the list.
int
RegEx
::
AndOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
int
first
=
-
1
;
for
(
unsigned
i
=
0
;
i
<
regex
.
m_params
.
size
();
i
++
)
{
int
n
=
regex
.
m_params
[
i
].
Match
(
str
);
if
(
n
==
-
1
)
return
-
1
;
if
(
i
==
0
)
first
=
n
;
}
return
first
;
}
int
RegEx
::
AndOperator
::
Match
(
std
::
istream
&
in
,
const
RegEx
&
regex
)
const
{
int
first
=
-
1
;
for
(
unsigned
i
=
0
;
i
<
regex
.
m_params
.
size
();
i
++
)
{
int
n
=
regex
.
m_params
[
i
].
Match
(
in
);
if
(
n
==
-
1
)
return
-
1
;
if
(
i
==
0
)
first
=
n
;
}
return
first
;
}
// NotOperator
int
RegEx
::
NotOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
...
...
regex.h
View file @
0d5a97bf
...
...
@@ -6,7 +6,7 @@
namespace
YAML
{
enum
REGEX_OP
{
REGEX_EMPTY
,
REGEX_MATCH
,
REGEX_RANGE
,
REGEX_OR
,
REGEX_NOT
,
REGEX_SEQ
};
enum
REGEX_OP
{
REGEX_EMPTY
,
REGEX_MATCH
,
REGEX_RANGE
,
REGEX_OR
,
REGEX_
AND
,
REGEX_
NOT
,
REGEX_SEQ
};
// simplified regular expressions
// . Only straightforward matches (no repeated characters)
...
...
@@ -35,6 +35,11 @@ namespace YAML
virtual
int
Match
(
std
::
istream
&
in
,
const
RegEx
&
regex
)
const
;
};
struct
AndOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
std
::
istream
&
in
,
const
RegEx
&
regex
)
const
;
};
struct
NotOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
std
::
istream
&
in
,
const
RegEx
&
regex
)
const
;
...
...
@@ -63,6 +68,7 @@ namespace YAML
friend
RegEx
operator
!
(
const
RegEx
&
ex
);
friend
RegEx
operator
||
(
const
RegEx
&
ex1
,
const
RegEx
&
ex2
);
friend
RegEx
operator
&&
(
const
RegEx
&
ex1
,
const
RegEx
&
ex2
);
friend
RegEx
operator
+
(
const
RegEx
&
ex1
,
const
RegEx
&
ex2
);
private
:
...
...
scanner.h
View file @
0d5a97bf
...
...
@@ -5,6 +5,7 @@
#include <queue>
#include <stack>
#include <set>
#include "regex.h"
namespace
YAML
{
...
...
@@ -44,6 +45,7 @@ namespace YAML
bool
IsPlainScalar
();
void
GetBlockIndentation
(
int
&
indent
,
std
::
string
&
breaks
);
std
::
string
ScanScalar
(
RegEx
end
,
bool
eatEnd
,
int
indent
,
char
escape
,
bool
fold
,
bool
eatLeadingWhitespace
,
bool
trimTrailingSpaces
,
int
chomp
);
struct
SimpleKey
{
SimpleKey
(
int
pos_
,
int
line_
,
int
column_
,
int
flowLevel_
);
...
...
scanscalar.cpp
View file @
0d5a97bf
This diff is collapsed.
Click to expand it.
test.yaml
View file @
0d5a97bf
people
:
-
&jsb
name
:
Jesse
age
:
23
-
&dab
name
:
'
Daniel'
age
:
25
-
&ncb
name
:
"
Naftali"
age
:
21
students
:
-
*jsb
-
*ncb
\ No newline at end of file
---
-
"
quoted
scalar
that
contains
---
the
document
start!"
\ No newline at end of file
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