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
46 * Helper to resolve URL type from the string
47 * @param[in] url to check
50 inline UrlType::Type ResolveUrlType( const std::string& url )
52 // if only one char in string, can only be regular image
53 const std::size_t count = url.size();
56 // parsing from the end for better chance of early outs
57 enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX;
58 char SVG[ 4 ] = { 'g', 'v', 's', '.' };
59 char GIF[ 4 ] = { 'f', 'i', 'g', '.' };
60 unsigned int svgScore = 0;
61 unsigned int gifScore = 0;
65 const char currentChar = url[ index ];
66 const std::size_t offsetFromEnd = count - index - 1u;
67 if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) )
69 // early out if SVG as can't be used in N patch for now
70 if( ++svgScore == sizeof(SVG) )
75 if( ( offsetFromEnd < sizeof(GIF) )&&( tolower( currentChar ) == GIF[ offsetFromEnd ] ) )
78 if( ++gifScore == sizeof(GIF) )
87 if( '.' == currentChar )
95 if( ( '#' == currentChar ) || ( '9' == currentChar ) )
101 // early out, not a valid N/9-patch URL
102 return UrlType::REGULAR_IMAGE;
108 if( '.' == currentChar )
110 return UrlType::N_PATCH;
114 // early out, not a valid N/9-patch URL
115 return UrlType::REGULAR_IMAGE;
122 // if we got here it is a regular image
123 return UrlType::REGULAR_IMAGE;
126 } // namespace Internal
128 } // namespace Toolkit
132 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H */