END_TEST;
}
+
+int UtcDaliScriptingCompareEnums(void)
+{
+ // EQUAL
+ DALI_TEST_CHECK( CompareEnums( "", "" ) );
+ DALI_TEST_CHECK( CompareEnums( "HELLO", "HELLO" ) );
+ DALI_TEST_CHECK( CompareEnums( "HELLO", "hello" ) );
+ DALI_TEST_CHECK( CompareEnums( "hello", "HELLO" ) );
+ DALI_TEST_CHECK( CompareEnums( "hello-world", "HELLO_WORLD" ) );
+ DALI_TEST_CHECK( CompareEnums( "hello_WORLD", "HELLO-world" ) );
+ DALI_TEST_CHECK( CompareEnums( "hello_WORLD-", "HELLO-world_" ) );
+ DALI_TEST_CHECK( CompareEnums( "_hello_WORLD-", "-HELLO-world_" ) );
+ DALI_TEST_CHECK( CompareEnums( "-hello_WORLD-", "_HELLO-world_" ) );
+ DALI_TEST_CHECK( CompareEnums( "hello123", "HELLO123" ) );
+
+ // NOT EQUAL
+ DALI_TEST_CHECK( ! CompareEnums( "hello", "HELLOWORLD" ) );
+
+ END_TEST;
+}
case Dali::Actor::SIZE_MODE:
{
- SetSizeMode( Scripting::GetEnumeration< SizeMode >( property.Get<std::string>(), SIZE_MODE_TABLE, SIZE_MODE_TABLE_COUNT ) );
+ SetSizeMode( Scripting::GetEnumeration< SizeMode >( property.Get<std::string>().c_str(), SIZE_MODE_TABLE, SIZE_MODE_TABLE_COUNT ) );
break;
}
} // unnamed namespace
-bool CompareEnums(const std::string& a, const std::string& b)
+bool CompareEnums( const char * a, const char * b )
{
- std::string::const_iterator ia = a.begin();
- std::string::const_iterator ib = b.begin();
-
- while( (ia != a.end()) && (ib != b.end()) )
+ while( ( *a != '\0' ) && ( *b != '\0' ) )
{
- char ca = *ia;
- char cb = *ib;
+ char ca = *a;
+ char cb = *b;
- if(ca == '-' || ca == '_')
+ if( ( ( ca == '-' ) || ( ca == '_') ) &&
+ ( ( cb == '-' ) || ( cb == '_') ) )
{
- ++ia;
+ ++a;
+ ++b;
continue;
}
- if(cb == '-' || cb == '_')
+ if( ( 'A' <= ca ) && ( ca <= 'Z') )
{
- ++ib;
- continue;
+ ca = ca + ( 'a' - 'A' );
}
- if( 'A' <= ca && ca <= 'Z')
+ if( ( 'A' <= cb ) && ( cb <= 'Z') )
{
- ca = ca + ('a' - 'A');
- }
-
- if( 'A' <= cb && cb <= 'Z')
- {
- cb = cb + ('a' - 'A');
+ cb = cb + ( 'a' - 'A' );
}
if( ca != cb )
return false;
}
- ++ia;
- ++ib;
+ ++a;
+ ++b;
}
- if( (ia == a.end() && ib == b.end() ) )
+ if( ( *a == '\0' ) && ( *b == '\0' ) )
{
return true;
}
- else
- {
- return false;
- }
+ return false;
}
ColorMode GetColorMode( const std::string& value )
{
- return GetEnumeration< ColorMode >( value, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT );
+ return GetEnumeration< ColorMode >( value.c_str(), COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT );
}
PositionInheritanceMode GetPositionInheritanceMode( const std::string& value )
{
- return GetEnumeration< PositionInheritanceMode >( value, POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT );
+ return GetEnumeration< PositionInheritanceMode >( value.c_str(), POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT );
}
DrawMode::Type GetDrawMode( const std::string& value )
{
- return GetEnumeration< DrawMode::Type >( value, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT );
+ return GetEnumeration< DrawMode::Type >( value.c_str(), DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT );
}
Vector3 GetAnchorConstant( const std::string& value )
{
- return GetEnumeration< Vector3 >( value, ANCHOR_CONSTANT_TABLE, ANCHOR_CONSTANT_TABLE_COUNT );
+ return GetEnumeration< Vector3 >( value.c_str(), ANCHOR_CONSTANT_TABLE, ANCHOR_CONSTANT_TABLE_COUNT );
}
{
DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image load-policy property is not a string" );
std::string v(map.GetValue(field).Get<std::string>());
- loadPolicy = GetEnumeration< ResourceImage::LoadPolicy >( v, IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT );
+ loadPolicy = GetEnumeration< ResourceImage::LoadPolicy >( v.c_str(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT );
}
field = "release-policy";
{
DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
std::string v(map.GetValue(field).Get<std::string>());
- releasePolicy = GetEnumeration< Image::ReleasePolicy >( v, IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT );
+ releasePolicy = GetEnumeration< Image::ReleasePolicy >( v.c_str(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT );
}
if( map.HasKey("width") && map.HasKey("height") )
{
DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
std::string s(map.GetValue(field).Get<std::string>());
- attributes.SetPixelFormat( GetEnumeration< Pixel::Format >( s, PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ));
+ attributes.SetPixelFormat( GetEnumeration< Pixel::Format >( s.c_str(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ));
}
field = "scaling-mode";
{
DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
std::string s(map.GetValue(field).Get<std::string>());
- attributes.SetScalingMode( GetEnumeration< ImageAttributes::ScalingMode >( s, IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ) );
+ attributes.SetScalingMode( GetEnumeration< ImageAttributes::ScalingMode >( s.c_str(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ) );
}
if( map.HasKey("type") )
* @brief Permissive comparison for string enums.
*
* Case insensitive and ignores '_', '-' in either string when comparing.
- * If both strings are empty return true; ie like if(a==b) but not like a.compare(b)
- * @param[in] input The input string
- * @param[in] enumString The enum string
- * @return true if the strings are equal as defined above
+ *
+ * @note If both strings are empty return true;
+ *
+ * @param[in] a The first string
+ * @param[in] b The string to compare
+ * @return true if the strings are equal as defined above. If both empty, then return true.
*/
-DALI_IMPORT_API bool CompareEnums(const std::string& input, const std::string& enumString);
+DALI_IMPORT_API bool CompareEnums( const char * a, const char * b );
/**
* @brief Set the value if strings pass a permissive compare.
*
* @param[in] a The input string
- * @param[in] b The input string
+ * @param[in] b The string to compare
* @param[in] set The variable to set
* @param[in] value The value to set
* @return true if the strings pass the permissive compare
*/
template <typename T>
-bool SetIfEqual(const std::string& a, const std::string& b, T& set, T value)
+bool SetIfEqual(const char * a, const char * b, T& set, const T& value)
{
- if( CompareEnums(a, b ) )
+ if( CompareEnums( a, b ) )
{
set = value;
return true;
}
- else
- {
- return false;
- }
+
+ return false;
}
/**
* @return The equivalent enumeration for the given string.
*/
template< typename T >
-T GetEnumeration( const std::string& value, const StringEnum< T >* table, unsigned int tableCount )
+T GetEnumeration( const char * value, const StringEnum< T >* table, unsigned int tableCount )
{
T retVal( table->value );
bool set( false );
* @param[in] table A pointer to an array with the enumeration to string equivalents.
* @param[in] tableCount Number of items in the array.
*
- * @return The equivalent enumeration for the given string.
+ * @return The equivalent enumeration for the given string. Will return NULL if the value does not exist
+ *
+ * @note The caller is NOT responsible for cleaning up the returned pointer as it is statically allocated.
*/
template< typename T >
-std::string GetEnumerationName( T value, const StringEnum< T >* table, unsigned int tableCount )
+const char * GetEnumerationName( T value, const StringEnum< T >* table, unsigned int tableCount )
{
- std::string string( String::EMPTY );
-
for ( unsigned int i = 0; i < tableCount; ++i )
{
if ( value == table[ i ].value )
{
- string = table[ i ].string;
- break;
+ return table[ i ].string;
}
}
- return string;
+ return NULL;
}
/**