FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lpython/src/libasr/string_utils.cpp at type_checking · certik/lpython · GitHub
certik
/
lpython
Public
forked from
lcompilers/lpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lpython
/
src
/
libasr
/
string_utils.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (72 loc) · 2 KB
Breadcrumbs
lpython
/
src
/
libasr
/
string_utils.cpp
Copy path
File metadata and controls
87 lines (72 loc) · 2 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
#
include
<
cctype
>
#
include
<
regex
>
#
include
<
algorithm
>
#
include
<
string
>
#
include
<
libasr/string_utils.h
>
#
include
<
libasr/containers.h
>
namespace
LFortran
{
bool
startswith
(
const
std::string &s,
const
std::string &e)
{
if
(s.
size
() < e.
size
())
return
false
;
return
s.
substr
(
0
, e.
size
()) == e;
}
bool
endswith
(
const
std::string &s,
const
std::string &e)
{
if
(s.
size
() < e.
size
())
return
false
;
return
s.
substr
(s.
size
()-e.
size
()) == e;
}
std::string
to_lower
(
const
std::string &s) {
std::string res = s;
std::transform
(res.
begin
(), res.
end
(), res.
begin
(),
[](
unsigned
char
c){
return
std::tolower
(c); });
return
res;
}
char
*
s2c
(Allocator &al,
const
std::string &s) {
Str x; x.
from_str_view
(s);
return
x.
c_str
(al);
}
std::vector<std::string>
split
(
const
std::string &s)
{
std::vector<std::string> result;
std::string split_chars =
"
\n
"
;
size_t
old_pos =
0
;
size_t
new_pos;
while
((new_pos = s.
find_first_of
(split_chars, old_pos)) != std::string::npos) {
std::string substr = s.
substr
(old_pos, new_pos-old_pos);
if
(substr.
size
() >
0
) result.
push_back
(substr);
old_pos = new_pos+
1
;
}
result.
push_back
(s.
substr
(old_pos));
return
result;
}
std::string
join
(
const
std::string j,
const
std::vector<std::string> &l)
{
std::string result;
for
(
size_t
i=
0
; i<l.
size
(); i++) {
result += l[i];
if
(i < l.
size
()-
1
) result += j;
}
return
result;
}
std::vector<std::string>
slice
(
const
std::vector<std::string>& v,
int
start,
int
end)
{
int
oldlen = v.
size
();
int
newlen;
if
((end == -
1
) || (end >= oldlen)) {
newlen = oldlen-start;
}
else
{
newlen = end-start;
}
std::vector<std::string>
nv
(newlen);
for
(
int
i=
0
; i<newlen; i++) {
nv[i] = v[start+i];
}
return
nv;
}
std::string
replace
(
const
std::string &s,
const
std::string ®ex,
const
std::string &replace)
{
return
std::regex_replace
(s,
std::regex
(regex), replace);
}
}
//
namespace LFortran
Back
|
FazBrowse Home
|
New Git URL