CharacterData.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // CharacterData.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOM
  7. //
  8. // Definition of the DOM CharacterData class.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef DOM_CharacterData_INCLUDED
  16. #define DOM_CharacterData_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/DOM/AbstractNode.h"
  19. #include "Poco/XML/XMLString.h"
  20. namespace Poco {
  21. namespace XML {
  22. class XML_API CharacterData: public AbstractNode
  23. /// The CharacterData interface extends Node with a set of attributes and methods
  24. /// for accessing character data in the DOM. For clarity this set is defined
  25. /// here rather than on each object that uses these attributes and methods.
  26. /// No DOM objects correspond directly to CharacterData, though Text and others
  27. /// do inherit the interface from it. All offsets in this interface start from 0.
  28. ///
  29. /// Text strings in the DOM are represented in either UTF-8 (if XML_UNICODE_WCHAR_T is
  30. /// not defined) or in UTF-16 (if XML_UNICODE_WCHAR_T is defined).
  31. /// Indexing on character data is done in XMLChar units.
  32. {
  33. public:
  34. const XMLString& data() const;
  35. /// Returns the character data of the node that
  36. /// implements the interface.
  37. const XMLString& getData() const;
  38. /// Returns the character data of the node that
  39. /// implements the interface.
  40. void setData(const XMLString& data);
  41. /// Sets the character data of the node that
  42. /// implements the interface.
  43. unsigned long length() const;
  44. /// Returns the number of XMLChars that are available
  45. /// through getData and substringData. This may have the
  46. /// value zero.
  47. XMLString substringData(unsigned long offset, unsigned long count) const;
  48. /// Extracts a range of data from the node.
  49. /// If offset and count exceeds the length, then all
  50. /// the characters to the end of the data are returned.
  51. void appendData(const XMLString& arg);
  52. /// Append the string to the end of the character data
  53. /// of the node.
  54. void insertData(unsigned long offset, const XMLString& arg);
  55. /// Insert a string at the specified character offset.
  56. void deleteData(unsigned long offset, unsigned long count);
  57. /// Remove a range of characters from the node.
  58. void replaceData(unsigned long offset, unsigned long count, const XMLString& arg);
  59. /// Replace the characters starting at the specified character
  60. /// offset with the specified string.
  61. // Non-standard extensions
  62. XMLString trimmedData() const;
  63. /// Returns the character data of that node with
  64. /// all surrounding whitespace removed.
  65. ///
  66. /// This method is an extension to the W3C Document Object Model.
  67. // Node
  68. const XMLString& getNodeValue() const;
  69. void setNodeValue(const XMLString& value);
  70. protected:
  71. CharacterData(Document* pOwnerDocument, const XMLString& data);
  72. CharacterData(Document* pOwnerDocument, const CharacterData& data);
  73. ~CharacterData();
  74. private:
  75. XMLString _data;
  76. };
  77. //
  78. // inlines
  79. //
  80. inline const XMLString& CharacterData::data() const
  81. {
  82. return _data;
  83. }
  84. inline const XMLString& CharacterData::getData() const
  85. {
  86. return _data;
  87. }
  88. inline unsigned long CharacterData::length() const
  89. {
  90. return (unsigned long) _data.length();
  91. }
  92. } } // namespace Poco::XML
  93. #endif // DOM_CharacterData_INCLUDED