2011-12-31 01:44:03 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-31 01:44:03 -08:00
|
|
|
|
|
|
|
#include "SVGStringList.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2011-12-31 01:44:03 -08:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2011-12-31 01:44:03 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGStringList::CopyFrom(const SVGStringList& rhs)
|
|
|
|
{
|
|
|
|
if (!mStrings.SetCapacity(rhs.Length())) {
|
|
|
|
// Yes, we do want fallible alloc here
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mStrings = rhs.mStrings;
|
|
|
|
mIsSet = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 15:40:46 -08:00
|
|
|
SVGStringList::GetValue(nsAString& aValue) const
|
2011-12-31 01:44:03 -08:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t last = mStrings.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mStrings.Length(); ++i) {
|
2011-12-31 01:44:03 -08:00
|
|
|
aValue.Append(mStrings[i]);
|
|
|
|
if (i != last) {
|
2012-02-15 15:40:46 -08:00
|
|
|
if (mIsCommaSeparated) {
|
2011-12-31 01:44:03 -08:00
|
|
|
aValue.Append(',');
|
|
|
|
}
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-02-15 15:40:46 -08:00
|
|
|
SVGStringList::SetValue(const nsAString& aValue)
|
2011-12-31 01:44:03 -08:00
|
|
|
{
|
|
|
|
SVGStringList temp;
|
|
|
|
|
2012-02-15 15:40:46 -08:00
|
|
|
if (mIsCommaSeparated) {
|
2011-12-31 01:44:03 -08:00
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',');
|
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 05:52:39 -07:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2011-12-31 01:44:03 -08:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-17 05:52:39 -07:00
|
|
|
nsWhitespaceTokenizerTemplate<IsSVGWhitespace> tokenizer(aValue);
|
2011-12-31 01:44:03 -08:00
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|