X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Fbuilder-impl.cpp;h=73facc7abe90d43316dab7af147ee961ee683449;hp=7f1b4412f710137b277806e9b998d0f8afb1c9b7;hb=ed980a3b418d7a235d4774b786d84974421650fd;hpb=3b5c91aa5c8ec803487ded2008d6b460530e96ad diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index 7f1b441..73facc7 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -179,10 +179,10 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U } else { - // load configuration map - LoadConfiguration( *parser.GetRoot(), mConfigurationMap ); // load constant map (allows the user to override the constants in the json after loading) LoadConstants( *parser.GetRoot(), mReplacementMap ); + // load configuration map + LoadConfiguration( *parser.GetRoot(), mConfigurationMap ); // merge includes if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) ) { @@ -797,6 +797,61 @@ void Builder::LoadConfiguration( const TreeNode& root, Property::Map& intoMap ) if( (*iter).second.GetName() ) { DeterminePropertyFromNode( (*iter).second, property, replacer ); + + // If config is string, find constant and replace it to original value. + if( (*iter).second.GetType() == TreeNode::STRING ) + { + std::string stringConfigValue; + if( property.Get( stringConfigValue ) ) + { + std::size_t pos = 0; + + while( pos < stringConfigValue.size() ) + { + // If we can't find "{","}" pair in stringConfigValue, will out loop. + std::size_t leftPos = stringConfigValue.find( "{", pos ); + if( leftPos != std::string::npos ) + { + std::size_t rightPos = stringConfigValue.find( "}", pos+1 ); + + if( rightPos != std::string::npos ) + { + // If we find "{","}" pair but can't find matched constant + // try to find other "{","}" pair after current left position. + pos = leftPos+1; + + for( uint32_t i = 0; i < mReplacementMap.Count() ; i++ ) + { + Property::Key constant = mReplacementMap.GetKeyAt(i); + + // Compare string which is between "{" and "}" with constant string + // If they are same, change string in stringConfigValue to mapped constant value. + if ( 0 == stringConfigValue.compare( leftPos+1, rightPos-leftPos-1, constant.stringKey ) ) + { + std::string replaceString; + mReplacementMap.GetValue(i).Get( replaceString ); + + stringConfigValue.replace( leftPos, rightPos-leftPos+1, replaceString ); + pos = leftPos + replaceString.size(); + break; + } + } + } + else + { + // If we cannot find constant in const value, will out loop. + pos = stringConfigValue.size(); + } + } + else + { + // If we cannot find constant in const value, will out loop. + pos = stringConfigValue.size(); + } + } + property = Property::Value( stringConfigValue ); + } + } intoMap[ (*iter).second.GetName() ] = property; } }