1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "wukong_tree.h" 17 18namespace OHOS { 19namespace WuKong { 20bool WuKongTree::RecursUpdateNodeIndex(const uint32_t offset) 21{ 22 index_ = index_ + offset; 23 for (auto child : children_) { 24 child->RecursUpdateNodeIndex(offset); 25 } 26 return true; 27} 28uint64_t WuKongTree::GetSubName(std::string name, uint32_t count, bool isAbility) 29{ 30 TRACK_LOG_STR("name %s", name.c_str()); 31 const uint8_t heightPosion = 8; 32 uint64_t subName = 0; 33 uint32_t nameSize = name.size(); 34 if (isAbility) { 35 GetClearnAbility(name); 36 nameSize = name.size(); 37 for (uint32_t index = count; index > 0; index--) { 38 if (index > nameSize) { 39 continue; 40 } 41 subName |= name[nameSize - index]; 42 if (index > 1) { 43 subName = subName << heightPosion; 44 } 45 } 46 } else { 47 for (uint32_t index = count; index > 0; index--) { 48 if (index > nameSize) { 49 continue; 50 } 51 subName |= name[nameSize - index]; 52 if (index > 1) { 53 subName = subName << heightPosion; 54 } 55 } 56 } 57 return subName; 58} 59void WuKongTree::GetClearnAbility(std::string &name) 60{ 61 std::string target = "Ability"; 62 std::string replacement = ""; 63 size_t pos = name.find(target); 64 while (pos != std::string::npos) { 65 name.replace(pos, target.length(), replacement); 66 pos = name.find(target, pos + replacement.length()); 67 } 68} 69} // namespace WuKong 70} // namespace OHOS