]> git.lyx.org Git - features.git/commitdiff
Georg's mangling patch.
authorAngus Leeming <leeming@lyx.org>
Thu, 11 Mar 2004 11:45:08 +0000 (11:45 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 11 Mar 2004 11:45:08 +0000 (11:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8485 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/ChangeLog
src/support/filename.C
src/support/filename.h

index afa4bc315383d309307a4a5352253d62b67107da..5a25694d3e93088ed5b5b76ad0da2569fc718481 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-09  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * filename.[Ch] (mangledFilename): make sure that mangled names are
+       unique
+
 2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir,
index 337f9cbdb29d2cfeff03dbfc1bc22c7b5ceefee9..db6dd86f72fcb9361f4e1a1585471605c94e778b 100644 (file)
 
 #include <boost/assert.hpp>
 
+#include <map>
+#include <sstream>
 
+
+using std::map;
 using std::string;
 
 
@@ -65,6 +69,15 @@ string const FileName::outputFilename(string const & path) const
 
 string const FileName::mangledFilename() const
 {
+       // We need to make sure that every FileName instance for a given
+       // filename returns the same mangled name.
+    typedef map<string, string> MangledMap;
+       static MangledMap mangledNames;
+       MangledMap::const_iterator const it = mangledNames.find(name_);
+       if (it != mangledNames.end())
+               return (*it).second;
+
+       // Now the real work
        string mname = os::slashify_path(name_);
        // Remove the extension.
        mname = ChangeExtension(name_, string());
@@ -73,7 +86,15 @@ string const FileName::mangledFilename() const
        // Replace '.' in the file name with '_'
        mname = subst(mname, ".", "_");
        // Add the extension back on
-       return ChangeExtension(mname, GetExtension(name_));
+       mname = ChangeExtension(mname, GetExtension(name_));
+       // Prepend a counter to the filename. This is necessary to make
+       // the mangled name unique.
+       static int counter = 0;
+       std::ostringstream s;
+       s << counter++;
+       mname = s.str() + mname;
+       mangledNames[name_] = mname;
+       return mname;
 }
 
 
index f019fde922b846fae7dc58d8f101d5d2616b79f4..06b164c2e4da187b9bb81c42a8233c8680a65394 100644 (file)
@@ -46,6 +46,10 @@ public:
        /** \return a mangled version of the absolute file name,
         *  suitable for use in the temp dir when, for example, converting
         *  an image file to another format.
+        *  It is guaranteed that
+        *  - two different filenames have different mangled names
+        *  - two FileName instances with the same filename have identical
+        *    mangled names
         */
        std::string const mangledFilename() const;