You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ro...@locus.apache.org on 2000/02/22 01:36:37 UTC

cvs commit: xml-xerces/c/src/util XMLChTranscoder.cpp XMLChTranscoder.hpp TransService.cpp XMLUni.cpp XMLUni.hpp

roddey      00/02/21 16:36:37

  Modified:    c/src/util TransService.cpp XMLUni.cpp XMLUni.hpp
  Added:       c/src/util XMLChTranscoder.cpp XMLChTranscoder.hpp
  Log:
  Added a new 'native XMLCh' transcoder to correctly handle
  internal entities now that XMLCh isn't always UTF-16.
  
  Revision  Changes    Path
  1.13      +7 -0      xml-xerces/c/src/util/TransService.cpp
  
  Index: TransService.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/TransService.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TransService.cpp	2000/02/19 00:26:41	1.12
  +++ TransService.cpp	2000/02/22 00:36:36	1.13
  @@ -61,6 +61,7 @@
   #include <util/RefHashTableOf.hpp>
   #include <util/XML88591Transcoder.hpp>
   #include <util/XMLASCIITranscoder.hpp>
  +#include <util/XMLChTranscoder.hpp>
   #include <util/XMLEBCDICTranscoder.hpp>
   #include <util/XMLIBM1140Transcoder.hpp>
   #include <util/XMLUCS4Transcoder.hpp>
  @@ -259,6 +260,12 @@
       //  is to adopt the elements, which is fine with us.
       //
       gMappings = new RefHashTableOf<ENameMap>(103);
  +
  +    //
  +    //  Add in the magical mapping for the native XMLCh transcoder. This
  +    //  is used for internal entities.
  +    //
  +    gMappings->put(new ENameMapFor<XMLChTranscoder>(XMLUni::fgXMLChEncodingString));
   
       //
       //  Add in our mappings for ASCII.
  
  
  
  1.13      +9 -0      xml-xerces/c/src/util/XMLUni.cpp
  
  Index: XMLUni.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/XMLUni.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XMLUni.cpp	2000/02/19 00:26:41	1.12
  +++ XMLUni.cpp	2000/02/22 00:36:37	1.13
  @@ -56,6 +56,10 @@
   
   /**
    * $Log: XMLUni.cpp,v $
  + * Revision 1.13  2000/02/22 00:36:37  roddey
  + * Added a new 'native XMLCh' transcoder to correctly handle
  + * internal entities now that XMLCh isn't always UTF-16.
  + *
    * Revision 1.12  2000/02/19 00:26:41  roddey
    * Yet, yet, yet still another EBCDIC alias tweak.
    *
  @@ -505,6 +509,12 @@
   {
           chLatin_W, chLatin_I, chLatin_N, chLatin_D, chLatin_O, chLatin_W
       ,   chLatin_S, chDash, chDigit_1, chDigit_2, chDigit_5, chDigit_2, chNull
  +};
  +
  +const XMLCh XMLUni::fgXMLChEncodingString[] =
  +{
  +        chLatin_X, chLatin_E, chLatin_R, chLatin_C, chLatin_E, chLatin_S
  +    ,   chDash, chLatin_X, chLatin_M, chLatin_L, chLatin_C, chLatin_H, chNull
   };
   
   const XMLCh XMLUni::fgXMLString[] =
  
  
  
  1.12      +4 -0      xml-xerces/c/src/util/XMLUni.hpp
  
  Index: XMLUni.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/XMLUni.hpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XMLUni.hpp	2000/02/19 00:26:41	1.11
  +++ XMLUni.hpp	2000/02/22 00:36:37	1.12
  @@ -56,6 +56,10 @@
   
   /**
    * $Log: XMLUni.hpp,v $
  + * Revision 1.12  2000/02/22 00:36:37  roddey
  + * Added a new 'native XMLCh' transcoder to correctly handle
  + * internal entities now that XMLCh isn't always UTF-16.
  + *
    * Revision 1.11  2000/02/19 00:26:41  roddey
    * Yet, yet, yet still another EBCDIC alias tweak.
    *
  @@ -307,6 +311,7 @@
       static const XMLCh fgVersionString[];
       static const XMLCh fgValidityDomain[];
       static const XMLCh fgWin1252EncodingString[];
  +    static const XMLCh fgXMLChEncodingString[];
       static const XMLCh fgXMLDeclString[];
       static const XMLCh fgXMLString[];
       static const XMLCh fgXMLStringSpace[];
  
  
  
  1.1                  xml-xerces/c/src/util/XMLChTranscoder.cpp
  
  Index: XMLChTranscoder.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   * 
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   * 
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   * 
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache\@apache.org.
   * 
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <util/BitOps.hpp>
  #include <util/XMLChTranscoder.hpp>
  #include <memory.h>
  
  
  
  // ---------------------------------------------------------------------------
  //  XMLChTranscoder: Constructors and Destructor
  // ---------------------------------------------------------------------------
  XMLChTranscoder::XMLChTranscoder(const  XMLCh* const    encodingName
                                  , const unsigned int    blockSize) :
  
      XMLTranscoder(encodingName, blockSize)
  {
  }
  
  
  XMLChTranscoder::~XMLChTranscoder()
  {
  }
  
  
  // ---------------------------------------------------------------------------
  //  XMLChTranscoder: Implementation of the transcoder API
  // ---------------------------------------------------------------------------
  bool XMLChTranscoder::supportsSrcOfs() const
  {
      // Yes we support this
      return true;
  }
  
  
  XMLCh
  XMLChTranscoder::transcodeOne(  const   XMLByte* const  srcData
                                  , const unsigned int    srcBytes
                                  ,       unsigned int&   bytesEaten)
  {
      // If not enough source bytes, return zero
      if (srcBytes < sizeof(XMLCh))
          return 0;
  
      // We are going to eat one XMLCh char's worth of bytes
      bytesEaten = sizeof(XMLCh);
  
      // Just cast the src bufer and deref the char currently there
      return *((const XMLCh*)srcData);
  }
  
  
  unsigned int
  XMLChTranscoder::transcodeXML(  const   XMLByte* const          srcData
                                  , const unsigned int            srcCount
                                  ,       XMLCh* const            toFill
                                  , const unsigned int            maxChars
                                  ,       unsigned int&           bytesEaten
                                  ,       unsigned char* const    charSizes)
  {
      // If debugging, make sure that the block size is legal
      #if defined(XML4C_DEBUG)
      checkBlockSize(maxChars);
      #endif
  
      //
      //  Calculate the max chars we can do here. Its the lesser of the
      //  max output chars and the number of chars in the source.
      //
      const unsigned int srcChars = srcCount / sizeof(XMLCh);
      const unsigned int countToDo = srcChars < maxChars ? srcChars : maxChars;
  
      //
      //  Copy over the count of chars that we precalculated. Notice we
      //  convert char count to byte count here!!!
      //
      memcpy(toFill, srcData, countToDo * sizeof(XMLCh));
  
      // Set the bytes eaten
      bytesEaten = countToDo * sizeof(XMLCh);
  
      // Set the character sizes to the fixed size
      memset(charSizes, sizeof(XMLCh), countToDo);
  
      // Return the chars we transcoded
      return countToDo;
  }
  
  
  
  1.1                  xml-xerces/c/src/util/XMLChTranscoder.hpp
  
  Index: XMLChTranscoder.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
   * reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   * 
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   * 
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   * 
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache\@apache.org.
   * 
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #ifndef XMLCHTRANSCODER_HPP
  #define XMLCHTRANSCODER_HPP
  
  #include <util/XML4CDefs.hpp>
  #include <util/TransService.hpp>
  
  
  //
  //  This class provides an implementation of the XMLTranscoder interface
  //  for a simple XMLCh transcoder. This is used for internal entities, which
  //  are already in the native XMLCh format.
  //
  class XMLUTIL_EXPORT XMLChTranscoder : public XMLTranscoder
  {
  public :
      // -----------------------------------------------------------------------
      //  Public constructors and destructor
      // -----------------------------------------------------------------------
      XMLChTranscoder
      (
          const   XMLCh* const    encodingName
          , const unsigned int    blockSize
      );
  
      virtual ~XMLChTranscoder();
  
  
      // -----------------------------------------------------------------------
      //  Implementation of the XMLTranscoder interface
      // -----------------------------------------------------------------------
      virtual bool supportsSrcOfs() const;
  
      virtual XMLCh transcodeOne
      (
          const   XMLByte* const  srcData
          , const unsigned int    srcBytes
          ,       unsigned int&   bytesEaten
      );
  
      virtual unsigned int transcodeXML
      (
          const   XMLByte* const          srcData
          , const unsigned int            srcCount
          ,       XMLCh* const            toFill
          , const unsigned int            maxChars
          ,       unsigned int&           bytesEaten
          ,       unsigned char* const    charSizes
      );
  
  
  private :
      // -----------------------------------------------------------------------
      //  Unimplemented constructors and operators
      // -----------------------------------------------------------------------
      XMLChTranscoder(const XMLChTranscoder&);
      void operator=(const XMLChTranscoder&);
  };
  
  #endif