X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fbuilder%2Ftree-node.cpp;h=571816aa171bd3923e646e476f6cde6a71bcff5d;hb=3890e8d5e0d6c13b7a20538b0de12125946f6d87;hp=302c7a2cc7e497481bafe00a821c07c9ab91df03;hpb=9d09b345fbdef7a0532f5b45ffe65754f87258c6;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 302c7a2..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) 2015 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. @@ -16,7 +16,10 @@ */ // EXTERNAL INCLUDES -#include +#include +#include +#include +#include // INTERNAL INCLUDES #include "dali-toolkit/devel-api/builder/tree-node.h" @@ -24,25 +27,32 @@ namespace Dali { +/** + * return true if the lower cased ASCII strings are equal. + */ +bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b) +{ + 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 { - TreeNode::TreeNode() - : mName(NULL), - mParent(NULL), - mNextSibling(NULL), - mFirstChild(NULL), - mLastChild(NULL), - mStringValue(NULL), - mType(TreeNode::IS_NULL), - mSubstituion(false) +: mName(NULL), + mParent(NULL), + mNextSibling(NULL), + mFirstChild(NULL), + mLastChild(NULL), + mStringValue(NULL), + mType(TreeNode::IS_NULL), + mSubstituion(false) { } TreeNode::~TreeNode() { - } const char* TreeNode::GetName() const @@ -80,10 +90,9 @@ bool TreeNode::GetBoolean() const return mIntValue == 1 ? true : false; } - size_t TreeNode::Size() const { - size_t c = 0; + size_t c = 0; TreeNode* p = mFirstChild; while(p) { @@ -93,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) @@ -106,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; } @@ -120,9 +129,23 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const return NULL; } -const TreeNode* TreeNode::Find(const std::string& childName) const +const TreeNode* TreeNode::GetChildIgnoreCase(std::string_view childName) const { - if(mName && std::string(mName) == childName) + const TreeNode* p = mFirstChild; + while(p) + { + if(p->mName && CaseInsensitiveStringCompare(p->mName, childName)) + { + return p; + } + p = p->mNextSibling; + } + return NULL; +} + +const TreeNode* TreeNode::Find(std::string_view childName) const +{ + if(mName && std::string_view(mName) == childName) { return this; } @@ -137,19 +160,17 @@ TreeNode::ConstIterator TreeNode::CBegin() const return ConstIterator(mFirstChild); } - TreeNode::ConstIterator TreeNode::CEnd() const { return ConstIterator(NULL); } - -TreeNode::ConstIterator::ConstIterator(TreeNode* v) : mNode(v) +TreeNode::ConstIterator::ConstIterator(TreeNode* v) +: mNode(v) { - } -TreeNode::ConstIterator& TreeNode::ConstIterator::operator ++() +TreeNode::ConstIterator& TreeNode::ConstIterator::operator++() { if(mNode) { @@ -162,7 +183,7 @@ TreeNode::ConstIterator& TreeNode::ConstIterator::operator ++() return *this; } -TreeNode::ConstIterator TreeNode::ConstIterator::operator ++(int) +TreeNode::ConstIterator TreeNode::ConstIterator::operator++(int) { TreeNode::ConstIterator ret(mNode); @@ -177,12 +198,12 @@ TreeNode::ConstIterator TreeNode::ConstIterator::operator ++(int) return ret; } -TreeNode::KeyNodePair TreeNode::ConstIterator::operator *() +TreeNode::KeyNodePair TreeNode::ConstIterator::operator*() { return KeyNodePair(mNode->mName, *mNode); } -bool TreeNode::ConstIterator::operator!=( const TreeNode::ConstIterator& rhs ) const +bool TreeNode::ConstIterator::operator!=(const TreeNode::ConstIterator& rhs) const { return mNode != rhs.mNode; }