2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../core/juce_StandardHeader.h"
30 #include "juce_StringPool.h"
33 //==============================================================================
34 StringPool::StringPool() noexcept
{}
35 StringPool::~StringPool() {}
37 namespace StringPoolHelpers
39 template <class StringType
>
40 const String::CharPointerType
getPooledStringFromArray (Array
<String
>& strings
, StringType newString
)
43 int end
= strings
.size();
49 jassert (start
<= end
);
50 strings
.insert (start
, newString
);
51 return strings
.getReference (start
).getCharPointer();
55 const String
& startString
= strings
.getReference (start
);
57 if (startString
== newString
)
58 return startString
.getCharPointer();
60 const int halfway
= (start
+ end
) >> 1;
64 if (startString
.compare (newString
) < 0)
67 strings
.insert (start
, newString
);
68 return strings
.getReference (start
).getCharPointer();
71 const int comp
= strings
.getReference (halfway
).compare (newString
);
74 return strings
.getReference (halfway
).getCharPointer();
84 const String::CharPointerType
StringPool::getPooledString (const String
& s
)
87 return String::empty
.getCharPointer();
89 return StringPoolHelpers::getPooledStringFromArray (strings
, s
);
92 const String::CharPointerType
StringPool::getPooledString (const char* const s
)
94 if (s
== nullptr || *s
== 0)
95 return String::empty
.getCharPointer();
97 return StringPoolHelpers::getPooledStringFromArray (strings
, s
);
100 const String::CharPointerType
StringPool::getPooledString (const wchar_t* const s
)
102 if (s
== nullptr || *s
== 0)
103 return String::empty
.getCharPointer();
105 return StringPoolHelpers::getPooledStringFromArray (strings
, s
);
108 int StringPool::size() const noexcept
110 return strings
.size();
113 const String::CharPointerType
StringPool::operator[] (const int index
) const noexcept
115 return strings
[index
].getCharPointer();