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/. */
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
#include "SVGNumberList.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTextFormatter.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2011-04-14 22:47:27 +04:00
|
|
|
namespace mozilla {
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGNumberList::CopyFrom(const SVGNumberList& rhs)
|
|
|
|
{
|
2015-07-07 21:27:03 +03:00
|
|
|
if (!mNumbers.Assign(rhs.mNumbers, fallible)) {
|
2010-12-03 19:40:23 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGNumberList::GetValueAsString(nsAString& aValue) const
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t buf[24];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t last = mNumbers.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mNumbers.Length(); ++i) {
|
2010-12-03 19:40:23 +03:00
|
|
|
// Would like to use aValue.AppendPrintf("%f", mNumbers[i]), but it's not
|
|
|
|
// possible to always avoid trailing zeros.
|
2011-10-11 09:50:08 +04:00
|
|
|
nsTextFormatter::snprintf(buf, ArrayLength(buf),
|
2013-12-13 05:50:01 +04:00
|
|
|
MOZ_UTF16("%g"),
|
2010-12-03 19:40:23 +03:00
|
|
|
double(mNumbers[i]));
|
|
|
|
// We ignore OOM, since it's not useful for us to return an error.
|
|
|
|
aValue.Append(buf);
|
|
|
|
if (i != last) {
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGNumberList::SetValueFromString(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SVGNumberList temp;
|
|
|
|
|
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
|
|
|
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
2013-10-01 11:50:40 +04:00
|
|
|
float num;
|
|
|
|
if (!SVGContentUtils::ParseNumber(tokenizer.nextToken(), num)) {
|
2010-12-03 19:40:23 +03:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
2011-11-09 16:58:34 +04:00
|
|
|
if (!temp.AppendItem(num)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2010-12-03 19:40:23 +03:00
|
|
|
}
|
2013-09-17 16:52:39 +04:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2010-12-03 19:40:23 +03:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
2011-04-14 22:47:27 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|