Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alexander Lapshin
common
Commits
5f6d7696
Commit
5f6d7696
authored
May 06, 2020
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
303a6372
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
38 deletions
+40
-38
TextFunctions.h
utils/TextFunctions.h
+40
-38
No files found.
utils/TextFunctions.h
View file @
5f6d7696
...
...
@@ -20,7 +20,7 @@
static
std
::
string
ToStr
(
const
int
arg
,
const
int
leading_zeros
)
{
std
::
ostringstream
ss
;
if
(
leading_zeros
)
{
if
(
leading_zeros
)
{
ss
<<
std
::
setw
(
leading_zeros
)
<<
std
::
setfill
(
'0'
);
}
ss
<<
arg
;
...
...
@@ -37,7 +37,7 @@ static std::string ToStr(const size_t arg, const int leading_zeros)
return
ss
.
str
();
}
template
<
typename
T
>
template
<
typename
T
>
void
hangle_to_chars_error
(
const
std
::
to_chars_result
&
res
,
const
T
&
arg
)
{
if
(
res
.
ec
==
std
::
errc
::
invalid_argument
)
{
...
...
@@ -51,37 +51,18 @@ void hangle_to_chars_error(const std::to_chars_result& res, const T& arg)
throw
Exp
()
<<
"failed to convert value ["
<<
arg
<<
"] to string"
;
}
static
std
::
string
ToStr
(
const
int
arg
)
{
std
::
array
<
char
,
32
>
buf
;
const
auto
res
=
std
::
to_chars
(
buf
.
data
(),
buf
.
data
()
+
buf
.
size
(),
arg
);
if
(
res
.
ec
==
std
::
errc
())
{
return
std
::
string
(
buf
.
data
(),
res
.
ptr
-
buf
.
data
());
}
hangle_to_chars_error
(
res
,
arg
);
return
""
;
}
static
std
::
string
ToStr
(
const
size_t
arg
)
static
std
::
string
ToStr
(
const
double
value
,
const
int
precision
=
0
)
{
std
::
array
<
char
,
32
>
buf
;
const
auto
res
=
std
::
to_chars
(
buf
.
data
(),
buf
.
data
()
+
buf
.
size
(),
arg
);
if
(
res
.
ec
==
std
::
errc
())
{
return
std
::
string
(
buf
.
data
(),
res
.
ptr
-
buf
.
data
());
std
::
ostringstream
ss
;
if
(
precision
)
{
ss
<<
std
::
setprecision
(
precision
);
}
hangle_to_chars_error
(
res
,
arg
);
return
""
;
ss
<<
value
;
return
ss
.
str
();
}
static
std
::
string
ToStr
(
const
double
arg
)
template
<
typename
T
>
static
std
::
string
ToStr
(
const
T
arg
)
{
std
::
array
<
char
,
32
>
buf
;
...
...
@@ -96,13 +77,35 @@ static std::string ToStr(const double arg)
return
""
;
}
static
std
::
string
ToStr
(
const
double
value
,
const
int
precision
)
{
std
::
ostringstream
ss
;
ss
<<
std
::
setprecision
(
precision
);
ss
<<
value
;
return
ss
.
str
();
}
// static std::string ToStr(const size_t arg)
// {
// std::array<char, 32> buf;
//
// const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
//
// if (res.ec == std::errc()) {
// return std::string(buf.data(), res.ptr - buf.data());
// }
//
// hangle_to_chars_error(res, arg);
//
// return "";
// }
//
// static std::string ToStr(const double arg)
// {
// std::array<char, 32> buf;
//
// const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
//
// if (res.ec == std::errc()) {
// return std::string(buf.data(), res.ptr - buf.data());
// }
//
// hangle_to_chars_error(res, arg);
//
// return "";
// }
static
void
string_replace
(
std
::
string
&
str
,
const
std
::
string
&
from
,
const
std
::
string
&
to
)
{
...
...
@@ -397,7 +400,7 @@ std::vector<T> map_keys(const std::map<T, T2>& map)
std
::
vector
<
T
>
result
;
result
.
reserve
(
map
.
size
());
for
(
const
auto
&
it
:
map
)
{
for
(
const
auto
&
it
:
map
)
{
result
.
push_back
(
it
.
first
);
}
...
...
@@ -425,4 +428,3 @@ bool in_array(const std::vector<T>& src, T subject)
{
return
std
::
find
(
std
::
begin
(
src
),
std
::
end
(
src
),
subject
)
!=
std
::
end
(
src
);
}
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