dbertoni    00/06/23 07:30:17

  Modified:    c/src/XSLT AVT.cpp AVT.hpp ElemLiteralResult.cpp
  Log:
  Updated AVT code.
  
  Revision  Changes    Path
  1.6       +65 -30    xml-xalan/c/src/XSLT/AVT.cpp
  
  Index: AVT.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/AVT.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AVT.cpp   2000/04/11 15:09:19     1.5
  +++ AVT.cpp   2000/06/23 14:30:14     1.6
  @@ -58,8 +58,13 @@
   
   
   
  +#include <algorithm>
  +
  +
  +
   #include <PlatformSupport/DOMStringHelper.hpp>
   #include <PlatformSupport/StringTokenizer.hpp>
  +#include <PlatformSupport/STLHelper.hpp>
   
   
   
  @@ -85,12 +90,10 @@
                m_simpleString(),
                m_pcType(type)
   {
  -     StringTokenizer tokenizer(stringedValue, 
XALAN_STATIC_UCODE_STRING("{}\"\'"), true);
  +     StringTokenizer         tokenizer(stringedValue, 
XALAN_STATIC_UCODE_STRING("{}\"\'"), true);
   
  -     const int       nTokens = tokenizer.countTokens();
  +     const unsigned int      nTokens = tokenizer.countTokens();
   
  -     assert(length(m_simpleString) == 0);
  -
        if(nTokens < 2)
        {
                m_simpleString = stringedValue; // then do the simple thing
  @@ -110,13 +113,17 @@
                        if(length(lookahead))
                        {
                                t = lookahead;
  -                             lookahead = XalanDOMString();
  +
  +                             clear(lookahead);
                        }
  -                     else t = tokenizer.nextToken();
  -                                     
  +                     else
  +                     {
  +                             t = tokenizer.nextToken();
  +                     }
  +
                        if(length(t) == 1)
                        {
  -                             const XalanDOMChar      theChar = t.charAt(0);
  +                             const XalanDOMChar      theChar = charAt(t, 0);
   
                                switch(theChar)
                                {
  @@ -127,8 +134,10 @@
                                                if(equals(lookahead, 
XALAN_STATIC_UCODE_STRING("{")))
                                                {
                                                        // Double curlys mean 
escape to show curly
  -                                                     
append(buffer,lookahead);
  -                                                     lookahead = 
XalanDOMString();
  +                                                     append(buffer, 
lookahead);
  +
  +                                                     clear(lookahead);
  +
                                                        break; // from switch
                                                }
                                                else
  @@ -136,42 +145,51 @@
                                                        if(length(buffer) > 0)
                                                        {
                                                                
m_parts.push_back(new AVTPartSimple(buffer));
  -                                                             buffer = 
XalanDOMString();
  +
  +                                                             clear(buffer);
                                                        }
                                                                        
  -                                                     exprBuffer = 
XalanDOMString();
  +                                                     clear(exprBuffer);
  +
                                                        while(length(lookahead) 
> 0 && !equals(lookahead, XALAN_STATIC_UCODE_STRING("}")))
                                                        {
                                                                
if(length(lookahead) == 1)
                                                                {
  -                                                                     
switch(lookahead.charAt(0))
  +                                                                     
switch(charAt(lookahead, 0))
                                                                        {
                                                                                
case '\'':
                                                                                
case '\"':
                                                                                
{
                                                                                
        // String start
  -                                                                             
        append(exprBuffer,lookahead);
  +                                                                             
        append(exprBuffer, lookahead);
  +
                                                                                
        const XalanDOMString quote = lookahead;
  +
                                                                                
        // Consume stuff 'till next quote
                                                                                
        lookahead = tokenizer.nextToken();
  +
                                                                                
        while(!equals(lookahead, quote))
                                                                                
        {
  -                                                                             
                append(exprBuffer,lookahead);
  +                                                                             
                append(exprBuffer, lookahead);
  +
                                                                                
                lookahead = tokenizer.nextToken();
                                                                                
        }
  +
                                                                                
        append(exprBuffer,lookahead);
  +
                                                                                
        break;
                                                                                
}
                                                                                
case '{':
                                                                                
{
                                                                                
        // What's another curly doing here?
                                                                                
        error = "Error: Can not have \"{\" within expression.";
  +
                                                                                
        break;
                                                                                
}
                                                                                
default:
                                                                                
{
                                                                                
        // part of the template stuff, just add it.
  -                                                                             
        append(exprBuffer,lookahead);
  +                                                                             
        append(exprBuffer, lookahead);
                                                                                
}
                                                                        } // 
end inner switch
                                                                } // end if 
lookahead length == 1
  @@ -180,16 +198,21 @@
                                                                        // part 
of the template stuff, just add it.
                                                                        
append(exprBuffer,lookahead);
                                                                }
  +
                                                                lookahead = 
tokenizer.nextToken();
                                                        } // end 
while(!equals(lookahead, "}"))
                                                        
assert(equals(lookahead, XALAN_STATIC_UCODE_STRING("}")));
                                                        
                                                        // Proper close of 
attribute template. Evaluate the
                                                        // expression.
  -                                                     buffer = 
XalanDOMString();
  -                                                     XPath *xpath = 
constructionContext.createXPath(exprBuffer, resolver);
  +                                                     clear(buffer);
  +
  +                                                     const XPath* const      
xpath = constructionContext.createXPath(exprBuffer, resolver);
  +
                                                        m_parts.push_back(new 
AVTPartXPath(xpath));
  -                                                     lookahead = 
XalanDOMString(); // breaks out of inner while loop
  +
  +                                                     clear(lookahead); // 
breaks out of inner while loop
  +
                                                        if(length(error) > 0)
                                                        {
                                                                break; // from 
inner while loop
  @@ -200,16 +223,19 @@
                                        case('}'):
                                        {
                                                lookahead = 
tokenizer.nextToken();
  +
                                                if(equals(lookahead, 
XALAN_STATIC_UCODE_STRING("}")))
                                                {
                                                        // Double curlys mean 
escape to show curly
  -                                                     
append(buffer,lookahead);
  -                                                     lookahead = 
XalanDOMString(); // swallow
  +                                                     append(buffer, 
lookahead);
  +
  +                                                     clear(lookahead); // 
swallow
                                                }
                                                else
                                                {
                                                        // Illegal, I think...
                                                        
constructionContext.warn("Found \"}\" but no attribute template open!");
  +
                                                        append(buffer, 
XALAN_STATIC_UCODE_STRING("}"));
                                                        // leave the lookahead 
to be processed by the next round.
                                                }
  @@ -220,7 +246,8 @@
                                                // @@ Just to make sure we're 
not getting the whole string
                                                // There seemed to be a problem 
with single character
                                                // strings
  -                                             DOMString s(&theChar, 1);
  +                                             const DOMString         
s(&theChar, 1);
  +
                                                // Anything else just add to 
string.
                                                append(buffer, s);
                                        }
  @@ -235,6 +262,7 @@
                        if(length(error) > 0)
                        {
                                constructionContext.warn("Attr Template, " + 
error);
  +
                                break;
                        }
                } // end while(tokenizer.hasMoreTokens())
  @@ -253,18 +281,25 @@
                // Error?
                clear(m_simpleString);
        }
  +     else if (m_parts.size() < m_parts.capacity())
  +     {
  +             AVTPartPtrVectorType(m_parts).swap(m_parts);
  +     }
  +
   }
   
   
   
   AVT::~AVT()
   {
  -     for (unsigned i = 0; i < m_parts.size(); ++i)
  -     {
  -             delete (m_parts[i]);
  -     }
  -
  -     m_pcType = 0;
  +#if !defined(XALAN_NO_NAMESPACES)
  +     using std::for_each;
  +#endif
  +
  +     // Clean up all entries in the vector.
  +     for_each(m_parts.begin(),
  +                      m_parts.end(),
  +                      DeleteFunctor<AVTPart>());
   }
   
   
  @@ -282,7 +317,7 @@
        }
        else if(!m_parts.empty())
        {
  -             buf = XalanDOMString();
  +             clear(buf);
   
                const AVTPartPtrVectorType::size_type   n = m_parts.size();
   
  @@ -295,6 +330,6 @@
        }
        else
        {
  -             buf = XalanDOMString();
  +             clear(buf);
        }
   }
  
  
  
  1.6       +6 -7      xml-xalan/c/src/XSLT/AVT.hpp
  
  Index: AVT.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/AVT.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AVT.hpp   2000/04/11 15:09:19     1.5
  +++ AVT.hpp   2000/06/23 14:30:14     1.6
  @@ -58,7 +58,7 @@
   #define XALAN_AVT_HEADER_GUARD 
   
   /**
  - * $Id: AVT.hpp,v 1.5 2000/04/11 15:09:19 dbertoni Exp $
  + * $Id: AVT.hpp,v 1.6 2000/06/23 14:30:14 dbertoni Exp $
    * 
    * $State: Exp $
    * 
  @@ -130,7 +130,7 @@
         * 
         * @return type of AVT
         */
  -     const XalanDOMChar*
  +     const XalanDOMString&
        getType() const
        {
                return m_pcType;
  @@ -152,19 +152,18 @@
        AVT& operator=(const AVT &);
   
   #if defined(XALAN_NO_NAMESPACES)
  -     typedef vector<AVTPart*>                AVTPartPtrVectorType;
  +     typedef vector<const AVTPart*>          AVTPartPtrVectorType;
   #else
  -     typedef std::vector<AVTPart*>   AVTPartPtrVectorType;
  +     typedef std::vector<const AVTPart*>     AVTPartPtrVectorType;
   #endif
   
        XalanDOMString                  m_simpleString;
   
        AVTPartPtrVectorType    m_parts;
   
  -     XalanDOMString                  m_name;
  +     const XalanDOMString    m_name;
   
  -     // $$$ ToDO: Is this OK just to hold a pointer?
  -     const XalanDOMChar*             m_pcType;
  +     const XalanDOMString    m_pcType;
   };
   
   
  
  
  
  1.13      +15 -2     xml-xalan/c/src/XSLT/ElemLiteralResult.cpp
  
  Index: ElemLiteralResult.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/ElemLiteralResult.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ElemLiteralResult.cpp     2000/05/24 19:38:48     1.12
  +++ ElemLiteralResult.cpp     2000/06/23 14:30:14     1.13
  @@ -102,6 +102,8 @@
   {
        const unsigned int      nAttrs = atts.getLength();
   
  +     m_avts.reserve(nAttrs);
  +
        for(unsigned int i = 0; i < nAttrs; i++)
        {
                const XalanDOMChar*     const   aname = atts.getName(i);
  @@ -157,8 +159,17 @@
                                                        *this, 
constructionContext));
                        }
                }
  +
                removeExcludedPrefixes(m_excludeResultPrefixes);
        }
  +
  +     // Shrink the vector of AVTS, if necessary...
  +     if (m_avts.capacity() > m_avts.size())
  +     {
  +             // Make a copy that's the exact size, and
  +             // swap the two...
  +             AVTVectorType(m_avts).swap(m_avts);
  +     }
   }
   
   
  @@ -201,8 +212,10 @@
   
                        if(!isEmpty(stringedValue))
                        {
  -                             
executionContext.replacePendingAttribute(toCharArray(avt->getName()), 
  -                                     avt->getType(), 
toCharArray(stringedValue));
  +                             executionContext.replacePendingAttribute(
  +                                     c_wstr(avt->getName()), 
  +                                     c_wstr(avt->getType()),
  +                                     c_wstr(stringedValue));
                        }
                }
        }
  
  
  

Reply via email to