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
18bddb39
Commit
18bddb39
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
string utils: bring back high precision to_string
Change-Id: I2829c6b42fbebec200b3935aadc62b60498effd0
parent
2353b70d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/string_utils.cpp
+10
-0
10 additions, 0 deletions
src/string_utils.cpp
src/string_utils.h
+2
-0
2 additions, 0 deletions
src/string_utils.h
test/unitTest/string_utils/testString_utils.cpp
+4
-4
4 additions, 4 deletions
test/unitTest/string_utils/testString_utils.cpp
with
16 additions
and
4 deletions
src/string_utils.cpp
+
10
−
0
View file @
18bddb39
...
...
@@ -70,6 +70,16 @@ bstrToStdString(BSTR bstr)
}
#endif
std
::
string
to_string
(
double
value
)
{
char
buf
[
64
];
int
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%-.*G"
,
16
,
value
);
if
(
len
<=
0
)
throw
std
::
invalid_argument
{
"can't parse double"
};
return
{
buf
,
(
size_t
)
len
};
}
std
::
string
trim
(
const
std
::
string
&
s
)
{
...
...
This diff is collapsed.
Click to expand it.
src/string_utils.h
+
2
−
0
View file @
18bddb39
...
...
@@ -39,6 +39,8 @@ bool_to_str(bool b) noexcept
return
b
?
TRUE_STR
:
FALSE_STR
;
}
std
::
string
to_string
(
double
value
);
#ifdef _WIN32
std
::
wstring
to_wstring
(
const
std
::
string
&
s
);
std
::
string
decodeMultibyteString
(
const
std
::
string
&
s
);
...
...
This diff is collapsed.
Click to expand it.
test/unitTest/string_utils/testString_utils.cpp
+
4
−
4
View file @
18bddb39
...
...
@@ -45,9 +45,9 @@ private:
CPPUNIT_TEST
(
split_string_test
);
CPPUNIT_TEST_SUITE_END
();
const
double
DOUBLE
=
3.14159
3
;
const
double
DOUBLE
=
3.14159
265359
;
const
int
INT
=
42
;
const
std
::
string
PI_DOUBLE
=
"3.14159
3
"
;
const
std
::
string
PI_DOUBLE
=
"3.14159
265359
"
;
const
std
::
string
PI_FLOAT
=
"3.14159265359"
;
const
std
::
string
PI_42
=
"42"
;
};
...
...
@@ -65,11 +65,11 @@ void
StringUtilsTest
::
to_string_test
()
{
// test with double
CPPUNIT_ASSERT
(
std
::
to_string
(
DOUBLE
)
==
PI_DOUBLE
);
CPPUNIT_ASSERT
(
to_string
(
DOUBLE
)
==
PI_DOUBLE
);
// test with float
float
varFloat
=
3.14
;
std
::
string
sVarFloat
=
std
::
to_string
(
varFloat
);
std
::
string
sVarFloat
=
to_string
(
varFloat
);
CPPUNIT_ASSERT
(
sVarFloat
.
at
(
0
)
==
'3'
&&
sVarFloat
.
at
(
1
)
==
'.'
&&
sVarFloat
.
at
(
2
)
==
'1'
&&
sVarFloat
.
at
(
3
)
==
'4'
);
...
...
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