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.

142 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. StringPairArray::StringPairArray (const bool ignoreCase_)
  18. : ignoreCase (ignoreCase_)
  19. {
  20. }
  21. StringPairArray::StringPairArray (const StringPairArray& other)
  22. : keys (other.keys),
  23. values (other.values),
  24. ignoreCase (other.ignoreCase)
  25. {
  26. }
  27. StringPairArray::~StringPairArray()
  28. {
  29. }
  30. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  31. {
  32. keys = other.keys;
  33. values = other.values;
  34. return *this;
  35. }
  36. bool StringPairArray::operator== (const StringPairArray& other) const
  37. {
  38. for (int i = keys.size(); --i >= 0;)
  39. if (other [keys[i]] != values[i])
  40. return false;
  41. return true;
  42. }
  43. bool StringPairArray::operator!= (const StringPairArray& other) const
  44. {
  45. return ! operator== (other);
  46. }
  47. const String& StringPairArray::operator[] (StringRef key) const
  48. {
  49. return values [keys.indexOf (key, ignoreCase)];
  50. }
  51. String StringPairArray::getValue (StringRef key, const String& defaultReturnValue) const
  52. {
  53. const int i = keys.indexOf (key, ignoreCase);
  54. if (i >= 0)
  55. return values[i];
  56. return defaultReturnValue;
  57. }
  58. bool StringPairArray::containsKey (StringRef key) const noexcept
  59. {
  60. return keys.contains (key);
  61. }
  62. void StringPairArray::set (const String& key, const String& value)
  63. {
  64. const int i = keys.indexOf (key, ignoreCase);
  65. if (i >= 0)
  66. {
  67. values.set (i, value);
  68. }
  69. else
  70. {
  71. keys.add (key);
  72. values.add (value);
  73. }
  74. }
  75. void StringPairArray::addArray (const StringPairArray& other)
  76. {
  77. for (int i = 0; i < other.size(); ++i)
  78. set (other.keys[i], other.values[i]);
  79. }
  80. void StringPairArray::clear()
  81. {
  82. keys.clear();
  83. values.clear();
  84. }
  85. void StringPairArray::remove (StringRef key)
  86. {
  87. remove (keys.indexOf (key, ignoreCase));
  88. }
  89. void StringPairArray::remove (const int index)
  90. {
  91. keys.remove (index);
  92. values.remove (index);
  93. }
  94. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  95. {
  96. ignoreCase = shouldIgnoreCase;
  97. }
  98. String StringPairArray::getDescription() const
  99. {
  100. String s;
  101. for (int i = 0; i < keys.size(); ++i)
  102. {
  103. s << keys[i] << " = " << values[i];
  104. if (i < keys.size())
  105. s << ", ";
  106. }
  107. return s;
  108. }
  109. void StringPairArray::minimiseStorageOverheads()
  110. {
  111. keys.minimiseStorageOverheads();
  112. values.minimiseStorageOverheads();
  113. }