tng         2002/09/23 11:42:19

  Modified:    c/src/xercesc/util XMLString.cpp XMLString.hpp
  Log:
  DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename 
to standard URI form.
  
  Revision  Changes    Path
  1.8       +60 -1     xml-xerces/c/src/xercesc/util/XMLString.cpp
  
  Index: XMLString.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLString.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLString.cpp     27 Aug 2002 19:24:43 -0000      1.7
  +++ XMLString.cpp     23 Sep 2002 18:42:18 -0000      1.8
  @@ -1736,6 +1736,65 @@
       return;
   }
   
  +
  +/**
  + * Fixes a platform dependent absolute path filename to standard URI form.
  + * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash
  + * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
  + */
  +void XMLString::fixURI(const XMLCh* const str, XMLBuffer& toFill)
  +{
  +    toFill.reset();
  +
  +    if (!str || !*str)
  +        return;
  +
  +    int colonIdx = XMLString::indexOf(str, chColon);
  +    int slashIdx = XMLString::indexOf(str, chForwardSlash);
  +
  +    // If starts with a '/' we assume
  +    // this is an absolute (UNIX) file path and prefix it with file://
  +    if (colonIdx == -1 && XMLString::indexOf(str, chForwardSlash) == 0) {
  +        const XMLCh FILE_SCHEME[] = {
  +            chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon,
  +            chForwardSlash, chForwardSlash, chNull};
  +
  +        toFill.set(FILE_SCHEME);
  +
  +        // copy the string
  +        const XMLCh* inPtr = str;
  +        while (*inPtr)
  +            toFill.append(*inPtr++);
  +
  +        toFill.append(chNull);
  +    }
  +    else if (colonIdx == 1 && XMLString::isAlpha(*str)) {
  +        // If starts with a driver letter 'x:' we assume
  +        // this is an absolute (Windows) file path and prefix it with file:///
  +        const XMLCh FILE_SCHEME[] = {
  +            chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon,
  +            chForwardSlash, chForwardSlash, chForwardSlash, chNull};
  +
  +        toFill.set(FILE_SCHEME);
  +
  +        // copy the string and fix any backward slash
  +        const XMLCh* inPtr = str;
  +        while (*inPtr) {
  +            if (*inPtr == chYenSign ||
  +                *inPtr == chWonSign ||
  +                *inPtr == chBackSlash)
  +                toFill.append(chForwardSlash);
  +            else
  +                toFill.append(*inPtr);
  +            inPtr++;
  +        }
  +
  +        // cap it with null
  +        toFill.append(chNull);
  +    }
  +}
  +
  +
   // ---------------------------------------------------------------------------
   //  XMLString: Private static methods
   // ---------------------------------------------------------------------------
  
  
  
  1.4       +13 -0     xml-xerces/c/src/xercesc/util/XMLString.hpp
  
  Index: XMLString.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLString.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLString.hpp     27 Aug 2002 19:24:43 -0000      1.3
  +++ XMLString.hpp     23 Sep 2002 18:42:18 -0000      1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.4  2002/09/23 18:42:18  tng
  + * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path 
filename to standard URI form.
  + *
    * Revision 1.3  2002/08/27 19:24:43  peiyongz
    * Bug#12087: patch from Thomas Ford ([EMAIL PROTECTED])
    *
  @@ -194,6 +197,7 @@
   
   #include <xercesc/util/XercesDefs.hpp>
   #include <xercesc/util/RefVectorOf.hpp>
  +#include <xercesc/framework/XMLBuffer.hpp>
   
   class XMLLCPTranscoder;
   
  @@ -1305,6 +1309,15 @@
         *        On return , this buffer also holds the converted string
         */
       static void collapseWS(XMLCh* const toConvert);
  +
  +    /**
  +     * Fixes a platform dependent absolute path filename to standard URI form.
  +     * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward 
slash
  +     * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
  +     * @param str    The string that has the absolute path filename
  +     * @param toFill The XMLBuffer that will be filled with the URI
  +     */
  +    static void fixURI(const XMLCh* const str, XMLBuffer& toFill);
       //@}
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to