Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
2958c56a
Unverified
Commit
2958c56a
authored
Nov 01, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change parser to use streambuf directly
parent
9cff8768
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
15 deletions
+11
-15
include/cif++/parser.hpp
+1
-1
src/parser.cpp
+10
-14
No files found.
include/cif++/parser.hpp
View file @
2958c56a
...
@@ -248,7 +248,7 @@ class sac_parser
...
@@ -248,7 +248,7 @@ class sac_parser
SAVE
SAVE
};
};
std
::
istream
&
m_source
;
std
::
streambuf
&
m_source
;
// Parser state
// Parser state
bool
m_validate
;
bool
m_validate
;
...
...
src/parser.cpp
View file @
2958c56a
...
@@ -47,7 +47,7 @@ namespace cif
...
@@ -47,7 +47,7 @@ namespace cif
// --------------------------------------------------------------------
// --------------------------------------------------------------------
sac_parser
::
sac_parser
(
std
::
istream
&
is
,
bool
init
)
sac_parser
::
sac_parser
(
std
::
istream
&
is
,
bool
init
)
:
m_source
(
is
)
:
m_source
(
*
is
.
rdbuf
()
)
{
{
m_validate
=
true
;
m_validate
=
true
;
m_line_nr
=
1
;
m_line_nr
=
1
;
...
@@ -62,20 +62,20 @@ sac_parser::sac_parser(std::istream &is, bool init)
...
@@ -62,20 +62,20 @@ sac_parser::sac_parser(std::istream &is, bool init)
// translation.
// translation.
int
sac_parser
::
get_next_char
()
int
sac_parser
::
get_next_char
()
{
{
int
result
;
int
result
=
std
::
char_traits
<
char
>::
eof
()
;
if
(
m_buffer
.
empty
())
if
(
not
m_buffer
.
empty
())
result
=
m_source
.
get
();
else
{
{
result
=
m_buffer
.
back
();
result
=
m_buffer
.
back
();
m_buffer
.
pop_back
();
m_buffer
.
pop_back
();
}
}
else
result
=
m_source
.
sbumpc
();
// very simple CR/LF translation into LF
// very simple CR/LF translation into LF
if
(
result
==
'\r'
)
if
(
result
==
'\r'
)
{
{
int
lookahead
=
m_source
.
get
();
int
lookahead
=
m_source
.
sbumpc
();
if
(
lookahead
!=
'\n'
)
if
(
lookahead
!=
'\n'
)
m_buffer
.
push_back
(
lookahead
);
m_buffer
.
push_back
(
lookahead
);
result
=
'\n'
;
result
=
'\n'
;
...
@@ -453,8 +453,6 @@ void sac_parser::match(CIFToken token)
...
@@ -453,8 +453,6 @@ void sac_parser::match(CIFToken token)
bool
sac_parser
::
parse_single_datablock
(
const
std
::
string
&
datablock
)
bool
sac_parser
::
parse_single_datablock
(
const
std
::
string
&
datablock
)
{
{
// first locate the start, as fast as we can
// first locate the start, as fast as we can
auto
&
sb
=
*
m_source
.
rdbuf
();
enum
enum
{
{
start
,
start
,
...
@@ -471,7 +469,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock)
...
@@ -471,7 +469,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock)
std
::
string
::
size_type
si
=
0
;
std
::
string
::
size_type
si
=
0
;
bool
found
=
false
;
bool
found
=
false
;
for
(
auto
ch
=
sb
.
sbumpc
();
not
found
and
ch
!=
std
::
streambuf
::
traits_type
::
eof
();
ch
=
sb
.
sbumpc
())
for
(
auto
ch
=
m_source
.
sbumpc
();
not
found
and
ch
!=
std
::
streambuf
::
traits_type
::
eof
();
ch
=
m_source
.
sbumpc
())
{
{
switch
(
state
)
switch
(
state
)
{
{
...
@@ -544,8 +542,6 @@ sac_parser::datablock_index sac_parser::index_datablocks()
...
@@ -544,8 +542,6 @@ sac_parser::datablock_index sac_parser::index_datablocks()
datablock_index
index
;
datablock_index
index
;
// first locate the start, as fast as we can
// first locate the start, as fast as we can
auto
&
sb
=
*
m_source
.
rdbuf
();
enum
enum
{
{
start
,
start
,
...
@@ -563,7 +559,7 @@ sac_parser::datablock_index sac_parser::index_datablocks()
...
@@ -563,7 +559,7 @@ sac_parser::datablock_index sac_parser::index_datablocks()
std
::
string
::
size_type
si
=
0
;
std
::
string
::
size_type
si
=
0
;
std
::
string
datablock
;
std
::
string
datablock
;
for
(
auto
ch
=
sb
.
sbumpc
();
ch
!=
std
::
streambuf
::
traits_type
::
eof
();
ch
=
sb
.
sbumpc
())
for
(
auto
ch
=
m_source
.
sbumpc
();
ch
!=
std
::
streambuf
::
traits_type
::
eof
();
ch
=
m_source
.
sbumpc
())
{
{
switch
(
state
)
switch
(
state
)
{
{
...
@@ -626,7 +622,7 @@ sac_parser::datablock_index sac_parser::index_datablocks()
...
@@ -626,7 +622,7 @@ sac_parser::datablock_index sac_parser::index_datablocks()
else
if
(
isspace
(
ch
))
else
if
(
isspace
(
ch
))
{
{
if
(
not
datablock
.
empty
())
if
(
not
datablock
.
empty
())
index
[
datablock
]
=
m_source
.
tellg
(
);
index
[
datablock
]
=
m_source
.
pubseekoff
(
0
,
std
::
ios_base
::
cur
,
std
::
ios_base
::
in
);
state
=
start
;
state
=
start
;
}
}
...
@@ -648,7 +644,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data
...
@@ -648,7 +644,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data
auto
i
=
index
.
find
(
datablock
);
auto
i
=
index
.
find
(
datablock
);
if
(
i
!=
index
.
end
())
if
(
i
!=
index
.
end
())
{
{
m_source
.
seekg
(
i
->
second
);
m_source
.
pubseekpos
(
i
->
second
,
std
::
ios_base
::
in
);
produce_datablock
(
datablock
);
produce_datablock
(
datablock
);
m_lookahead
=
get_next_token
();
m_lookahead
=
get_next_token
();
...
...
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