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/01/12 01:16:47 UTC
cvs commit: xml-xerces/c/src/util/Platforms/Win32 Win32PlatformUtils.cpp
roddey 00/01/11 16:16:47
Modified: c/src/util/Platforms/Win32 Win32PlatformUtils.cpp
Log:
Changes to deal with multiply nested, relative pathed, entities and to deal
with the new URL class changes.
Revision Changes Path
1.3 +112 -9 xml-xerces/c/src/util/Platforms/Win32/Win32PlatformUtils.cpp
Index: Win32PlatformUtils.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/Platforms/Win32/Win32PlatformUtils.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Win32PlatformUtils.cpp 1999/11/22 20:41:26 1.2
+++ Win32PlatformUtils.cpp 2000/01/12 00:16:47 1.3
@@ -56,6 +56,10 @@
/**
* $Log: Win32PlatformUtils.cpp,v $
+ * Revision 1.3 2000/01/12 00:16:47 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
+ *
* Revision 1.2 1999/11/22 20:41:26 abagchi
* Changed 'intlFiles/Locales' to 'icu/data'
*
@@ -450,7 +454,7 @@
// ---------------------------------------------------------------------------
// XMLPlatformUtils: File system methods
// ---------------------------------------------------------------------------
-XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath)
+XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath)
{
//
// NOTE: THe path provided has always already been opened successfully,
@@ -470,10 +474,6 @@
if (!::GetFullPathNameW(srcPath, bufSize, tmpPath, &namePart))
return 0;
- // Cap it off at the name part, leaving just the full path
- if (namePart)
- *namePart = 0;
-
// Return a copy of the path
return XMLString::replicate(tmpPath);
}
@@ -491,10 +491,6 @@
if (!::GetFullPathNameA(tmpSrcPath, bufSize, tmpPath, &namePart))
return 0;
- // Cap it off at the name part, leaving just the full path
- if (namePart)
- *namePart = 0;
-
// Return a transcoded copy of the path
return XMLString::transcode(tmpPath);
}
@@ -530,6 +526,114 @@
// Else assume its a relative path
return true;
+}
+
+
+XMLCh* XMLPlatformUtils::weavePaths(const XMLCh* const basePath
+ , const XMLCh* const relativePath)
+
+{
+ // Create a buffer as large as both parts and empty it
+ XMLCh* tmpBuf = new XMLCh[XMLString::stringLen(basePath)
+ + XMLString::stringLen(relativePath)
+ + 2];
+ *tmpBuf = 0;
+
+ //
+ // If we have no base path, then just take the relative path as
+ // is.
+ //
+ if (!basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ if (!*basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ const XMLCh* basePtr = basePath + (XMLString::stringLen(basePath) - 1);
+ if ((*basePtr != chForwardSlash)
+ && (*basePtr != chBackSlash))
+ {
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+ }
+
+ // There is no relevant base path, so just take the relative part
+ if (basePtr < basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ // After this, make sure the buffer gets handled if we exit early
+ ArrayJanitor<XMLCh> janBuf(tmpBuf);
+
+ //
+ // We have some path part, so we need to check to see if we ahve to
+ // weave any of the parts together.
+ //
+ const XMLCh* pathPtr = relativePath;
+ while (true)
+ {
+ // If it does not start with some period, then we are done
+ if (*pathPtr != chPeriod)
+ break;
+
+ unsigned int periodCount = 1;
+ pathPtr++;
+ if (*pathPtr == chPeriod)
+ {
+ pathPtr++;
+ periodCount++;
+ }
+
+ // Has to be followed by a \ or / or the null to mean anything
+ if ((*pathPtr != chForwardSlash) && (*pathPtr != chBackSlash)
+ && *pathPtr)
+ {
+ break;
+ }
+ if (*pathPtr)
+ pathPtr++;
+
+ // If its one period, just eat it, else move backwards in the base
+ if (periodCount == 2)
+ {
+ basePtr--;
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+
+ if (basePtr < basePath)
+ {
+ // The base cannot provide enough levels, so its in error
+ // <TBD>
+ }
+ }
+ }
+
+ // Copy the base part up to the base pointer
+ XMLCh* bufPtr = tmpBuf;
+ const XMLCh* tmpPtr = basePath;
+ while (tmpPtr <= basePtr)
+ *bufPtr++ = *tmpPtr++;
+
+ // And then copy on the rest of our path
+ XMLString::copyString(bufPtr, pathPtr);
+
+ // Orphan the buffer and return it
+ janBuf.orphan();
+ return tmpBuf;
}