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.

140 lines
3.4KB

  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. StringPairArray::StringPairArray (const bool ignoreCase_)
  19. : ignoreCase (ignoreCase_)
  20. {
  21. }
  22. StringPairArray::StringPairArray (const StringPairArray& other)
  23. : keys (other.keys),
  24. values (other.values),
  25. ignoreCase (other.ignoreCase)
  26. {
  27. }
  28. StringPairArray::~StringPairArray()
  29. {
  30. }
  31. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  32. {
  33. keys = other.keys;
  34. values = other.values;
  35. return *this;
  36. }
  37. bool StringPairArray::operator== (const StringPairArray& other) const
  38. {
  39. for (int i = keys.size(); --i >= 0;)
  40. if (other [keys[i]] != values[i])
  41. return false;
  42. return true;
  43. }
  44. bool StringPairArray::operator!= (const StringPairArray& other) const
  45. {
  46. return ! operator== (other);
  47. }
  48. const String& StringPairArray::operator[] (const String& key) const
  49. {
  50. return values [keys.indexOf (key, ignoreCase)];
  51. }
  52. String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  53. {
  54. const int i = keys.indexOf (key, ignoreCase);
  55. if (i >= 0)
  56. return values[i];
  57. return defaultReturnValue;
  58. }
  59. void StringPairArray::set (const String& key, const String& value)
  60. {
  61. const int i = keys.indexOf (key, ignoreCase);
  62. if (i >= 0)
  63. {
  64. values.set (i, value);
  65. }
  66. else
  67. {
  68. keys.add (key);
  69. values.add (value);
  70. }
  71. }
  72. void StringPairArray::addArray (const StringPairArray& other)
  73. {
  74. for (int i = 0; i < other.size(); ++i)
  75. set (other.keys[i], other.values[i]);
  76. }
  77. void StringPairArray::clear()
  78. {
  79. keys.clear();
  80. values.clear();
  81. }
  82. void StringPairArray::remove (const String& key)
  83. {
  84. remove (keys.indexOf (key, ignoreCase));
  85. }
  86. void StringPairArray::remove (const int index)
  87. {
  88. keys.remove (index);
  89. values.remove (index);
  90. }
  91. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  92. {
  93. ignoreCase = shouldIgnoreCase;
  94. }
  95. String StringPairArray::getDescription() const
  96. {
  97. String s;
  98. for (int i = 0; i < keys.size(); ++i)
  99. {
  100. s << keys[i] << " = " << values[i];
  101. if (i < keys.size())
  102. s << ", ";
  103. }
  104. return s;
  105. }
  106. void StringPairArray::minimiseStorageOverheads()
  107. {
  108. keys.minimiseStorageOverheads();
  109. values.minimiseStorageOverheads();
  110. }