Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGStringList.cpp
blobf0db81556984166c9e8dfa41e8205cd4ec10c7eb
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 "SVGStringList.h"
8 #include "nsError.h"
9 #include "nsCharSeparatedTokenizer.h"
10 #include "nsContentUtils.h"
11 #include "nsReadableUtils.h"
12 #include "nsString.h"
13 #include "nsWhitespaceTokenizer.h"
14 #include "SVGContentUtils.h"
16 namespace mozilla {
18 nsresult SVGStringList::CopyFrom(const SVGStringList& rhs) {
19 if (!mStrings.Assign(rhs.mStrings, fallible)) {
20 return NS_ERROR_OUT_OF_MEMORY;
22 mIsSet = true;
23 return NS_OK;
26 void SVGStringList::GetValue(nsAString& aValue) const {
27 aValue = StringJoin(mIsCommaSeparated ? u", "_ns : u" "_ns, mStrings);
30 nsresult SVGStringList::SetValue(const nsAString& aValue) {
31 SVGStringList temp;
33 if (mIsCommaSeparated) {
34 nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
35 tokenizer(aValue, ',');
37 while (tokenizer.hasMoreTokens()) {
38 if (!temp.AppendItem(tokenizer.nextToken())) {
39 return NS_ERROR_OUT_OF_MEMORY;
42 if (tokenizer.separatorAfterCurrentToken()) {
43 return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
45 } else {
46 nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tokenizer(
47 aValue);
49 while (tokenizer.hasMoreTokens()) {
50 if (!temp.AppendItem(tokenizer.nextToken())) {
51 return NS_ERROR_OUT_OF_MEMORY;
56 return CopyFrom(temp);
59 } // namespace mozilla