Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitri Naumov
ogs
Commits
537032d2
Commit
537032d2
authored
8 years ago
by
Norihiro Watanabe
Browse files
Options
Downloads
Patches
Plain Diff
add format() in StringTools
parent
5c337872
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/StringTools.cpp
+20
-2
20 additions, 2 deletions
BaseLib/StringTools.cpp
BaseLib/StringTools.h
+3
-0
3 additions, 0 deletions
BaseLib/StringTools.h
with
23 additions
and
2 deletions
BaseLib/StringTools.cpp
+
20
−
2
View file @
537032d2
...
@@ -16,10 +16,11 @@
...
@@ -16,10 +16,11 @@
#include
<algorithm>
#include
<algorithm>
#include
<cctype>
#include
<cctype>
#include
<cstdarg>
#include
<cstdio>
#include
<iomanip>
#include
<iomanip>
#include
"logog/include/logog.hpp"
#include
<logog/include/logog.hpp>
#include
<boost/algorithm/string/replace.hpp>
#include
<boost/algorithm/string/replace.hpp>
namespace
BaseLib
namespace
BaseLib
...
@@ -77,6 +78,23 @@ std::string const& tostring(std::string const& value)
...
@@ -77,6 +78,23 @@ std::string const& tostring(std::string const& value)
return
value
;
return
value
;
}
}
std
::
string
format
(
const
char
*
format_str
,
...
)
{
va_list
args
;
va_start
(
args
,
format_str
);
// get the number of chars to write
va_list
args_tmp
;
va_copy
(
args_tmp
,
args
);
int
char_length
=
std
::
vsnprintf
(
nullptr
,
0
,
format_str
,
args_tmp
);
va_end
(
args_tmp
);
// allocate buffer and store formatted output there
std
::
vector
<
char
>
buffer
(
char_length
+
1
);
// note +1 for null terminator
vsnprintf
(
buffer
.
data
(),
buffer
.
size
(),
format_str
,
args
);
va_end
(
args
);
return
std
::
string
(
buffer
.
data
());
}
}
// end namespace BaseLib
}
// end namespace BaseLib
#ifdef MSVC
#ifdef MSVC
...
...
This diff is collapsed.
Click to expand it.
BaseLib/StringTools.h
+
3
−
0
View file @
537032d2
...
@@ -79,6 +79,9 @@ template<typename T> std::string tostring(T const& value)
...
@@ -79,6 +79,9 @@ template<typename T> std::string tostring(T const& value)
//! \overload
//! \overload
std
::
string
const
&
tostring
(
std
::
string
const
&
value
);
std
::
string
const
&
tostring
(
std
::
string
const
&
value
);
//! returns printf-like formatted string
std
::
string
format
(
const
char
*
format_string
,
...
);
}
// end namespace BaseLib
}
// end namespace BaseLib
#ifdef MSVC
#ifdef MSVC
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment