Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
medialibrary
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
58
Issues
58
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VideoLAN
medialibrary
Commits
81fea597
Commit
81fea597
authored
Dec 11, 2018
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: Add a trim helper function
parent
906e9fd3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
Makefile.am
Makefile.am
+2
-0
src/utils/Strings.cpp
src/utils/Strings.cpp
+59
-0
src/utils/Strings.h
src/utils/Strings.h
+46
-0
test/unittest/MiscTests.cpp
test/unittest/MiscTests.cpp
+10
-0
No files found.
Makefile.am
View file @
81fea597
...
...
@@ -102,6 +102,7 @@ libmedialibrary_la_SOURCES = \
src/utils/Directory.cpp
\
src/utils/Filename.cpp
\
src/utils/ModificationsNotifier.cpp
\
src/utils/Strings.cpp
\
src/utils/Url.cpp
\
$(NULL)
...
...
@@ -161,6 +162,7 @@ noinst_HEADERS = \
src/utils/Directory.h
\
src/utils/Filename.h
\
src/utils/ModificationsNotifier.h
\
src/utils/Strings.h
\
src/utils/SWMRLock.h
\
src/utils/Url.h
\
src/VideoTrack.h
\
...
...
src/utils/Strings.cpp
0 → 100644
View file @
81fea597
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2018 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Strings.h"
#include <algorithm>
#include <cctype>
namespace
medialibrary
{
namespace
utils
{
namespace
str
{
std
::
string
&
trim
(
std
::
string
&
value
)
{
value
.
erase
(
begin
(
value
),
std
::
find_if
(
begin
(
value
),
end
(
value
),
[](
char
c
)
{
return
isspace
(
c
)
==
false
;
}));
value
.
erase
(
std
::
find_if
(
value
.
rbegin
(),
value
.
rend
(),
[](
char
c
)
{
return
isspace
(
c
)
==
false
;
}).
base
(),
value
.
end
()
);
return
value
;
}
std
::
string
trim
(
const
std
::
string
&
value
)
{
std
::
string
v
=
value
;
trim
(
v
);
return
v
;
}
}
}
}
src/utils/Strings.h
0 → 100644
View file @
81fea597
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2018 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include <string>
namespace
medialibrary
{
namespace
utils
{
namespace
str
{
/**
* @brief trim Trim the provided string in place
*/
std
::
string
&
trim
(
std
::
string
&
value
);
/**
* @brief trim Returns a copy of the trimmed provided string
*/
std
::
string
trim
(
const
std
::
string
&
value
);
}
}
}
test/unittest/MiscTests.cpp
View file @
81fea597
...
...
@@ -29,6 +29,7 @@
#include "Tests.h"
#include "database/SqliteTools.h"
#include "database/SqliteConnection.h"
#include "utils/Strings.h"
#include "Artist.h"
#include "Media.h"
...
...
@@ -48,6 +49,15 @@ TEST_F( Misc, FileExtensions )
}
}
TEST_F
(
Misc
,
TrimString
)
{
ASSERT_EQ
(
utils
::
str
::
trim
(
"hello world"
),
"hello world"
);
ASSERT_EQ
(
utils
::
str
::
trim
(
" spaaaaaace "
),
"spaaaaaace"
);
ASSERT_EQ
(
utils
::
str
::
trim
(
"
\t
fluffy
\n
otters
\t\n
"
),
"fluffy
\n
otters"
);
ASSERT_EQ
(
utils
::
str
::
trim
(
" "
),
""
);
ASSERT_EQ
(
utils
::
str
::
trim
(
""
),
""
);
}
class
DbModel
:
public
testing
::
Test
{
protected:
...
...
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