Updating Builder and Control to handle styled States
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / builder / tree-node.cpp
index 3ecb1d5..3d9eed7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
 
 // EXTERNAL INCLUDES
 #include <cstring>
+#include <algorithm>
 
 // 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 result = false;
+  if( a.length() == b.length() )
+  {
+    result = std::equal( a.begin(), a.end(), b.begin(), CaseInsensitiveCharacterCompare );
+  }
+  return result;
+}
+
 namespace Toolkit
 {
 
@@ -80,7 +101,6 @@ bool TreeNode::GetBoolean() const
   return mIntValue == 1 ? true : false;
 }
 
-
 size_t TreeNode::Size() const
 {
   size_t c = 0;
@@ -120,6 +140,25 @@ 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)
+    {
+      std::string nodeName(p->mName);
+      if( CaseInsensitiveStringCompare( nodeName, childName) )
+      {
+        return p;
+      }
+    }
+    p = p->mNextSibling;
+  }
+  return NULL;
+}
+
 const TreeNode* TreeNode::Find(const std::string& childName) const
 {
   if(mName && std::string(mName) == childName)
@@ -182,11 +221,6 @@ TreeNode::KeyNodePair TreeNode::ConstIterator::operator *()
   return KeyNodePair(mNode->mName, *mNode);
 }
 
-TreeNode::KeyNodePair TreeNode::ConstIterator::operator ->()
-{
-  return KeyNodePair(mNode->mName, *mNode);
-}
-
 bool TreeNode::ConstIterator::operator!=( const TreeNode::ConstIterator& rhs ) const
 {
   return mNode != rhs.mNode;
@@ -195,4 +229,3 @@ bool TreeNode::ConstIterator::operator!=( const TreeNode::ConstIterator& rhs ) c
 } // namespace Toolkit
 
 } // namespace Dali
-