Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
1e4876b4
Commit
1e4876b4
authored
Nov 22, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
410621dd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
wcfs/internal/wcfs_misc.cpp
wcfs/internal/wcfs_misc.cpp
+23
-0
wcfs/internal/wcfs_misc.h
wcfs/internal/wcfs_misc.h
+7
-0
wcfs/internal/wcfs_watchlink.cpp
wcfs/internal/wcfs_watchlink.cpp
+3
-1
No files found.
wcfs/internal/wcfs_misc.cpp
View file @
1e4876b4
...
...
@@ -174,6 +174,29 @@ bool has_prefix(const string &s, char prefix) {
return
(
s
.
size
()
>=
1
&&
s
[
0
]
==
prefix
);
}
bool
has_suffix
(
const
string
&
s
,
const
string
&
suffix
)
{
return
(
s
.
size
()
>=
suffix
.
size
()
&&
s
.
compare
(
s
.
size
()
-
suffix
.
size
(),
suffix
.
size
(),
suffix
));
}
bool
has_suffix
(
const
string
&
s
,
char
suffix
)
{
return
(
s
.
size
()
>=
1
&&
s
[
s
.
size
()
-
1
]
==
suffix
);
}
// XXX trim_prefix
string
trim_suffix
(
const
string
&
s
,
const
string
&
suffix
)
{
if
(
!
has_suffix
(
s
,
suffix
))
return
s
;
return
s
.
substr
(
0
,
s
.
size
()
-
suffix
.
size
());
}
string
trim_suffix
(
const
string
&
s
,
char
suffix
)
{
if
(
!
has_suffix
(
s
,
suffix
))
return
s
;
return
s
.
substr
(
0
,
s
.
size
()
-
1
);
}
vector
<
string
>
split
(
const
string
&
s
,
char
sep
)
{
vector
<
string
>
r
;
int
psep_prev
=-
1
;
...
...
wcfs/internal/wcfs_misc.h
View file @
1e4876b4
...
...
@@ -132,6 +132,13 @@ namespace strings {
bool
has_prefix
(
const
string
&
s
,
const
string
&
prefix
);
bool
has_prefix
(
const
string
&
s
,
char
prefix
);
bool
has_suffix
(
const
string
&
s
,
const
string
&
suffix
);
bool
has_suffix
(
const
string
&
s
,
char
suffix
);
string
trim_prefix
(
const
string
&
s
,
const
string
&
prefix
);
string
trim_prefix
(
const
string
&
s
,
char
prefix
);
string
trim_suffix
(
const
string
&
s
,
const
string
&
suffix
);
string
trim_suffix
(
const
string
&
s
,
char
suffix
);
vector
<
string
>
split
(
const
string
&
s
,
char
sep
);
}
// strings::
...
...
wcfs/internal/wcfs_watchlink.cpp
View file @
1e4876b4
...
...
@@ -388,8 +388,10 @@ error rxPkt::from_string(const string &rx) {
auto
sp
=
rx
.
find
(
' '
);
if
(
sp
==
string
::
npos
)
return
fmt
::
errorf
(
"invalid pkt: no SP"
);
if
(
!
strings
::
has_suffix
(
rx
,
'\n'
))
return
fmt
::
errorf
(
"invalid pkt: no LF"
);
string
sid
=
rx
.
substr
(
0
,
sp
);
string
smsg
=
rx
.
substr
(
sp
+
1
);
string
smsg
=
strings
::
trim_suffix
(
rx
.
substr
(
sp
+
1
),
'\n'
);
error
err
;
tie
(
pkt
.
stream
,
err
)
=
xstrconv
::
parseUint
(
sid
);
...
...
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