Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
59d38f87
Commit
59d38f87
authored
Aug 07, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringUtil: add StripRight() overload with "end" argument
parent
5c5c6a96
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
18 deletions
+50
-18
ClientRead.cxx
src/client/ClientRead.cxx
+3
-4
StandardDirectory.cxx
src/fs/StandardDirectory.cxx
+1
-4
TextInputStream.cxx
src/input/TextInputStream.cxx
+3
-4
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+3
-6
StringUtil.cxx
src/util/StringUtil.cxx
+18
-0
StringUtil.hxx
src/util/StringUtil.hxx
+22
-0
No files found.
src/client/ClientRead.cxx
View file @
59d38f87
...
...
@@ -22,7 +22,7 @@
#include "Partition.hxx"
#include "Instance.hxx"
#include "event/Loop.hxx"
#include "util/
Char
Util.hxx"
#include "util/
String
Util.hxx"
#include <string.h>
...
...
@@ -39,11 +39,10 @@ Client::OnSocketInput(void *data, size_t length)
BufferedSocket
::
ConsumeInput
(
newline
+
1
-
p
);
/* skip whitespace at the end of the line */
while
(
newline
>
p
&&
IsWhitespaceFast
(
newline
[
-
1
]))
--
newline
;
char
*
end
=
StripRight
(
p
,
newline
);
/* terminate the string at the end of the line */
*
newline
=
0
;
*
end
=
0
;
CommandResult
result
=
client_process_line
(
*
this
,
p
);
switch
(
result
)
{
...
...
src/fs/StandardDirectory.cxx
View file @
59d38f87
...
...
@@ -40,7 +40,6 @@
#endif
#ifdef USE_XDG
#include "util/CharUtil.hxx"
#include "util/StringUtil.hxx"
#include "TextFile.hxx"
#include <string.h>
...
...
@@ -169,9 +168,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir)
if
(
line_end
==
nullptr
)
return
true
;
}
else
{
line_end
=
line
+
strlen
(
line
);
while
(
line
<
line_end
&&
IsWhitespaceNotNull
(
line_end
[
-
1
]))
--
line_end
;
line_end
=
StripRight
(
line
,
line
+
strlen
(
line
));
}
// check for empty result
...
...
src/input/TextInputStream.cxx
View file @
59d38f87
...
...
@@ -20,7 +20,7 @@
#include "config.h"
#include "TextInputStream.hxx"
#include "InputStream.hxx"
#include "util/
Char
Util.hxx"
#include "util/
String
Util.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
...
...
@@ -72,8 +72,7 @@ TextInputStream::ReadLine()
buffer
.
Consume
(
p
-
src
+
1
);
while
(
p
>
src
&&
IsWhitespaceFast
(
p
[
-
1
]))
--
p
;
*
p
=
0
;
char
*
end
=
StripRight
(
src
,
p
);
*
end
=
0
;
return
src
;
}
src/input/plugins/CurlInputPlugin.cxx
View file @
59d38f87
...
...
@@ -31,7 +31,7 @@
#include "event/Call.hxx"
#include "IOThread.hxx"
#include "util/ASCII.hxx"
#include "util/
Char
Util.hxx"
#include "util/
String
Util.hxx"
#include "util/NumberParser.hxx"
#include "util/CircularBuffer.hxx"
#include "util/HugeAllocator.hxx"
...
...
@@ -661,11 +661,8 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
/* strip the value */
while
(
value
<
end
&&
IsWhitespaceOrNull
(
*
value
))
++
value
;
while
(
end
>
value
&&
IsWhitespaceOrNull
(
end
[
-
1
]))
--
end
;
value
=
StripLeft
(
value
,
end
);
end
=
StripRight
(
value
,
end
);
c
.
HeaderReceived
(
name
,
std
::
string
(
value
,
end
));
return
size
;
...
...
src/util/StringUtil.cxx
View file @
59d38f87
...
...
@@ -35,6 +35,24 @@ StripLeft(const char *p)
return
p
;
}
const
char
*
StripLeft
(
const
char
*
p
,
const
char
*
end
)
{
while
(
p
<
end
&&
IsWhitespaceOrNull
(
*
p
))
++
p
;
return
p
;
}
const
char
*
StripRight
(
const
char
*
p
,
const
char
*
end
)
{
while
(
end
>
p
&&
IsWhitespaceOrNull
(
end
[
-
1
]))
--
end
;
return
end
;
}
size_t
StripRight
(
const
char
*
p
,
size_t
length
)
{
...
...
src/util/StringUtil.hxx
View file @
59d38f87
...
...
@@ -39,6 +39,28 @@ StripLeft(char *p)
return
const_cast
<
char
*>
(
StripLeft
((
const
char
*
)
p
));
}
gcc_pure
const
char
*
StripLeft
(
const
char
*
p
,
const
char
*
end
);
/**
* Determine the string's end as if it was stripped on the right side.
*/
gcc_pure
const
char
*
StripRight
(
const
char
*
p
,
const
char
*
end
);
/**
* Determine the string's end as if it was stripped on the right side.
*/
gcc_pure
static
inline
char
*
StripRight
(
char
*
p
,
char
*
end
)
{
return
const_cast
<
char
*>
(
StripRight
((
const
char
*
)
p
,
(
const
char
*
)
end
));
}
/**
* Determine the string's length as if it was stripped on the right
* side.
...
...
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