Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
jami-daemon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
130
Issues
130
List
Boards
Labels
Service Desk
Milestones
Iterations
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
savoirfairelinux
jami-daemon
Commits
18bddb39
Commit
18bddb39
authored
Jul 04, 2019
by
Adrien Béraud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string utils: bring back high precision to_string
Change-Id: I2829c6b42fbebec200b3935aadc62b60498effd0
parent
2353b70d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
src/string_utils.cpp
src/string_utils.cpp
+10
-0
src/string_utils.h
src/string_utils.h
+2
-0
test/unitTest/string_utils/testString_utils.cpp
test/unitTest/string_utils/testString_utils.cpp
+4
-4
No files found.
src/string_utils.cpp
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
)
{
...
...
src/string_utils.h
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
);
...
...
test/unitTest/string_utils/testString_utils.cpp
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'
);
...
...
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