From: Dan Dennedy Date: Mon, 20 May 2013 05:18:39 +0000 (-0700) Subject: Interpret % after numeric string. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=8a436da9938748975aba41a16806f8d9c7936687;p=mlt Interpret % after numeric string. --- diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index fd1659db..7d8808fb 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -432,6 +432,8 @@ int mlt_property_get_int( mlt_property self, double fps, locale_t locale ) * If the string contains a colon it is interpreted as a time value. If it also * contains a period or comma character, the string is parsed as a clock value: * HH:MM:SS. Otherwise, the time value is parsed as a SMPTE timecode: HH:MM:SS:FF. + * If the numeric string ends with '%' then the value is divided by 100 to convert + * it into a ratio. * \private \memberof mlt_property_s * \param value the string to convert * \param fps frames per second, used when converting from time value @@ -449,11 +451,17 @@ static double mlt_property_atof( const char *value, double fps, locale_t locale } else { + char *end = NULL; + double result; #if defined(__GLIBC__) || defined(__DARWIN__) if ( locale ) - return strtod_l( value, NULL, locale ); + result = strtod_l( value, &end, locale ); #endif - return strtod( value, NULL ); + else + result = strtod( value, &end ); + if ( *end && end[0] == '%' ) + result /= 100.0; + return result; } } diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index d496e4c8..206cd694 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -649,6 +649,15 @@ private Q_SLOTS: QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 30, 100), 300); mlt_property_close(p); } + + void PercentAsRatio() + { + Properties p; + p.set("foo", "12.3%"); + QCOMPARE(p.get_double("foo"), 0.123); + p.set("foo", "456 %"); + QCOMPARE(p.get_double("foo"), 456.0); + } }; QTEST_APPLESS_MAIN(TestProperties)