mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
New class StringPool. Removed the class var::identifier from its parent class, and renamed it "Identifier" - I've left a typedef in var to allow old code to still work, but I'll remove this at some point, so please switch to using the new classname directly. Jucer development.
This commit is contained in:
parent
ed97872c1a
commit
b46e94cffd
90 changed files with 2839 additions and 1733 deletions
105
src/text/juce_StringPool.cpp
Normal file
105
src/text/juce_StringPool.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-10 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "../core/juce_StandardHeader.h"
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
#include "juce_StringPool.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
StringPool::StringPool() throw() {}
|
||||
StringPool::~StringPool() {}
|
||||
|
||||
template <class StringType>
|
||||
static const juce_wchar* getPooledStringFromArray (Array<String>& strings, StringType newString)
|
||||
{
|
||||
int start = 0;
|
||||
int end = strings.size();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
jassert (start <= end);
|
||||
strings.insert (start, newString);
|
||||
return strings.getReference (start);
|
||||
}
|
||||
else
|
||||
{
|
||||
const String& startString = strings.getReference (start);
|
||||
|
||||
if (startString == newString)
|
||||
return startString;
|
||||
|
||||
const int halfway = (start + end) >> 1;
|
||||
|
||||
if (halfway == start)
|
||||
{
|
||||
if (startString.compare (newString) < 0)
|
||||
++start;
|
||||
|
||||
strings.insert (start, newString);
|
||||
return strings.getReference (start);
|
||||
}
|
||||
|
||||
const int comp = strings.getReference (halfway).compare (newString);
|
||||
|
||||
if (comp == 0)
|
||||
return strings.getReference (halfway);
|
||||
else if (comp < 0)
|
||||
start = halfway;
|
||||
else
|
||||
end = halfway;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const String& s)
|
||||
{
|
||||
if (s.isEmpty())
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const char* const s)
|
||||
{
|
||||
if (s == 0 || *s == 0)
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const juce_wchar* const s)
|
||||
{
|
||||
if (s == 0 || *s == 0)
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
Loading…
Add table
Add a link
Reference in a new issue