Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
savoirfairelinux
jami-daemon
Commits
dc158931
Commit
dc158931
authored
2 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
string utils: add to_int
Change-Id: I8c3ef6c6aee6b326bf917d3bcb8fc53857072cc3
parent
426c064f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/string_utils.h
+16
-0
16 additions, 0 deletions
src/string_utils.h
with
16 additions
and
0 deletions
src/string_utils.h
+
16
−
0
View file @
dc158931
...
...
@@ -27,6 +27,7 @@
#include
<algorithm>
#include
<regex>
#include
<iterator>
#include
<charconv>
#ifdef _WIN32
#include
<WTypes.h>
...
...
@@ -53,6 +54,21 @@ std::string to_string(const std::wstring& wstr, int codePage = CP_UTF8);
std
::
string
to_hex_string
(
uint64_t
id
);
uint64_t
from_hex_string
(
const
std
::
string
&
str
);
template
<
typename
T
>
T
to_int
(
std
::
string_view
str
)
{
T
result
;
auto
[
p
,
ec
]
=
std
::
from_chars
(
str
.
data
(),
str
.
data
()
+
str
.
size
(),
result
);
if
(
ec
==
std
::
errc
())
return
result
;
if
(
ec
==
std
::
errc
::
invalid_argument
)
throw
std
::
invalid_argument
(
"Can't parse integer: invalid_argument"
);
else
if
(
ec
==
std
::
errc
::
result_out_of_range
)
throw
std
::
out_of_range
(
"Can't parse integer: out of range"
);
throw
std
::
system_error
(
std
::
make_error_code
(
ec
));
}
static
inline
int
stoi
(
const
std
::
string
&
str
)
{
...
...
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