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.

145 lines
3.6KB

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