Skip to content

Commit

Permalink
Keep track of textContentLength wherever it might be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby White committed Nov 24, 2007
1 parent 01cd7c0 commit 80369aa
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 16 deletions.
30 changes: 30 additions & 0 deletions dom/m_dom_character_data.m4
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ TOHW_m_dom_contents(`
TOHW_m_dom_throw_error(FoX_INVALID_CDATA_SECTION)
endif

! And propagate length upwards ...
if (getNodeType(arg)/=COMMENT_NODE) &
call updateTextContentLength(arg, len(data))

end subroutine appendData


Expand Down Expand Up @@ -139,6 +143,10 @@ TOHW_m_dom_contents(`
TOHW_m_dom_throw_error(FoX_INVALID_CDATA_SECTION)
endif

! And propagate length upwards ...
if (getNodeType(arg)/=COMMENT_NODE) &
call updateTextContentLength(arg, len(data))

end subroutine insertData


Expand All @@ -148,6 +156,7 @@ TOHW_m_dom_contents(`
integer, intent(in) :: count

character, pointer :: tmp(:)
integer :: n

if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
Expand All @@ -160,11 +169,21 @@ TOHW_m_dom_contents(`
elseif (offset<0.or.offset>size(arg%nodeValue).or.count<0) then
TOHW_m_dom_throw_error(INDEX_SIZE_ERR)
endif

if (offset+count>size(arg%nodeValue)) then
n = size(arg%nodeValue)-offset
else
n = count
endif

tmp => arg%nodeValue
arg%nodeValue => vs_str_alloc(str_vs(tmp(:offset))//str_vs(tmp(offset+count+1:)))
deallocate(tmp)

! And propagate length upwards ...
if (getNodeType(arg)/=COMMENT_NODE) &
call updateTextContentLength(arg, -n)

end subroutine deleteData


Expand All @@ -175,6 +194,7 @@ TOHW_m_dom_contents(`
character(len=*), intent(in) :: data

character, pointer :: tmp(:)
integer :: n

if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
Expand All @@ -192,6 +212,12 @@ TOHW_m_dom_contents(`
TOHW_m_dom_throw_error(FoX_INVALID_CHARACTER)
endif

if (offset+count>size(arg%nodeValue)) then
n = len(data)-(size(arg%nodeValue)-offset)
else
n = len(data)-count
endif

tmp => arg%nodeValue
if (offset+count <= size(arg%nodeValue)) then
arg%nodeValue => vs_str_alloc(str_vs(tmp(:offset))//data//str_vs(tmp(offset+count+1:)))
Expand All @@ -208,6 +234,10 @@ TOHW_m_dom_contents(`
TOHW_m_dom_throw_error(FoX_INVALID_CDATA_SECTION)
endif

! And propagate length upwards ...
if (getNodeType(arg)/=COMMENT_NODE) &
call updateTextContentLength(arg, n)

end subroutine replaceData

')`'dnl
29 changes: 27 additions & 2 deletions dom/m_dom_common.m4
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ TOHW_m_dom_contents(`
TOHW_subroutine(setData, (arg, data))
type(Node), pointer :: arg
character(len=*) :: data

integer :: n

if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
Expand All @@ -30,11 +32,34 @@ TOHW_m_dom_contents(`
if (arg%readonly) then
TOHW_m_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR)
endif
deallocate(arg%nodeValue)
arg%nodeValue => vs_str_alloc(data)
else
TOHW_m_dom_throw_error(FoX_INVALID_NODE)
endif

select case (arg%nodeType)
case (CDATA_SECTION_NODE)
if (index(data,"]]>")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_CDATA_SECTION)
endif
case (COMMENT_NODE)
if (index(data,"--")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_COMMENT)
endif
case (PROCESSING_INSTRUCTION_NODE)
if (index(data,"?>")>0) then
TOHW_m_dom_throw_error(FoX_INVALID_PI_DATA)
endif
end select

deallocate(arg%nodeValue)
arg%nodeValue => vs_str_alloc(data)

if (arg%nodeType==TEXT_NODE .or. &
arg%nodeType==CDATA_SECTION_NODE) then
n = len(data) - arg%textContentLength
call updateTextContentLength(arg, n)
endif

end subroutine setData

TOHW_m_dom_get(DOMString, name, np%nodeName, (DOCUMENT_TYPE_NODE, ATTRIBUTE_NODE))
Expand Down
4 changes: 4 additions & 0 deletions dom/m_dom_document.m4
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ TOHW_m_dom_get(Node, documentElement, np%docExtras%documentElement, (DOCUMENT_NO
endif

np => createNode(arg, TEXT_NODE, "#text", data)
np%textContentLength = len(data)

if (getGCstate(arg)) then
np%inDocument = .false.
Expand Down Expand Up @@ -250,6 +251,7 @@ TOHW_m_dom_get(Node, documentElement, np%docExtras%documentElement, (DOCUMENT_NO
endif

np => createNode(arg, COMMENT_NODE, "#comment", data)
np%textContentLength = len(data)

if (getGCstate(arg)) then
np%inDocument = .false.
Expand Down Expand Up @@ -278,6 +280,7 @@ TOHW_m_dom_get(Node, documentElement, np%docExtras%documentElement, (DOCUMENT_NO
endif

np => createNode(arg, CDATA_SECTION_NODE, "#cdata-section", data)
np%textContentLength = len(data)

if (getGCstate(arg)) then
np%inDocument = .false.
Expand Down Expand Up @@ -309,6 +312,7 @@ TOHW_m_dom_get(Node, documentElement, np%docExtras%documentElement, (DOCUMENT_NO
endif

np => createNode(arg, PROCESSING_INSTRUCTION_NODE, target, data)
np%textContentLength = len(data)

if (getGCstate(arg)) then
np%inDocument = .false.
Expand Down
Loading

0 comments on commit 80369aa

Please sign in to comment.