Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
GUYOT DOMINIQUE
paraload-ng
Commits
28170238
Commit
28170238
authored
Jan 27, 2020
by
GUYOT DOMINIQUE
Browse files
Initial def of struct parser
parent
2bf683a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
11 deletions
+49
-11
parser.cpp
parser.cpp
+49
-11
No files found.
parser.cpp
View file @
28170238
...
...
@@ -7,22 +7,60 @@
#include <fcntl.h>
#include <unistd.h>
#include <string_view>
#include <iostream>
#include <vector>
using
namespace
::
std
;
int
main
(
int
argc
,
char
**
argv
){
struct
stat
sfd
;
int
fd
;
size_t
size
;
char
*
mmfile
;
int
i
;
fd
=
open
(
argv
[
1
],
O_RDONLY
);
fstat
(
fd
,
&
sfd
);
size
=
sfd
.
st_size
;
mmfile
=
(
char
*
)
mmap
(
NULL
,
size
,
PROT_READ
,
MAP_PRIVATE
|
MAP_DENYWRITE
,
fd
,
0
);
close
(
fd
);
struct
Parser
{
vector
<
string_view
>
chunks
;
Parser
(
char
**
argv
){
struct
stat
sfd
;
int
fd
;
size_t
size
;
size_t
pos
=
0
;
size_t
chunk_size
;
char
*
mmfile
;
fd
=
open
(
argv
[
1
],
O_RDONLY
);
fstat
(
fd
,
&
sfd
);
size
=
sfd
.
st_size
;
mmfile
=
(
char
*
)
mmap
(
NULL
,
size
,
PROT_READ
,
MAP_PRIVATE
|
MAP_DENYWRITE
,
fd
,
0
);
close
(
fd
);
string_view
mapview
(
mmfile
,
size
);
string_view
sentinel
(
">"
);
string_view
chunk
;
while
(
pos
<
mapview
.
size
()){
pos
=
mapview
.
find
(
sentinel
,
pos
);
chunk_size
=
mapview
.
find
(
sentinel
,
pos
+
sentinel
.
size
())
-
pos
;
chunk
=
mapview
.
substr
(
pos
,
chunk_size
);
chunks
.
push_back
(
chunk
);
pos
+=
chunk_size
;
}
chunks
.
shrink_to_fit
();
}
~
Parser
(){
}
string_view
get_chunk
(
size_t
i
){
return
(
chunks
[
i
]);
}
};
int
main
(
int
argc
,
char
**
argv
){
Parser
*
P
=
new
Parser
(
argv
);
cout
<<
P
->
get_chunk
(
4
);
}
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