FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpputils/include/cpputils/string-lineenum.h at master · nlitsme/cpputils · GitHub
nlitsme
/
cpputils
Public
Notifications
You must be signed in to change notification settings
Fork
10
Star
24
Code
Issues
1
Pull requests
1
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpputils
/
include
/
cpputils
/
string-lineenum.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (87 loc) · 2.14 KB
Breadcrumbs
cpputils
/
include
/
cpputils
/
string-lineenum.h
Copy path
File metadata and controls
100 lines (87 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
pragma
once
#
include
<
cpputils/arrayview.h
>
#
include
<
algorithm
>
/*
*
* enumerate lines in a byte / char range like this:
*
* for (auto line : lineenumerator(range))
* {
* ...
* }
*
* note that this is kind of a duplicate of stringsplitter
*/
//
todo: fix problem where last non-lf terminated section is not
//
returned as a part.
template
<
typename
PTR
=std::string::const_iterator>
struct
lineenumerator
{
struct
iter
{
PTR
p, q, last;
iter
(
PTR
first,
PTR
last)
: p(first), q(first), last(last)
{
q =
std::find
(p, last,
'
\n
'
);
}
auto
operator
*()
{
return
std::string
(p, q);
}
iter&
operator
++()
{
p = (q<last) ? q+
1
: last;
q =
std::find
(p, last,
'
\n
'
);
return
*
this
;
}
friend
bool
operator
!=(
const
iter& lhs,
const
iter& rhs)
{
return
lhs.
p
!= rhs.
p
;
}
};
PTR
first, last;
lineenumerator
(
const
std::string& v)
: first(v.begin()), last(v.end())
{
}
lineenumerator
(
PTR
first,
PTR
last)
: first(first), last(last)
{
}
iter
begin
() {
return
iter
(first, last); }
iter
end
() {
return
iter
(last, last); }
};
/*
struct lineenumerator {
template<typename PTR>
struct iter {
PTR p, q, last;
iter(PTR first, PTR last)
: p(first), q(first), last(last)
{
q = std::find(p, last, '\n');
}
auto operator*()
{
return std::span(p, q);
}
iter& operator++()
{
p = (q<last) ? q+1 : last;
q = std::find(p, last, '\n');
return *this;
}
friend bool operator!=(const iter& lhs, const iter& rhs)
{
return lhs.p != rhs.p;
}
};
std::span<const char> text;
template<typename CHAR>
lineenumerator(std::span<const CHAR> text)
: text((const char*)text.data(), (const char*)text.data()+text.size())
{
}
iter begin() { return iter(text.begin(), text.end()); }
iter end() { return iter(text.end(), text.end()); }
};
*/
Back
|
FazBrowse Home
|
New Git URL