You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2004/08/11 18:46:54 UTC

cvs commit: xml-xerces/c/src/xercesc/util HexBin.hpp HexBin.cpp

peiyongz    2004/08/11 09:46:54

  Modified:    c/src/xercesc/util HexBin.hpp HexBin.cpp
  Log:
  Decoding and getCanRep
  
  Revision  Changes    Path
  1.4       +43 -2     xml-xerces/c/src/xercesc/util/HexBin.hpp
  
  Index: HexBin.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/HexBin.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HexBin.hpp	29 Jan 2004 11:48:46 -0000	1.3
  +++ HexBin.hpp	11 Aug 2004 16:46:54 -0000	1.4
  @@ -61,7 +61,7 @@
   #ifndef HEXBIN_HPP
   #define HEXBIN_HPP
   
  -#include <xercesc/util/XercesDefs.hpp>
  +#include <xercesc/util/PlatformUtils.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -91,6 +91,47 @@
        */
   
       static bool isArrayByteHex(const XMLCh* const hexData);
  +
  +     /**
  +     * get canonical representation
  +     *
  +     * Caller is responsible for the proper deallcation
  +     * of the string returned.
  +     * 
  +     * @param hexData A string containing the HexBinary
  +     *
  +     * return: the canonical representation of the HexBinary
  +     *         if it is a valid HexBinary, 
  +     *         0 otherwise
  +     */
  +
  +    static XMLCh* getCanonicalRepresentation
  +                  (
  +                      const XMLCh*          const hexData
  +                    ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
  +                  );
  +
  +    /**
  +     * Decodes HexBinary data into XMLCh
  +     *
  +     * NOTE: The returned buffer is dynamically allocated and is the
  +     * responsibility of the caller to delete it when not longer needed.
  +     * You can call XMLString::release to release this returned buffer.
  +     *
  +     * If a memory manager is provided, ask the memory manager to de-allocate
  +     * the returned buffer.
  +     *
  +     * @param hexData HexBinary data in XMLCh stream.
  +     * @param memMgr client provided memory manager
  +     * @return Decoded binary data in XMLCh stream,
  +     *      or NULL if input data can not be decoded.
  +     * @see   XMLString::release(XMLCh**)
  +     */
  +    static XMLCh* decode(
  +                         const XMLCh*          const    hexData
  +                       ,       MemoryManager*  const    manager = XMLPlatformUtils::fgMemoryManager
  +                        );
  +
   
       //@}
   
  
  
  
  1.4       +55 -0     xml-xerces/c/src/xercesc/util/HexBin.cpp
  
  Index: HexBin.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/HexBin.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HexBin.cpp	4 Nov 2002 15:22:03 -0000	1.3
  +++ HexBin.cpp	11 Aug 2004 16:46:54 -0000	1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.4  2004/08/11 16:46:54  peiyongz
  + * Decoding and getCanRep
  + *
    * Revision 1.3  2002/11/04 15:22:03  tng
    * C++ Namespace Support.
    *
  @@ -76,6 +79,7 @@
   #include <xercesc/util/HexBin.hpp>
   #include <xercesc/util/XMLUniDefs.hpp>
   #include <xercesc/util/XMLString.hpp>
  +#include <xercesc/util/Janitor.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -115,6 +119,57 @@
               return false;
   
       return true;
  +}
  +
  +XMLCh* HexBin::getCanonicalRepresentation(const XMLCh*          const hexData
  +                                        ,       MemoryManager*  const manager)
  +{
  +
  +    if (getDataLength(hexData) == -1)
  +        return 0;
  +
  +    XMLCh* retStr = XMLString::replicate(hexData, manager);
  +    XMLString::upperCase(retStr);
  +
  +    return retStr;
  +}
  +
  +
  +XMLCh* HexBin::decode(const XMLCh*          const   hexData
  +                    ,       MemoryManager*  const   manager)
  +{
  +    if (( hexData == 0 ) || ( *hexData == 0 )) // zero length
  +        return 0;
  +
  +    int strLen = XMLString::stringLen(hexData);
  +    if ( strLen%2 != 0 )
  +        return 0;
  +
  +    if ( !isInitialized )
  +        init();
  +
  +    //prepare the return string
  +    XMLCh *retVal = (XMLCh*) manager->allocate( (strLen/2 + 1) * sizeof(XMLCh));
  +    ArrayJanitor<XMLCh> janFill(retVal, manager);
  +
  +    for ( int i = 0; i < strLen; )
  +    {
  +        if( !isHex(hexData[i])  || 
  +            !isHex(hexData[i+1])  )
  +            return 0;
  +        else
  +        {
  +            retVal[i/2] = (XMLCh)(
  +                                   (((XMLByte) hexData[i]) << 4 ) | 
  +                                    ((XMLByte) hexData[i+1])
  +                                 );      
  +            i+=2;
  +        }
  +    }
  +
  +    janFill.release();
  +    retVal[strLen/2] = 0;
  +    return retVal;
   }
   
   // -----------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org