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.

150 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. StringPairArray::StringPairArray (const bool ignoreCase_)
  24. : ignoreCase (ignoreCase_)
  25. {
  26. }
  27. StringPairArray::StringPairArray (const StringPairArray& other)
  28. : keys (other.keys),
  29. values (other.values),
  30. ignoreCase (other.ignoreCase)
  31. {
  32. }
  33. StringPairArray::~StringPairArray()
  34. {
  35. }
  36. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  37. {
  38. keys = other.keys;
  39. values = other.values;
  40. return *this;
  41. }
  42. bool StringPairArray::operator== (const StringPairArray& other) const
  43. {
  44. for (int i = keys.size(); --i >= 0;)
  45. if (other [keys[i]] != values[i])
  46. return false;
  47. return true;
  48. }
  49. bool StringPairArray::operator!= (const StringPairArray& other) const
  50. {
  51. return ! operator== (other);
  52. }
  53. const String& StringPairArray::operator[] (StringRef key) const
  54. {
  55. return values [keys.indexOf (key, ignoreCase)];
  56. }
  57. String StringPairArray::getValue (StringRef key, const String& defaultReturnValue) const
  58. {
  59. const int i = keys.indexOf (key, ignoreCase);
  60. if (i >= 0)
  61. return values[i];
  62. return defaultReturnValue;
  63. }
  64. bool StringPairArray::containsKey (StringRef key) const noexcept
  65. {
  66. return keys.contains (key);
  67. }
  68. void StringPairArray::set (const String& key, const String& value)
  69. {
  70. const int i = keys.indexOf (key, ignoreCase);
  71. if (i >= 0)
  72. {
  73. values.set (i, value);
  74. }
  75. else
  76. {
  77. keys.add (key);
  78. values.add (value);
  79. }
  80. }
  81. void StringPairArray::addArray (const StringPairArray& other)
  82. {
  83. for (int i = 0; i < other.size(); ++i)
  84. set (other.keys[i], other.values[i]);
  85. }
  86. void StringPairArray::clear()
  87. {
  88. keys.clear();
  89. values.clear();
  90. }
  91. void StringPairArray::remove (StringRef key)
  92. {
  93. remove (keys.indexOf (key, ignoreCase));
  94. }
  95. void StringPairArray::remove (const int index)
  96. {
  97. keys.remove (index);
  98. values.remove (index);
  99. }
  100. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  101. {
  102. ignoreCase = shouldIgnoreCase;
  103. }
  104. String StringPairArray::getDescription() const
  105. {
  106. String s;
  107. for (int i = 0; i < keys.size(); ++i)
  108. {
  109. s << keys[i] << " = " << values[i];
  110. if (i < keys.size())
  111. s << ", ";
  112. }
  113. return s;
  114. }
  115. void StringPairArray::minimiseStorageOverheads()
  116. {
  117. keys.minimiseStorageOverheads();
  118. values.minimiseStorageOverheads();
  119. }