1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "SVGLengthList.h"
8 #include "nsCharSeparatedTokenizer.h"
9 #include "nsContentUtils.h"
12 #include "SVGElement.h"
13 #include "SVGAnimatedLengthList.h"
14 #include "SVGContentUtils.h"
15 #include "SVGLength.h"
19 nsresult
SVGLengthList::CopyFrom(const SVGLengthList
& rhs
) {
20 if (!mLengths
.Assign(rhs
.mLengths
, fallible
)) {
21 return NS_ERROR_OUT_OF_MEMORY
;
26 void SVGLengthList::GetValueAsString(nsAString
& aValue
) const {
28 uint32_t last
= mLengths
.Length() - 1;
29 for (uint32_t i
= 0; i
< mLengths
.Length(); ++i
) {
31 mLengths
[i
].GetValueAsString(length
);
32 // We ignore OOM, since it's not useful for us to return an error.
33 aValue
.Append(length
);
40 nsresult
SVGLengthList::SetValueFromString(const nsAString
& aValue
) {
43 nsCharSeparatedTokenizerTemplate
<nsContentUtils::IsHTMLWhitespace
,
44 nsTokenizerFlags::SeparatorOptional
>
45 tokenizer(aValue
, ',');
47 while (tokenizer
.hasMoreTokens()) {
49 if (!length
.SetValueFromString(tokenizer
.nextToken())) {
50 return NS_ERROR_DOM_SYNTAX_ERR
;
52 if (!temp
.AppendItem(length
)) {
53 return NS_ERROR_OUT_OF_MEMORY
;
56 if (tokenizer
.separatorAfterCurrentToken()) {
57 return NS_ERROR_DOM_SYNTAX_ERR
; // trailing comma
59 mLengths
= std::move(temp
.mLengths
);
63 bool SVGLengthList::operator==(const SVGLengthList
& rhs
) const {
64 if (Length() != rhs
.Length()) {
67 for (uint32_t i
= 0; i
< Length(); ++i
) {
68 if (!(mLengths
[i
] == rhs
.mLengths
[i
])) {
75 } // namespace mozilla