1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
## -*- Ruby -*-
## XML::DOM
## 1998-2001 by yoshidam
##
require 'xml/dom2/node'
require 'xml/dom2/domexception'
module XML
module DOM
=begin
== Class XML::DOM::CharacterData
=== superclass
Node
=end
class CharacterData<Node
=begin
=== Class Methods
--- CharacterData.new(text)
creates a new CharacterData.
=end
## new(text)
## text: String
def initialize(text = nil)
super()
raise "parameter error" if !text
@value = text
end
=begin
=== Methods
--- CharacterData#data()
[DOM]
returns the character data of the node.
=end
## [DOM]
def data
@value.dup
end
=begin
--- CharacterData#data=(p)
[DOM]
set the character data of the node.
=end
## [DOM]
def data=(p)
@value = p
end
=begin
--- CharacterData#length()
[DOM]
returns length of this CharacterData.
=end
## [DOM]
def length
@value.length
end
=begin
--- CharacterData#substringData(start, count)
[DOM]
extracts a range of data from the node.
=end
## [DOM]
def substringData(start, count)
if start < 0 || start > @value.length || count < 0
raise DOMException.new(DOMException::INDEX_SIZE_ERR)
end
## if the sum of start and count > length,
## return all characters to the end of the value.
@value[start, count]
end
=begin
--- CharacterData#appendData(str)
[DOM]
append the string to the end of the character data.
=end
## [DOM]
def appendData(str)
@value << str
end
=begin
--- CharacterData#insertData(offset, str)
[DOM]
insert a string at the specified character offset.
=end
## [DOM]
def insertData(offset, str)
if offset < 0 || offset > @value.length
raise DOMException.new(DOMException::INDEX_SIZE_ERR)
end
@value[offset, 0] = str
end
=begin
--- CharacterData#deleteData(offset, count)
[DOM]
removes a range of characters from the node.
=end
## [DOM]
def deleteData(offset, count)
if offset < 0 || offset > @value.length || count < 0
raise DOMException.new(DOMException::INDEX_SIZE_ERR)
end
@value[offset, count] = ''
end
=begin
--- CharacterData#replaceData(offset, count, str)
[DOM]
replaces the characters starting at the specified character offset
with specified string.
=end
## [DOM]
def replaceData(offset, count, str)
if offset < 0 || offset > @value.length || count < 0
raise DOMException.new(DOMException::INDEX_SIZE_ERR)
end
@value[offset, count] = str
end
=begin
--- CharacterData#cloneData(deep = true)
[DOM]
returns the copy of the CharacterData.
=end
## [DOM]
def cloneNode(deep = true)
super(deep, @value.dup)
end
=begin
--- CharacterData#nodeValue
[DOM]
return nodevalue.
=end
## [DOM]
def nodeValue
@value
end
=begin
--- CharacterData#nodeValue=(p)
[DOM]
set nodevalue as p.
=end
## [DOM]
def nodeValue=(p)
@value = p
end
end
end
end
|