The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include "../basics/juce_StandardHeader.h"
  24. BEGIN_JUCE_NAMESPACE
  25. #include "juce_StringPairArray.h"
  26. //==============================================================================
  27. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  28. : ignoreCase (ignoreCase_)
  29. {
  30. }
  31. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  32. : keys (other.keys),
  33. values (other.values),
  34. ignoreCase (other.ignoreCase)
  35. {
  36. }
  37. StringPairArray::~StringPairArray() throw()
  38. {
  39. }
  40. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  41. {
  42. keys = other.keys;
  43. values = other.values;
  44. return *this;
  45. }
  46. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  47. {
  48. for (int i = keys.size(); --i >= 0;)
  49. if (other [keys[i]] != values[i])
  50. return false;
  51. return true;
  52. }
  53. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  54. {
  55. return ! operator== (other);
  56. }
  57. const String& StringPairArray::operator[] (const String& key) const throw()
  58. {
  59. return values [keys.indexOf (key, ignoreCase)];
  60. }
  61. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  62. {
  63. const int i = keys.indexOf (key, ignoreCase);
  64. if (i >= 0)
  65. return values[i];
  66. return defaultReturnValue;
  67. }
  68. void StringPairArray::set (const String& key,
  69. const String& value) throw()
  70. {
  71. const int i = keys.indexOf (key, ignoreCase);
  72. if (i >= 0)
  73. {
  74. values.set (i, value);
  75. }
  76. else
  77. {
  78. keys.add (key);
  79. values.add (value);
  80. }
  81. }
  82. void StringPairArray::addArray (const StringPairArray& other)
  83. {
  84. for (int i = 0; i < other.size(); ++i)
  85. set (other.keys[i], other.values[i]);
  86. }
  87. void StringPairArray::clear() throw()
  88. {
  89. keys.clear();
  90. values.clear();
  91. }
  92. void StringPairArray::remove (const String& key) throw()
  93. {
  94. remove (keys.indexOf (key, ignoreCase));
  95. }
  96. void StringPairArray::remove (const int index) throw()
  97. {
  98. keys.remove (index);
  99. values.remove (index);
  100. }
  101. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  102. {
  103. ignoreCase = shouldIgnoreCase;
  104. }
  105. const String StringPairArray::getDescription() const
  106. {
  107. String s;
  108. for (int i = 0; i < keys.size(); ++i)
  109. {
  110. s << keys[i] << T(" = ") << values[i];
  111. if (i < keys.size())
  112. s << T(", ");
  113. }
  114. return s;
  115. }
  116. void StringPairArray::minimiseStorageOverheads() throw()
  117. {
  118. keys.minimiseStorageOverheads();
  119. values.minimiseStorageOverheads();
  120. }
  121. END_JUCE_NAMESPACE