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.

146 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. namespace juce
  18. {
  19. StringPairArray::StringPairArray (bool shouldIgnoreCase) : ignoreCase (shouldIgnoreCase)
  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[] (StringRef key) const
  49. {
  50. return values [keys.indexOf (key, ignoreCase)];
  51. }
  52. String StringPairArray::getValue (StringRef 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. bool StringPairArray::containsKey (StringRef key) const noexcept
  60. {
  61. return keys.contains (key);
  62. }
  63. void StringPairArray::set (const String& key, const String& value)
  64. {
  65. const int i = keys.indexOf (key, ignoreCase);
  66. if (i >= 0)
  67. {
  68. values.set (i, value);
  69. }
  70. else
  71. {
  72. keys.add (key);
  73. values.add (value);
  74. }
  75. }
  76. void StringPairArray::addArray (const StringPairArray& other)
  77. {
  78. for (int i = 0; i < other.size(); ++i)
  79. set (other.keys[i], other.values[i]);
  80. }
  81. void StringPairArray::clear()
  82. {
  83. keys.clear();
  84. values.clear();
  85. }
  86. void StringPairArray::remove (StringRef key)
  87. {
  88. remove (keys.indexOf (key, ignoreCase));
  89. }
  90. void StringPairArray::remove (const int index)
  91. {
  92. keys.remove (index);
  93. values.remove (index);
  94. }
  95. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  96. {
  97. ignoreCase = shouldIgnoreCase;
  98. }
  99. String StringPairArray::getDescription() const
  100. {
  101. String s;
  102. for (int i = 0; i < keys.size(); ++i)
  103. {
  104. s << keys[i] << " = " << values[i];
  105. if (i < keys.size())
  106. s << ", ";
  107. }
  108. return s;
  109. }
  110. void StringPairArray::minimiseStorageOverheads()
  111. {
  112. keys.minimiseStorageOverheads();
  113. values.minimiseStorageOverheads();
  114. }
  115. } // namespace juce