1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
34 * The type of the URL based on the string contents
45 * Helper to resolve URL type from the string
46 * @param[in] url to check
49 inline UrlType::Type ResolveUrlType( const std::string& url )
51 // if only one char in string, can only be regular image
52 const std::size_t count = url.size();
55 // parsing from the end for better chance of early outs
56 enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX;
57 char SVG[ 4 ] = { 'g', 'v', 's', '.' };
58 unsigned int svgScore = 0;
62 const char currentChar = url[ index ];
63 const std::size_t offsetFromEnd = count - index - 1u;
64 if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) )
66 // early out if SVG as can't be used in N patch for now
67 if( ++svgScore == sizeof(SVG) )
76 if( '.' == currentChar )
84 if( ( '#' == currentChar ) || ( '9' == currentChar ) )
90 // early out, not a valid N/9-patch URL
91 return UrlType::REGULAR_IMAGE;
97 if( '.' == currentChar )
99 return UrlType::N_PATCH;
103 // early out, not a valid N/9-patch URL
104 return UrlType::REGULAR_IMAGE;
111 // if we got here it is a regular image
112 return UrlType::REGULAR_IMAGE;
115 } // namespace Internal
117 } // namespace Toolkit
121 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H */