2 * Copyright (c) 2021 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 <string_view>
22 #include <dali/internal/event/common/demangler.h>
26 // Extracts the number from the src view and update the view.
27 size_t ExtractNumber(std::string_view& src)
29 auto IsDigit = [](char c) { return (c >= '0' && c <= '9'); };
32 for(auto i = 0u; i < src.size(); ++i)
37 //update the src view.
43 number = 10 * number + (c - '0');
51 * @brief Demangle a nested typeid name into its component parts and return
53 * A nested type name is one containing namespaces and class names only.
54 * eg ExtractDemangleNestedName(typeid(Dali::Actor).name());
55 * @param[in] typeIdName The type id name string to demangle.
56 * @returns the last component "Actor" or an empty string_view
58 std::string_view ExtractDemangleNestedName(std::string_view mangledName)
60 if(mangledName.empty())
65 // classes nested inside a namespace starts with 'N' and ends with 'E'
67 if(mangledName.front() == 'N' && mangledName.back() == 'E')
69 mangledName.remove_prefix(1);
70 mangledName.remove_suffix(1);
73 std::string_view result;
74 while(!mangledName.empty())
76 auto length = ExtractNumber(mangledName);
77 result = {mangledName.data(), length};
78 mangledName.remove_prefix(length);
90 std::string DemangleClassName(const char* typeIdName)
92 return std::string(ExtractDemangleNestedName(typeIdName));
95 } // namespace Internal