/src/mozilla-central/dom/svg/SVGLengthList.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "SVGLengthList.h" |
8 | | #include "nsCharSeparatedTokenizer.h" |
9 | | #include "nsError.h" |
10 | | #include "nsString.h" |
11 | | #include "nsSVGElement.h" |
12 | | #include "SVGAnimatedLengthList.h" |
13 | | #include "SVGContentUtils.h" |
14 | | #include "SVGLength.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | nsresult |
19 | | SVGLengthList::CopyFrom(const SVGLengthList& rhs) |
20 | 0 | { |
21 | 0 | if (!mLengths.Assign(rhs.mLengths, fallible)) { |
22 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
23 | 0 | } |
24 | 0 | return NS_OK; |
25 | 0 | } |
26 | | |
27 | | void |
28 | | SVGLengthList::GetValueAsString(nsAString& aValue) const |
29 | 0 | { |
30 | 0 | aValue.Truncate(); |
31 | 0 | uint32_t last = mLengths.Length() - 1; |
32 | 0 | for (uint32_t i = 0; i < mLengths.Length(); ++i) { |
33 | 0 | nsAutoString length; |
34 | 0 | mLengths[i].GetValueAsString(length); |
35 | 0 | // We ignore OOM, since it's not useful for us to return an error. |
36 | 0 | aValue.Append(length); |
37 | 0 | if (i != last) { |
38 | 0 | aValue.Append(' '); |
39 | 0 | } |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | nsresult |
44 | | SVGLengthList::SetValueFromString(const nsAString& aValue) |
45 | 0 | { |
46 | 0 | SVGLengthList temp; |
47 | 0 |
|
48 | 0 | nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> |
49 | 0 | tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL); |
50 | 0 |
|
51 | 0 | while (tokenizer.hasMoreTokens()) { |
52 | 0 | SVGLength length; |
53 | 0 | if (!length.SetValueFromString(tokenizer.nextToken())) { |
54 | 0 | return NS_ERROR_DOM_SYNTAX_ERR; |
55 | 0 | } |
56 | 0 | if (!temp.AppendItem(length)) { |
57 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
58 | 0 | } |
59 | 0 | } |
60 | 0 | if (tokenizer.separatorAfterCurrentToken()) { |
61 | 0 | return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma |
62 | 0 | } |
63 | 0 | return CopyFrom(temp); |
64 | 0 | } |
65 | | |
66 | | bool |
67 | | SVGLengthList::operator==(const SVGLengthList& rhs) const |
68 | 0 | { |
69 | 0 | if (Length() != rhs.Length()) { |
70 | 0 | return false; |
71 | 0 | } |
72 | 0 | for (uint32_t i = 0; i < Length(); ++i) { |
73 | 0 | if (!(mLengths[i] == rhs.mLengths[i])) { |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | } |
77 | 0 | return true; |
78 | 0 | } |
79 | | |
80 | | } // namespace mozilla |