]> git.sesse.net Git - mlt/commitdiff
Interpret % after numeric string.
authorDan Dennedy <dan@dennedy.org>
Mon, 20 May 2013 05:18:39 +0000 (22:18 -0700)
committerDan Dennedy <dan@dennedy.org>
Fri, 31 May 2013 23:58:12 +0000 (16:58 -0700)
src/framework/mlt_property.c
src/tests/test_properties/test_properties.cpp

index fd1659dbf07cb90dffbcbd540cadf8ceb6b39f7b..7d8808fb53d46e34f61584ff81ee6a513e09bc83 100644 (file)
@@ -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;
        }
 }
 
index d496e4c84cc35986a82d85b52277f6ee5d180372..206cd6943f12e1b8580dfc100e97d1a3e653826e 100644 (file)
@@ -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)