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
620c58ab
Commit
620c58ab
authored
Jun 01, 2009
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the nested RegEx classes so they don't need to also take an std::string
parent
d2e03739
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
80 deletions
+10
-80
src/regex.cpp
+10
-73
src/regex.h
+0
-7
No files found.
src/regex.cpp
View file @
620c58ab
...
...
@@ -106,29 +106,25 @@ namespace YAML
// . Returns -1 if no characters were matched (the reason for
// not returning zero is that we may have an empty regex
// which is ALWAYS successful at matching zero characters).
int
RegEx
::
Match
(
const
std
::
string
&
str
)
const
// . REMEMBER that we only match from the start of the buffer!
int
RegEx
::
Match
(
const
Buffer
&
buffer
)
const
{
if
(
!
m_pOp
)
return
str
.
empty
()
?
0
:
-
1
;
// the empty regex only is successful on the empty string
return
!
buffer
?
0
:
-
1
;
// the empty regex only is successful on the empty string
return
m_pOp
->
Match
(
st
r
,
*
this
);
return
m_pOp
->
Match
(
buffe
r
,
*
this
);
}
// Match
int
RegEx
::
Match
(
const
Stream
&
in
)
const
int
RegEx
::
Match
(
const
std
::
string
&
str
)
const
{
return
Match
(
in
.
current
());
Buffer
buffer
(
str
.
c_str
(),
str
.
size
());
return
Match
(
buffer
);
}
// Match
// . The buffer version does the same thing as the string version;
// REMEMBER that we only match from the start of the buffer!
int
RegEx
::
Match
(
const
Buffer
&
buffer
)
const
int
RegEx
::
Match
(
const
Stream
&
in
)
const
{
if
(
!
m_pOp
)
return
!
buffer
?
0
:
-
1
;
// see above
return
m_pOp
->
Match
(
buffer
,
*
this
);
return
Match
(
in
.
current
());
}
RegEx
operator
!
(
const
RegEx
&
ex
)
...
...
@@ -166,14 +162,6 @@ namespace YAML
// Operators
// MatchOperator
int
RegEx
::
MatchOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
if
(
str
.
empty
()
||
str
[
0
]
!=
regex
.
m_a
)
return
-
1
;
return
1
;
}
int
RegEx
::
MatchOperator
::
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
if
(
!
buffer
||
buffer
[
0
]
!=
regex
.
m_a
)
...
...
@@ -182,13 +170,6 @@ namespace YAML
}
// RangeOperator
int
RegEx
::
RangeOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
if
(
str
.
empty
()
||
regex
.
m_a
>
str
[
0
]
||
regex
.
m_z
<
str
[
0
])
return
-
1
;
return
1
;
}
int
RegEx
::
RangeOperator
::
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
if
(
!
buffer
||
regex
.
m_a
>
buffer
[
0
]
||
regex
.
m_z
<
buffer
[
0
])
...
...
@@ -197,16 +178,6 @@ namespace YAML
}
// OrOperator
int
RegEx
::
OrOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
for
(
unsigned
i
=
0
;
i
<
regex
.
m_params
.
size
();
i
++
)
{
int
n
=
regex
.
m_params
[
i
].
Match
(
str
);
if
(
n
>=
0
)
return
n
;
}
return
-
1
;
}
int
RegEx
::
OrOperator
::
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
for
(
unsigned
i
=
0
;
i
<
regex
.
m_params
.
size
();
i
++
)
{
...
...
@@ -221,19 +192,6 @@ namespace YAML
// 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
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
int
first
=
-
1
;
...
...
@@ -248,15 +206,6 @@ namespace YAML
}
// NotOperator
int
RegEx
::
NotOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
if
(
regex
.
m_params
.
empty
())
return
-
1
;
if
(
regex
.
m_params
[
0
].
Match
(
str
)
>=
0
)
return
-
1
;
return
1
;
}
int
RegEx
::
NotOperator
::
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
if
(
regex
.
m_params
.
empty
())
...
...
@@ -267,18 +216,6 @@ namespace YAML
}
// SeqOperator
int
RegEx
::
SeqOperator
::
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
{
int
offset
=
0
;
for
(
unsigned
i
=
0
;
i
<
regex
.
m_params
.
size
();
i
++
)
{
int
n
=
regex
.
m_params
[
i
].
Match
(
str
.
substr
(
offset
));
if
(
n
==
-
1
)
return
-
1
;
offset
+=
n
;
}
return
offset
;
}
int
RegEx
::
SeqOperator
::
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
{
int
offset
=
0
;
...
...
src/regex.h
View file @
620c58ab
...
...
@@ -19,37 +19,30 @@ namespace YAML
// the operators
struct
Operator
{
virtual
~
Operator
()
{}
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
=
0
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
=
0
;
};
struct
MatchOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
struct
RangeOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
struct
OrOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
struct
AndOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
struct
NotOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
struct
SeqOperator
:
public
Operator
{
virtual
int
Match
(
const
std
::
string
&
str
,
const
RegEx
&
regex
)
const
;
virtual
int
Match
(
const
Buffer
&
buffer
,
const
RegEx
&
regex
)
const
;
};
...
...
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