Adds % unit to float field trial parser.

This can improve readability in some situations and prevents the need
to define a parameter as some_value_in_percent.

Bug: webrtc:9510
Change-Id: I0959d2b6c463f1bc1cea8e66f0bd5b56380b8c03
Reviewed-on: https://webrtc-review.googlesource.com/97302
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24538}
This commit is contained in:
Sebastian Jansson
2018-09-03 11:31:26 +02:00
committed by Commit Bot
parent 5dd6167908
commit ec76466da2
2 changed files with 13 additions and 1 deletions

View File

@ -82,7 +82,10 @@ absl::optional<bool> ParseTypedParameter<bool>(std::string str) {
template <>
absl::optional<double> ParseTypedParameter<double>(std::string str) {
double value;
if (sscanf(str.c_str(), "%lf", &value) == 1) {
char unit[2]{0, 0};
if (sscanf(str.c_str(), "%lf%1s", &value, unit) >= 1) {
if (unit[0] == '%')
return value / 100;
return value;
} else {
return absl::nullopt;