This source file includes following definitions.
- initialize
- getItem
- insertItemBefore
- removeItem
- appendItem
- replaceItem
- parseInternal
- clone
- setValueAsString
- cloneForAnimation
- valueAsString
- checkIndexBound
- add
- calculateAnimatedValue
- calculateDistance
#include "config.h"
#include "core/svg/SVGStringList.h"
#include "core/svg/SVGElement.h"
#include "core/svg/SVGParserUtilities.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
SVGStringList::SVGStringList()
: SVGPropertyBase(classType())
{
}
SVGStringList::~SVGStringList()
{
}
void SVGStringList::initialize(const String& item)
{
m_values.clear();
m_values.append(item);
}
String SVGStringList::getItem(size_t index, ExceptionState& exceptionState)
{
if (!checkIndexBound(index, exceptionState))
return String();
return m_values.at(index);
}
void SVGStringList::insertItemBefore(const String& newItem, size_t index)
{
if (index > m_values.size())
index = m_values.size();
m_values.insert(index, newItem);
}
String SVGStringList::removeItem(size_t index, ExceptionState& exceptionState)
{
if (!checkIndexBound(index, exceptionState))
return String();
String oldItem = m_values.at(index);
m_values.remove(index);
return oldItem;
}
void SVGStringList::appendItem(const String& newItem)
{
m_values.append(newItem);
}
void SVGStringList::replaceItem(const String& newItem, size_t index, ExceptionState& exceptionState)
{
if (!checkIndexBound(index, exceptionState))
return;
m_values[index] = newItem;
}
template<typename CharType>
void SVGStringList::parseInternal(const CharType*& ptr, const CharType* end)
{
const UChar delimiter = ' ';
while (ptr < end) {
const CharType* start = ptr;
while (ptr < end && *ptr != delimiter && !isSVGSpace(*ptr))
ptr++;
if (ptr == start)
break;
m_values.append(String(start, ptr - start));
skipOptionalSVGSpacesOrDelimiter(ptr, end, delimiter);
}
}
PassRefPtr<SVGStringList> SVGStringList::clone()
{
RefPtr<SVGStringList> svgStringList = create();
svgStringList->m_values = m_values;
return svgStringList.release();
}
void SVGStringList::setValueAsString(const String& data, ExceptionState&)
{
m_values.clear();
if (data.isEmpty())
return;
if (data.is8Bit()) {
const LChar* ptr = data.characters8();
const LChar* end = ptr + data.length();
parseInternal(ptr, end);
} else {
const UChar* ptr = data.characters16();
const UChar* end = ptr + data.length();
parseInternal(ptr, end);
}
}
PassRefPtr<SVGPropertyBase> SVGStringList::cloneForAnimation(const String& string) const
{
RefPtr<SVGStringList> svgStringList = create();
svgStringList->setValueAsString(string, IGNORE_EXCEPTION);
return svgStringList.release();
}
String SVGStringList::valueAsString() const
{
StringBuilder builder;
Vector<String>::const_iterator it = m_values.begin();
Vector<String>::const_iterator itEnd = m_values.end();
if (it != itEnd) {
builder.append(*it);
++it;
for (; it != itEnd; ++it) {
builder.append(' ');
builder.append(*it);
}
}
return builder.toString();
}
bool SVGStringList::checkIndexBound(size_t index, ExceptionState& exceptionState)
{
if (index >= m_values.size()) {
exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::indexExceedsMaximumBound("index", index, m_values.size()));
return false;
}
return true;
}
void SVGStringList::add(PassRefPtr<SVGPropertyBase> other, SVGElement* contextElement)
{
ASSERT_NOT_REACHED();
}
void SVGStringList::calculateAnimatedValue(SVGAnimationElement*, float, unsigned, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, SVGElement*)
{
ASSERT_NOT_REACHED();
}
float SVGStringList::calculateDistance(PassRefPtr<SVGPropertyBase>, SVGElement*)
{
ASSERT_NOT_REACHED();
return -1.0f;
}
}