Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/parser/html/nsHtml5Portability.cpp
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "nsHtml5Portability.h"
6
#include "jArray.h"
7
#include "nsAtom.h"
8
#include "nsHtml5TreeBuilder.h"
9
#include "nsString.h"
10
11
nsAtom*
12
nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf,
13
                                           int32_t length,
14
                                           nsHtml5AtomTable* interner)
15
0
{
16
0
  NS_ASSERTION(interner, "Didn't get an atom service.");
17
0
  return interner->GetAtom(nsDependentSubstring(buf, buf + length));
18
0
}
19
20
static bool
21
ContainsWhiteSpace(mozilla::Span<char16_t> aSpan)
22
0
{
23
0
  for (char16_t c : aSpan) {
24
0
    if (nsContentUtils::IsHTMLWhitespace(c)) {
25
0
      return true;
26
0
    }
27
0
  }
28
0
  return false;
29
0
}
30
31
nsHtml5String
32
nsHtml5Portability::newStringFromBuffer(char16_t* buf,
33
                                        int32_t offset,
34
                                        int32_t length,
35
                                        nsHtml5TreeBuilder* treeBuilder,
36
                                        bool maybeAtomize)
37
0
{
38
0
  if (!length) {
39
0
    return nsHtml5String::EmptyString();
40
0
  }
41
0
  if (maybeAtomize &&
42
0
      !ContainsWhiteSpace(mozilla::MakeSpan(buf + offset, length))) {
43
0
    return nsHtml5String::FromAtom(
44
0
      NS_AtomizeMainThread(nsDependentSubstring(buf + offset, length)));
45
0
  }
46
0
  return nsHtml5String::FromBuffer(buf + offset, length, treeBuilder);
47
0
}
48
49
nsHtml5String
50
nsHtml5Portability::newEmptyString()
51
0
{
52
0
  return nsHtml5String::EmptyString();
53
0
}
54
55
nsHtml5String
56
nsHtml5Portability::newStringFromLiteral(const char* literal)
57
0
{
58
0
  return nsHtml5String::FromLiteral(literal);
59
0
}
60
61
nsHtml5String
62
nsHtml5Portability::newStringFromString(nsHtml5String string)
63
0
{
64
0
  return string.Clone();
65
0
}
66
67
jArray<char16_t, int32_t>
68
nsHtml5Portability::newCharArrayFromLocal(nsAtom* local)
69
0
{
70
0
  nsAutoString temp;
71
0
  local->ToString(temp);
72
0
  int32_t len = temp.Length();
73
0
  jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len);
74
0
  memcpy(arr, temp.BeginReading(), len * sizeof(char16_t));
75
0
  return arr;
76
0
}
77
78
jArray<char16_t, int32_t>
79
nsHtml5Portability::newCharArrayFromString(nsHtml5String string)
80
0
{
81
0
  MOZ_RELEASE_ASSERT(string);
82
0
  uint32_t len = string.Length();
83
0
  MOZ_RELEASE_ASSERT(len < INT32_MAX);
84
0
  jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len);
85
0
  string.CopyToBuffer(arr);
86
0
  return arr;
87
0
}
88
89
nsAtom*
90
nsHtml5Portability::newLocalFromLocal(nsAtom* local, nsHtml5AtomTable* interner)
91
0
{
92
0
  MOZ_ASSERT(local, "Atom was null.");
93
0
  MOZ_ASSERT(interner, "Atom table was null");
94
0
  if (!local->IsStatic()) {
95
0
    nsAutoString str;
96
0
    local->ToString(str);
97
0
    local = interner->GetAtom(str);
98
0
  }
99
0
  return local;
100
0
}
101
102
bool
103
nsHtml5Portability::localEqualsBuffer(nsAtom* local,
104
                                      char16_t* buf,
105
                                      int32_t length)
106
0
{
107
0
  return local->Equals(buf, length);
108
0
}
109
110
bool
111
nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
112
  const char* lowerCaseLiteral,
113
  nsHtml5String string)
114
0
{
115
0
  return string.LowerCaseStartsWithASCII(lowerCaseLiteral);
116
0
}
117
118
bool
119
nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(
120
  const char* lowerCaseLiteral,
121
  nsHtml5String string)
122
0
{
123
0
  return string.LowerCaseEqualsASCII(lowerCaseLiteral);
124
0
}
125
126
bool
127
nsHtml5Portability::literalEqualsString(const char* literal,
128
                                        nsHtml5String string)
129
0
{
130
0
  return string.EqualsASCII(literal);
131
0
}
132
133
bool
134
nsHtml5Portability::stringEqualsString(nsHtml5String one, nsHtml5String other)
135
0
{
136
0
  return one.Equals(other);
137
0
}
138
139
void
140
nsHtml5Portability::initializeStatics()
141
3
{
142
3
}
143
144
void
145
nsHtml5Portability::releaseStatics()
146
0
{
147
0
}