txExpandedName.cpp (1287B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "txExpandedName.h" 7 8 #include "nsReadableUtils.h" 9 #include "nsString.h" 10 #include "txNamespaceMap.h" 11 #include "txStringUtils.h" 12 #include "txXMLUtils.h" 13 14 nsresult txExpandedName::init(const nsAString& aQName, 15 txNamespaceMap* aResolver, bool aUseDefault) { 16 const nsString& qName = PromiseFlatString(aQName); 17 const char16_t* colon; 18 bool valid = XMLUtils::isValidQName(qName, &colon); 19 if (!valid) { 20 return NS_ERROR_FAILURE; 21 } 22 23 if (colon) { 24 RefPtr<nsAtom> prefix = NS_Atomize(Substring(qName.get(), colon)); 25 int32_t namespaceID = aResolver->lookupNamespace(prefix); 26 if (namespaceID == kNameSpaceID_Unknown) return NS_ERROR_FAILURE; 27 mNamespaceID = namespaceID; 28 29 const char16_t* end; 30 qName.EndReading(end); 31 mLocalName = NS_Atomize(Substring(colon + 1, end)); 32 } else { 33 mNamespaceID = 34 aUseDefault ? aResolver->lookupNamespace(nullptr) : kNameSpaceID_None; 35 mLocalName = NS_Atomize(aQName); 36 } 37 return NS_OK; 38 }