OpenShot Audio Library | OpenShotAudio: juce_StringPairArray.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_StringPairArray.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26StringPairArray::StringPairArray (bool shouldIgnoreCase) : ignoreCase (shouldIgnoreCase)
27{
28}
29
30 StringPairArray::StringPairArray (const StringPairArray& other)
31 : keys (other.keys),
32 values (other.values),
33 ignoreCase (other.ignoreCase)
34{
35}
36
37StringPairArray::~StringPairArray()
38{
39}
40
41 StringPairArray& StringPairArray::operator= (const StringPairArray& other)
42{
43 keys = other.keys;
44 values = other.values;
45 return *this;
46}
47
48 bool StringPairArray::operator== (const StringPairArray& other) const
49{
50 auto num = size();
51
52 if (num != other.size())
53 return false;
54
55 for (int i = 0; i < num; ++i)
56 {
57 if (keys[i] == other.keys[i]) // optimise for the case where the keys are in the same order
58 {
59 if (values[i] != other.values[i])
60 return false;
61 }
62 else
63 {
64 // if we encounter keys that are in a different order, search remaining items by brute force..
65 for (int j = i; j < num; ++j)
66 {
67 auto otherIndex = other.keys.indexOf (keys[j], other.ignoreCase);
68
69 if (otherIndex < 0 || values[j] != other.values[otherIndex])
70 return false;
71 }
72
73 return true;
74 }
75 }
76
77 return true;
78}
79
80 bool StringPairArray::operator!= (const StringPairArray& other) const
81{
82 return ! operator== (other);
83}
84
85 const String& StringPairArray::operator[] (StringRef key) const
86{
87 return values[keys.indexOf (key, ignoreCase)];
88}
89
90 String StringPairArray::getValue (StringRef key, const String& defaultReturnValue) const
91{
92 auto i = keys.indexOf (key, ignoreCase);
93
94 if (i >= 0)
95 return values[i];
96
97 return defaultReturnValue;
98}
99
100 bool StringPairArray::containsKey (StringRef key) const noexcept
101{
102 return keys.contains (key, ignoreCase);
103}
104
105 void StringPairArray::set (const String& key, const String& value)
106{
107 auto i = keys.indexOf (key, ignoreCase);
108
109 if (i >= 0)
110 {
111 values.set (i, value);
112 }
113 else
114 {
115 keys.add (key);
116 values.add (value);
117 }
118}
119
120 void StringPairArray::addArray (const StringPairArray& other)
121{
122 for (int i = 0; i < other.size(); ++i)
123 set (other.keys[i], other.values[i]);
124}
125
126 void StringPairArray::clear()
127{
128 keys.clear();
129 values.clear();
130}
131
132 void StringPairArray::remove (StringRef key)
133{
134 remove (keys.indexOf (key, ignoreCase));
135}
136
137 void StringPairArray::remove (int index)
138{
139 keys.remove (index);
140 values.remove (index);
141}
142
143 void StringPairArray::setIgnoresCase (bool shouldIgnoreCase)
144{
145 ignoreCase = shouldIgnoreCase;
146}
147
148 String StringPairArray::getDescription() const
149{
150 String s;
151
152 for (int i = 0; i < keys.size(); ++i)
153 {
154 s << keys[i] << " = " << values[i];
155
156 if (i < keys.size())
157 s << ", ";
158 }
159
160 return s;
161}
162
163 void StringPairArray::minimiseStorageOverheads()
164{
165 keys.minimiseStorageOverheads();
166 values.minimiseStorageOverheads();
167}
168
169} // namespace juce
juce::StringArray::indexOf
int indexOf(StringRef stringToLookFor, bool ignoreCase=false, int startIndex=0) const
Definition: juce_StringArray.cpp:193
juce::StringArray::minimiseStorageOverheads
void minimiseStorageOverheads()
Definition: juce_StringArray.cpp:468
juce::StringArray::clear
void clear()
Definition: juce_StringArray.cpp:111
juce::StringArray::size
int size() const noexcept
Definition: juce_StringArray.h:135
juce::StringArray::add
void add(String stringToAdd)
Definition: juce_StringArray.cpp:135
juce::StringArray::set
void set(int index, String newString)
Definition: juce_StringArray.cpp:183
juce::StringArray::remove
void remove(int index)
Definition: juce_StringArray.cpp:222
juce::StringPairArray
Definition: juce_StringPairArray.h:35
juce::StringPairArray::setIgnoresCase
void setIgnoresCase(bool shouldIgnoreCase)
Definition: juce_StringPairArray.cpp:143
juce::StringPairArray::getValue
String getValue(StringRef, const String &defaultReturnValue) const
Definition: juce_StringPairArray.cpp:90
juce::StringPairArray::operator=
StringPairArray & operator=(const StringPairArray &other)
Definition: juce_StringPairArray.cpp:41
juce::StringPairArray::containsKey
bool containsKey(StringRef key) const noexcept
Definition: juce_StringPairArray.cpp:100
juce::StringPairArray::set
void set(const String &key, const String &value)
Definition: juce_StringPairArray.cpp:105
juce::StringPairArray::clear
void clear()
Definition: juce_StringPairArray.cpp:126
juce::StringPairArray::getDescription
String getDescription() const
Definition: juce_StringPairArray.cpp:148
juce::StringPairArray::remove
void remove(StringRef key)
Definition: juce_StringPairArray.cpp:132
juce::StringPairArray::~StringPairArray
~StringPairArray()
Definition: juce_StringPairArray.cpp:37
juce::StringPairArray::StringPairArray
StringPairArray(bool ignoreCaseWhenComparingKeys=true)
Definition: juce_StringPairArray.cpp:26
juce::StringPairArray::operator[]
const String & operator[](StringRef key) const
Definition: juce_StringPairArray.cpp:85
juce::StringPairArray::operator!=
bool operator!=(const StringPairArray &other) const
Definition: juce_StringPairArray.cpp:80
juce::StringPairArray::minimiseStorageOverheads
void minimiseStorageOverheads()
Definition: juce_StringPairArray.cpp:163
juce::StringPairArray::addArray
void addArray(const StringPairArray &other)
Definition: juce_StringPairArray.cpp:120
juce::StringPairArray::size
int size() const noexcept
Definition: juce_StringPairArray.h:93
juce::StringPairArray::operator==
bool operator==(const StringPairArray &other) const
Definition: juce_StringPairArray.cpp:48
juce::StringRef
Definition: juce_StringRef.h:62
juce::String
Definition: juce_String.h:39