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
4b70f9d2
Commit
4b70f9d2
authored
Dec 04, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/DivideString: add option "strip"
parent
79d2d1c2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
3 deletions
+28
-3
AoOutputPlugin.cxx
src/output/plugins/AoOutputPlugin.cxx
+1
-1
DivideString.cxx
src/util/DivideString.cxx
+12
-1
DivideString.hxx
src/util/DivideString.hxx
+5
-1
DivideStringTest.hxx
test/DivideStringTest.hxx
+10
-0
No files found.
src/output/plugins/AoOutputPlugin.cxx
View file @
4b70f9d2
...
...
@@ -128,7 +128,7 @@ AoOutput::Configure(const config_param ¶m, Error &error)
value
=
param
.
GetBlockValue
(
"options"
,
nullptr
);
if
(
value
!=
nullptr
)
{
for
(
const
auto
&
i
:
SplitString
(
value
,
';'
))
{
const
DivideString
ss
(
i
.
c_str
(),
'='
);
const
DivideString
ss
(
i
.
c_str
(),
'='
,
true
);
if
(
!
ss
.
IsDefined
())
{
error
.
Format
(
ao_output_domain
,
...
...
src/util/DivideString.cxx
View file @
4b70f9d2
...
...
@@ -18,10 +18,11 @@
*/
#include "DivideString.hxx"
#include "StringUtil.hxx"
#include <string.h>
DivideString
::
DivideString
(
const
char
*
s
,
char
separator
)
DivideString
::
DivideString
(
const
char
*
s
,
char
separator
,
bool
strip
)
:
first
(
nullptr
)
{
const
char
*
x
=
strchr
(
s
,
separator
);
...
...
@@ -31,6 +32,16 @@ DivideString::DivideString(const char *s, char separator)
size_t
length
=
x
-
s
;
second
=
x
+
1
;
if
(
strip
)
second
=
StripLeft
(
second
);
if
(
strip
)
{
const
char
*
end
=
s
+
length
;
s
=
StripLeft
(
s
);
end
=
StripRight
(
s
,
end
);
length
=
end
-
s
;
}
first
=
new
char
[
length
+
1
];
memcpy
(
first
,
s
,
length
);
first
[
length
]
=
0
;
...
...
src/util/DivideString.hxx
View file @
4b70f9d2
...
...
@@ -33,7 +33,11 @@ class DivideString {
const
char
*
second
;
public
:
DivideString
(
const
char
*
s
,
char
separator
);
/**
* @param strip strip the first part and left-strip the second
* part?
*/
DivideString
(
const
char
*
s
,
char
separator
,
bool
strip
=
false
);
~
DivideString
()
{
delete
[]
first
;
...
...
test/DivideStringTest.hxx
View file @
4b70f9d2
...
...
@@ -15,6 +15,7 @@ class DivideStringTest : public CppUnit::TestFixture {
CPPUNIT_TEST
(
TestBasic
);
CPPUNIT_TEST
(
TestEmpty
);
CPPUNIT_TEST
(
TestFail
);
CPPUNIT_TEST
(
TestStrip
);
CPPUNIT_TEST_SUITE_END
();
public
:
...
...
@@ -41,4 +42,13 @@ public:
const
DivideString
ds
(
input
,
'.'
);
CPPUNIT_ASSERT
(
!
ds
.
IsDefined
());
}
void
TestStrip
()
{
constexpr
char
input
[]
=
" foo
\t
.
\n
bar
\r
"
;
const
DivideString
ds
(
input
,
'.'
,
true
);
CPPUNIT_ASSERT
(
ds
.
IsDefined
());
CPPUNIT_ASSERT
(
!
ds
.
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
0
,
strcmp
(
ds
.
GetFirst
(),
"foo"
));
CPPUNIT_ASSERT_EQUAL
(
input
+
7
,
ds
.
GetSecond
());
}
};
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