Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGStringList.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 "SVGStringList.h"
8
#include "nsError.h"
9
#include "nsCharSeparatedTokenizer.h"
10
#include "nsString.h"
11
#include "nsWhitespaceTokenizer.h"
12
#include "SVGContentUtils.h"
13
14
namespace mozilla {
15
16
nsresult
17
SVGStringList::CopyFrom(const SVGStringList& rhs)
18
0
{
19
0
  if (!mStrings.Assign(rhs.mStrings, fallible)) {
20
0
    return NS_ERROR_OUT_OF_MEMORY;
21
0
  }
22
0
  mIsSet = true;
23
0
  return NS_OK;
24
0
}
25
26
void
27
SVGStringList::GetValue(nsAString& aValue) const
28
0
{
29
0
  aValue.Truncate();
30
0
  uint32_t last = mStrings.Length() - 1;
31
0
  for (uint32_t i = 0; i < mStrings.Length(); ++i) {
32
0
    aValue.Append(mStrings[i]);
33
0
    if (i != last) {
34
0
      if (mIsCommaSeparated) {
35
0
        aValue.Append(',');
36
0
      }
37
0
      aValue.Append(' ');
38
0
    }
39
0
  }
40
0
}
41
42
nsresult
43
SVGStringList::SetValue(const nsAString& aValue)
44
0
{
45
0
  SVGStringList temp;
46
0
47
0
  if (mIsCommaSeparated) {
48
0
    nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
49
0
      tokenizer(aValue, ',');
50
0
51
0
    while (tokenizer.hasMoreTokens()) {
52
0
      if (!temp.AppendItem(tokenizer.nextToken())) {
53
0
        return NS_ERROR_OUT_OF_MEMORY;
54
0
      }
55
0
    }
56
0
    if (tokenizer.separatorAfterCurrentToken()) {
57
0
      return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
58
0
    }
59
0
  } else {
60
0
    nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
61
0
      tokenizer(aValue);
62
0
63
0
    while (tokenizer.hasMoreTokens()) {
64
0
      if (!temp.AppendItem(tokenizer.nextToken())) {
65
0
        return NS_ERROR_OUT_OF_MEMORY;
66
0
      }
67
0
    }
68
0
  }
69
0
70
0
  return CopyFrom(temp);
71
0
}
72
73
} // namespace mozilla