txExpandedName.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. #include "txExpandedName.h"
  6. #include "nsString.h"
  7. #include "nsReadableUtils.h"
  8. #include "txStringUtils.h"
  9. #include "txNamespaceMap.h"
  10. #include "txXMLUtils.h"
  11. nsresult
  12. txExpandedName::init(const nsAString& aQName, txNamespaceMap* aResolver,
  13. bool aUseDefault)
  14. {
  15. const nsAFlatString& qName = PromiseFlatString(aQName);
  16. const char16_t* colon;
  17. bool valid = XMLUtils::isValidQName(qName, &colon);
  18. if (!valid) {
  19. return NS_ERROR_FAILURE;
  20. }
  21. if (colon) {
  22. nsCOMPtr<nsIAtom> prefix = NS_Atomize(Substring(qName.get(), colon));
  23. int32_t namespaceID = aResolver->lookupNamespace(prefix);
  24. if (namespaceID == kNameSpaceID_Unknown)
  25. return NS_ERROR_FAILURE;
  26. mNamespaceID = namespaceID;
  27. const char16_t *end;
  28. qName.EndReading(end);
  29. mLocalName = NS_Atomize(Substring(colon + 1, end));
  30. }
  31. else {
  32. mNamespaceID = aUseDefault ? aResolver->lookupNamespace(nullptr) :
  33. kNameSpaceID_None;
  34. mLocalName = NS_Atomize(aQName);
  35. }
  36. return NS_OK;
  37. }