2015-05-03 22:32:37 +03: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 15:12:37 +04: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 13:44:03 +04:00
|
|
|
|
|
|
|
#include "SVGStringList.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2011-12-31 13:44:03 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
nsresult SVGStringList::CopyFrom(const SVGStringList& rhs) {
|
2015-07-07 21:27:03 +03:00
|
|
|
if (!mStrings.Assign(rhs.mStrings, fallible)) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mIsSet = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-16 03:40:46 +04:00
|
|
|
void SVGStringList::GetValue(nsAString& aValue) const {
|
2011-12-31 13:44:03 +04:00
|
|
|
aValue.Truncate();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t last = mStrings.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mStrings.Length(); ++i) {
|
2011-12-31 13:44:03 +04:00
|
|
|
aValue.Append(mStrings[i]);
|
|
|
|
if (i != last) {
|
2012-02-16 03:40:46 +04:00
|
|
|
if (mIsCommaSeparated) {
|
2011-12-31 13:44:03 +04:00
|
|
|
aValue.Append(',');
|
|
|
|
}
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 03:40:46 +04:00
|
|
|
nsresult SVGStringList::SetValue(const nsAString& aValue) {
|
2011-12-31 13:44:03 +04:00
|
|
|
SVGStringList temp;
|
|
|
|
|
2012-02-16 03:40:46 +04:00
|
|
|
if (mIsCommaSeparated) {
|
2018-03-18 10:14:32 +03:00
|
|
|
nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
|
2011-12-31 13:44:03 +04:00
|
|
|
tokenizer(aValue, ',');
|
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 16:52:39 +04:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2011-12-31 13:44:03 +04:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
|
|
|
} else {
|
2018-03-18 10:14:32 +03:00
|
|
|
nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tokenizer(
|
|
|
|
aValue);
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
if (!temp.AppendItem(tokenizer.nextToken())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|