Skip to content

Commit

Permalink
Interpret % after numeric string.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed May 31, 2013
1 parent 64299d1 commit 8a436da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/framework/mlt_property.c
Expand Up @@ -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
Expand All @@ -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;
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/tests/test_properties/test_properties.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 8a436da

Please sign in to comment.