Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ACGL
acgl
Commits
a579773f
Commit
a579773f
authored
Dec 16, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added function to convert an int to a string with padding (e.g. for filenames)
parent
32d9b53a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
include/ACGL/Utils/StringHelpers.hh
include/ACGL/Utils/StringHelpers.hh
+3
-0
src/ACGL/Utils/StringHelpers.cc
src/ACGL/Utils/StringHelpers.cc
+12
-0
No files found.
include/ACGL/Utils/StringHelpers.hh
View file @
a579773f
...
...
@@ -48,6 +48,9 @@ namespace StringHelpers
//! strips a string of all leading and trailing characters out of a given list (but leaves the ones in between)
std
::
string
stripOfCharacters
(
const
std
::
string
&
_string
,
const
std
::
string
&
_charsToStrip
);
//! converts an int to a string but adds leading zeros (e.g. _maxPadding = 2, 1 -> 01)
std
::
string
intToString
(
const
int
_number
,
const
int
_maxPadding
=
0
);
//! Convert a primitive type to a string (e.g. string s = toString(1.5f)), also supports some GLM types (but not complete)
template
<
class
T
>
std
::
string
toString
(
const
T
&
_t
);
...
...
src/ACGL/Utils/StringHelpers.cc
View file @
a579773f
...
...
@@ -7,6 +7,7 @@
#include <ACGL/Utils/StringHelpers.hh>
#include <ACGL/Math/Math.hh>
#include <algorithm> // transform
#include <iomanip> // setfill
namespace
ACGL
{
namespace
Utils
{
...
...
@@ -109,6 +110,17 @@ namespace StringHelpers
return
stripOfCharacters
(
_string
,
whitespaces
);
}
std
::
string
intToString
(
const
int
_number
,
const
int
_maxPadding
)
{
std
::
ostringstream
stream
;
if
(
_maxPadding
>
0
)
{
stream
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
_maxPadding
)
<<
_number
;
}
else
{
stream
<<
_number
;
}
return
stream
.
str
();
}
template
<
class
T
>
std
::
string
toString
(
const
T
&
_t
)
{
...
...
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