SVGStringList.cpp (1681B)
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 9 #include "SVGContentUtils.h" 10 #include "nsCharSeparatedTokenizer.h" 11 #include "nsContentUtils.h" 12 #include "nsError.h" 13 #include "nsReadableUtils.h" 14 #include "nsString.h" 15 #include "nsWhitespaceTokenizer.h" 16 17 namespace mozilla { 18 19 nsresult SVGStringList::CopyFrom(const SVGStringList& rhs) { 20 if (!mStrings.Assign(rhs.mStrings, fallible)) { 21 return NS_ERROR_OUT_OF_MEMORY; 22 } 23 mIsSet = true; 24 return NS_OK; 25 } 26 27 void SVGStringList::GetValue(nsAString& aValue) const { 28 aValue = StringJoin(mIsCommaSeparated ? u", "_ns : u" "_ns, mStrings); 29 } 30 31 nsresult SVGStringList::SetValue(const nsAString& aValue) { 32 SVGStringList temp; 33 34 if (mIsCommaSeparated) { 35 nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> 36 tokenizer(aValue, ','); 37 38 while (tokenizer.hasMoreTokens()) { 39 if (!temp.AppendItem(tokenizer.nextToken())) { 40 return NS_ERROR_OUT_OF_MEMORY; 41 } 42 } 43 if (tokenizer.separatorAfterCurrentToken()) { 44 return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma 45 } 46 } else { 47 nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tokenizer( 48 aValue); 49 50 while (tokenizer.hasMoreTokens()) { 51 if (!temp.AppendItem(tokenizer.nextToken())) { 52 return NS_ERROR_OUT_OF_MEMORY; 53 } 54 } 55 } 56 57 return CopyFrom(temp); 58 } 59 60 } // namespace mozilla