You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/11/30 21:06:35 UTC

cvs commit: xml-xerces/c/src/dom RangeImpl.cpp RangeImpl.hpp TextImpl.cpp

andyh       00/11/30 12:06:31

  Modified:    c/src/dom RangeImpl.cpp RangeImpl.hpp TextImpl.cpp
  Log:
  DOM Range - patch to fix a number of Range problems.  See mail of 11/21/2000.   Tinny Ng.
  
  Revision  Changes    Path
  1.7       +46 -34    xml-xerces/c/src/dom/RangeImpl.cpp
  
  Index: RangeImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/RangeImpl.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RangeImpl.cpp	2000/08/30 22:21:23	1.6
  +++ RangeImpl.cpp	2000/11/30 20:06:22	1.7
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: RangeImpl.cpp,v 1.6 2000/08/30 22:21:23 andyh Exp $
  + * $Id: RangeImpl.cpp,v 1.7 2000/11/30 20:06:22 andyh Exp $
    */
   
   #include <util/RefVectorOf.hpp>
  @@ -197,7 +197,9 @@
           collapse(true); 
       }
       
  -    if (fStartOffset >= fEndOffset)
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(true); //collapse the range positions to start
       else
           fCollapsed = false;
  @@ -217,7 +219,9 @@
           collapse(false);
       }
       
  -    if (fEndOffset <= fStartOffset) 
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(false); //collapse the range positions to end
       else
           fCollapsed = false;
  @@ -244,7 +248,9 @@
           collapse(true); 
       }
       
  -    if (fStartOffset > fEndOffset)
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(true); //collapse the range positions to start
       else
           fCollapsed = false;
  @@ -269,7 +275,9 @@
           collapse(true); 
       }
       
  -    if (fStartOffset > fEndOffset)
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(true); //collapse the range positions to start
       else
           fCollapsed = false;
  @@ -295,7 +303,9 @@
           collapse(true); 
       }
       
  -    if (fEndOffset < fStartOffset) 
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(false); //collapse the range positions to end
       else
           fCollapsed = false;
  @@ -321,7 +331,9 @@
           collapse(true); 
       }
       
  -    if (fEndOffset < fStartOffset) 
  +    //compare the start and end boundary point
  +    //collapse if start point is after the end point
  +    if(compareBoundaryPoints(DOM_Range::END_TO_START, this) == 1)
           collapse(false); //collapse the range positions to end
       else
           fCollapsed = false;
  @@ -503,28 +515,28 @@
       switch (how)
       {
       case (DOM_Range::START_TO_START) :
  -        pointA = srcRange->getStartContainer();
  -        pointB = fStartContainer;
  -        offsetA = srcRange->getStartOffset();
  -        offsetB = fStartOffset;
  +        pointB = srcRange->getStartContainer();
  +        pointA = fStartContainer;
  +        offsetB = srcRange->getStartOffset();
  +        offsetA = fStartOffset;
           break;
       case (DOM_Range::START_TO_END) :
  -        pointA = srcRange->getStartContainer();
  -        pointB = fEndContainer;
  -        offsetA = srcRange->getStartOffset();
  -        offsetB = fEndOffset;
  +        pointB = srcRange->getStartContainer();
  +        pointA = fEndContainer;
  +        offsetB = srcRange->getStartOffset();
  +        offsetA = fEndOffset;
           break;
       case (DOM_Range::END_TO_START) :
  -        pointA = srcRange->getEndContainer();
  -        pointB = fStartContainer;
  -        offsetA = srcRange->getEndOffset();
  -        offsetB = fStartOffset;
  +        pointB = srcRange->getEndContainer();
  +        pointA = fStartContainer;
  +        offsetB = srcRange->getEndOffset();
  +        offsetA = fStartOffset;
           break;
       case (DOM_Range::END_TO_END) :
  -        pointA = srcRange->getEndContainer();
  -        pointB = fEndContainer;
  -        offsetA = srcRange->getEndOffset();
  -        offsetB = fEndOffset;
  +        pointB = srcRange->getEndContainer();
  +        pointA = fEndContainer;
  +        offsetB = srcRange->getEndOffset();
  +        offsetA = fEndOffset;
           break;
       }
       
  @@ -807,6 +819,7 @@
   
           //set 'parent' and 'next' here
           parent = fStartContainer.getParentNode();
  +
           //split the text nodes
          if (fStartOffset > 0) 
               ((DOM_Text &)fStartContainer).splitText(fStartOffset);
  @@ -833,7 +846,6 @@
           else 
               parent.appendChild(newNode);
       }
  -
   }
   
   RangeImpl* RangeImpl::cloneRange() const
  @@ -863,7 +875,9 @@
       if ( (fStartContainer.getNodeType() == DOM_Node::TEXT_NODE)
           || (fStartContainer.getNodeType() == DOM_Node::CDATA_SECTION_NODE) ) {
           if (fStartContainer == fEndContainer) {
  -            tempString.appendData(fStartContainer.getNodeValue().substringData(fStartOffset, fEndOffset));
  +            //the substringData returns a substring from start to end all inclusive
  +            //we want a substring begins at fStartOffset inclusive, but ends at fEndOffset exclusive
  +            tempString.appendData(fStartContainer.getNodeValue().substringData(fStartOffset, fEndOffset-1));
               return tempString;
           } else {
               int length = fStartContainer.getNodeValue().length();
  @@ -940,7 +954,7 @@
   {
       unsigned short i = 0;
       if (child.getParentNode() != parent) return (unsigned short)-1;
  -    for(DOM_Node node = child; node!= null; node=node.getPreviousSibling()) {
  +    for(DOM_Node node = child.getPreviousSibling(); node!= null; node=node.getPreviousSibling()) {
           i++;
       }
       return i;
  @@ -1545,23 +1559,21 @@
   }
   
   
  -void RangeImpl::updateSplitInfo(TextImpl* oldNode, TextImpl* startNode)
  +void RangeImpl::updateSplitInfo(TextImpl* oldNode, TextImpl* startNode, unsigned int offset)
   {
       if (startNode == null) return;
       
       DOM_Text oldText(oldNode);
       DOM_Text newText(startNode);
  -    unsigned int oldStartOffset;
   
  -    if (fStartContainer == oldText) {
  -        oldStartOffset = fStartOffset;
  +    if (fStartContainer == oldText && fStartOffset > offset) {
  +          fStartOffset = fStartOffset - offset;
           fStartContainer = newText;
  -        fStartOffset = 0;
  +    }
           
  -        if (fEndContainer == oldText) {
  +    if (fEndContainer == oldText && fEndOffset > offset) {
               fEndContainer = newText;
  -            fEndOffset = fEndOffset - oldStartOffset;
  -        }
  +       fEndOffset = fEndOffset - offset;
       }
   }
   
  
  
  
  1.3       +2 -2      xml-xerces/c/src/dom/RangeImpl.hpp
  
  Index: RangeImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/RangeImpl.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RangeImpl.hpp	2000/08/10 01:16:33	1.2
  +++ RangeImpl.hpp	2000/11/30 20:06:23	1.3
  @@ -57,7 +57,7 @@
    */
   
    /*
  - * $Id: RangeImpl.hpp,v 1.2 2000/08/10 01:16:33 aruna1 Exp $
  + * $Id: RangeImpl.hpp,v 1.3 2000/11/30 20:06:23 andyh Exp $
    */
   
   
  @@ -124,7 +124,7 @@
       const DOM_Node    getCommonAncestorContainer() const;
   
       // functions to inform all existing valid ranges about a change
  -    void updateSplitInfo(TextImpl* oldNode, TextImpl* startNode);
  +    void updateSplitInfo(TextImpl* oldNode, TextImpl* startNode, unsigned int offset);
       void updateRangeForInsertedNode(NodeImpl* node);
       void receiveReplacedText(NodeImpl* node);
       void updateRangeForDeletedText(DOM_Node& node, unsigned int offset, int count);
  
  
  
  1.16      +2 -2      xml-xerces/c/src/dom/TextImpl.cpp
  
  Index: TextImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/TextImpl.cpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TextImpl.cpp	2000/11/30 19:46:02	1.15
  +++ TextImpl.cpp	2000/11/30 20:06:24	1.16
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: TextImpl.cpp,v 1.15 2000/11/30 19:46:02 andyh Exp $
  + * $Id: TextImpl.cpp,v 1.16 2000/11/30 20:06:24 andyh Exp $
    */
   
   #include "DocumentImpl.hpp"
  @@ -133,7 +133,7 @@
               unsigned int sz = ranges->size();
               if (sz != 0) {
                   for (unsigned int i =0; i<sz; i++) {
  -                    ranges->elementAt(i)->updateSplitInfo( this, newText);
  +                    ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
                   }
               }
           }