X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fbuilder%2Ftree-node.cpp;h=ef0071d9aefe36c25137898b0f248499989da88b;hp=f8473adf2a910a898a00e151866c0f14ef2a3fb0;hb=66e34be8b6c5d6e9c567e2eea8f4ed0bc9085b4b;hpb=acd889e1216f09643136902ba7a115c2e5589418 diff --git a/dali-toolkit/devel-api/builder/tree-node.cpp b/dali-toolkit/devel-api/builder/tree-node.cpp index f8473ad..ef0071d 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) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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,56 +16,44 @@ */ // EXTERNAL INCLUDES +#include #include -#include #include -#include +#include // INTERNAL INCLUDES #include "dali-toolkit/devel-api/builder/tree-node.h" #include "dali-toolkit/internal/builder/tree-node-manipulator.h" - 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 { - 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 @@ -105,7 +93,7 @@ bool TreeNode::GetBoolean() const size_t TreeNode::Size() const { - size_t c = 0; + size_t c = 0; TreeNode* p = mFirstChild; while(p) { @@ -133,7 +121,7 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const const TreeNode* p = mFirstChild; while(p) { - if(p->mName && (std::string(p->mName) == childName) ) + if(p->mName && (std::string(p->mName) == childName)) { return p; } @@ -142,19 +130,14 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const return NULL; } - const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& 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; } @@ -178,19 +161,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) { @@ -203,7 +184,7 @@ TreeNode::ConstIterator& TreeNode::ConstIterator::operator ++() return *this; } -TreeNode::ConstIterator TreeNode::ConstIterator::operator ++(int) +TreeNode::ConstIterator TreeNode::ConstIterator::operator++(int) { TreeNode::ConstIterator ret(mNode); @@ -218,12 +199,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; }