txXMLUtils.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /**
  6. * An XML Utility class
  7. **/
  8. #ifndef MITRE_XMLUTILS_H
  9. #define MITRE_XMLUTILS_H
  10. #include "txCore.h"
  11. #include "nsDependentSubstring.h"
  12. #include "txXPathNode.h"
  13. #define kExpatSeparatorChar 0xFFFF
  14. extern "C" int MOZ_XMLIsLetter(const char* ptr);
  15. extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
  16. class nsIAtom;
  17. class XMLUtils {
  18. public:
  19. static nsresult splitExpatName(const char16_t *aExpatName,
  20. nsIAtom **aPrefix, nsIAtom **aLocalName,
  21. int32_t* aNameSpaceID);
  22. static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
  23. nsIAtom** aLocalName);
  24. /*
  25. * Returns true if the given character is whitespace.
  26. */
  27. static bool isWhitespace(const char16_t& aChar)
  28. {
  29. return (aChar <= ' ' &&
  30. (aChar == ' ' || aChar == '\r' ||
  31. aChar == '\n'|| aChar == '\t'));
  32. }
  33. /**
  34. * Returns true if the given string has only whitespace characters
  35. */
  36. static bool isWhitespace(const nsAFlatString& aText);
  37. /**
  38. * Normalizes the value of a XML processingInstruction
  39. **/
  40. static void normalizePIValue(nsAString& attValue);
  41. /**
  42. * Returns true if the given string is a valid XML QName
  43. */
  44. static bool isValidQName(const nsAFlatString& aQName,
  45. const char16_t** aColon);
  46. /**
  47. * Returns true if the given character represents an Alpha letter
  48. */
  49. static bool isLetter(char16_t aChar)
  50. {
  51. return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
  52. }
  53. /**
  54. * Returns true if the given character is an allowable NCName character
  55. */
  56. static bool isNCNameChar(char16_t aChar)
  57. {
  58. return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
  59. }
  60. /*
  61. * Walks up the document tree and returns true if the closest xml:space
  62. * attribute is "preserve"
  63. */
  64. static bool getXMLSpacePreserve(const txXPathNode& aNode);
  65. };
  66. #endif