X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fbuilder%2Ftree-node.cpp;h=571816aa171bd3923e646e476f6cde6a71bcff5d;hb=90168515fb4b80ff64c068769420c0235a225d71;hp=082590573362e8376021eaa73efc2295c9e4fc67;hpb=1d82abb8a1a514ce0af63004706135fb7883f89b;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/devel-api/builder/tree-node.cpp b/dali-toolkit/devel-api/builder/tree-node.cpp index 0825905..571816a 100644 --- a/dali-toolkit/devel-api/builder/tree-node.cpp +++ b/dali-toolkit/devel-api/builder/tree-node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ // EXTERNAL INCLUDES #include #include -#include #include +#include // INTERNAL INCLUDES #include "dali-toolkit/devel-api/builder/tree-node.h" @@ -27,23 +27,14 @@ namespace Dali { -bool CaseInsensitiveCharacterCompare(unsigned char a, unsigned char b) -{ - // Converts to lower case in the current locale. - return std::tolower(a) == std::tolower(b); -} - /** * return true if the lower cased ASCII strings are equal. */ -bool CaseInsensitiveStringCompare(const std::string& a, const std::string& b) +bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b) { - bool result = false; - if(a.length() == b.length()) - { - result = std::equal(a.begin(), a.end(), b.begin(), CaseInsensitiveCharacterCompare); - } - return result; + return (a.length() == b.length()) && std::equal(a.begin(), a.end(), b.begin(), [](auto x, auto y) { + return std::tolower(x) == std::tolower(y); + }); } namespace Toolkit @@ -111,7 +102,7 @@ size_t TreeNode::Size() const return c; } -size_t TreeNode::Count(const std::string& childName) const +size_t TreeNode::Count(std::string_view childName) const { const TreeNode* c = GetChild(childName); if(c) @@ -124,12 +115,12 @@ size_t TreeNode::Count(const std::string& childName) const } } -const TreeNode* TreeNode::GetChild(const std::string& childName) const +const TreeNode* TreeNode::GetChild(std::string_view childName) const { const TreeNode* p = mFirstChild; while(p) { - if(p->mName && (std::string(p->mName) == childName)) + if(p->mName && (std::string_view(p->mName) == childName)) { return p; } @@ -138,27 +129,23 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const return NULL; } -const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& childName) const +const TreeNode* TreeNode::GetChildIgnoreCase(std::string_view childName) const { const TreeNode* p = mFirstChild; while(p) { - if(p->mName) + if(p->mName && CaseInsensitiveStringCompare(p->mName, childName)) { - std::string nodeName(p->mName); - if(CaseInsensitiveStringCompare(nodeName, childName)) - { - return p; - } + return p; } p = p->mNextSibling; } return NULL; } -const TreeNode* TreeNode::Find(const std::string& childName) const +const TreeNode* TreeNode::Find(std::string_view childName) const { - if(mName && std::string(mName) == childName) + if(mName && std::string_view(mName) == childName) { return this; }