2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 09:44:03 +00:00
|
|
|
|
|
|
|
#include "SVGStringList.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2011-12-31 09:44:03 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2011-12-31 09:44:03 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGStringList::CopyFrom(const SVGStringList& rhs)
|
|
|
|
{
|
2015-07-07 18:27:03 +00:00
|
|
|
if (!mStrings.Assign(rhs.mStrings, fallible)) {
|
2011-12-31 09:44:03 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mIsSet = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-15 23:40:46 +00:00
|
|
|
SVGStringList::GetValue(nsAString& aValue) const
|
2011-12-31 09:44:03 +00:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t last = mStrings.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mStrings.Length(); ++i) {
|
2011-12-31 09:44:03 +00:00
|
|
|
aValue.Append(mStrings[i]);
|
|
|
|
if (i != last) {
|
2012-02-15 23:40:46 +00:00
|
|
|
if (mIsCommaSeparated) {
|
2011-12-31 09:44:03 +00:00
|
|
|
aValue.Append(',');
|
|
|
|
}
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-02-15 23:40:46 +00:00
|
|
|
SVGStringList::SetValue(const nsAString& aValue)
|
2011-12-31 09:44:03 +00:00
|
|
|
{
|
|
|
|
SVGStringList temp;
|
|
|
|
|
2012-02-15 23:40:46 +00:00
|
|
|
if (mIsCommaSeparated) {
|
2011-12-31 09:44:03 +00:00
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',');
|
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 12:52:39 +00:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2011-12-31 09:44:03 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-17 12:52:39 +00:00
|
|
|
nsWhitespaceTokenizerTemplate<IsSVGWhitespace> tokenizer(aValue);
|
2011-12-31 09:44:03 +00:00
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|