2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/demangler.h>
22 #include <dali/public-api/common/vector-wrapper.h>
27 // true if character represent a digit
28 inline bool IsDigit(char c)
30 return (c >= '0' && c <= '9');
33 // Gets the number of characters (number is in string)
34 // start The start position to look for a number
35 // result The number as an integer
36 // returns the number of characters used to define the number ie '12' is 2
37 size_t GetNumberOfCharacters(const std::string& s, const size_t& start, int& result)
39 size_t size = s.size();
45 for( ; i < size; ++i )
54 number = 10 * number + (c - '0');
67 * @brief Demangle a nested typeid name into its component parts.
68 * A nested type name is one containing namespaces and class names only.
69 * eg DemangleNestedNames(typeid(Dali::Actor).name());
70 * @param[in] typeIdName The type id name string to demangle.
71 * @returns the demangled list of names ie ["Dali","Actor"] or an empty list
73 std::vector<std::string> DemangleNestedNames(const char *typeIdName)
75 // Demangle class name mangled according to the Itanium C++ ABI
76 // Returns demangled names ie "N4Dali8Internal5ActorE" is ["Dali","Internal","Actor"]
77 std::vector<std::string> ret;
79 const std::string mangledName(typeIdName);
82 size_t size = mangledName.size();
89 // If the class isnt nested in a namespace then it just starts with the
90 // number of characters
91 if(mangledName[0] == 'N' && mangledName[size-1] == 'E')
96 while( size_t chars = GetNumberOfCharacters(mangledName, start, number) )
98 ret.push_back( mangledName.substr( start + chars, number ) );
100 start += chars + number;
115 const std::string DemangleClassName(const char *typeIdName)
118 std::vector<std::string> names = DemangleNestedNames(typeIdName);
122 name = names[ names.size() - 1 ];
128 } // namespace Internal