[Box Backup-commit] COMMIT r1089 - box/chris/merge/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Tue Oct 17 00:23:03 BST 2006


Author: chris
Date: 2006-10-17 00:23:03 +0100 (Tue, 17 Oct 2006)
New Revision: 1089

Modified:
   box/chris/merge/lib/common/ExcludeList.cpp
   box/chris/merge/lib/common/ExcludeList.h
Log:
Match case-insensitively on Win32. (refs #3)


Modified: box/chris/merge/lib/common/ExcludeList.cpp
===================================================================
--- box/chris/merge/lib/common/ExcludeList.cpp	2006-10-16 23:22:17 UTC (rev 1088)
+++ box/chris/merge/lib/common/ExcludeList.cpp	2006-10-16 23:23:03 UTC (rev 1089)
@@ -65,7 +65,46 @@
 	}
 }
 
+#ifdef WIN32
+std::string ExcludeList::ReplaceSlashesDefinite(const std::string& input) const
+{
+	std::string output = input;
 
+	for (std::string::size_type pos = output.find("/");
+		pos != std::string::npos; 
+		pos = output.find("/"))
+	{
+		output.replace(pos, 1, DIRECTORY_SEPARATOR);
+	}
+
+	for (std::string::iterator i = output.begin(); i != output.end(); i++)
+	{
+		*i = tolower(*i);
+	}
+
+	return output;
+}
+
+std::string ExcludeList::ReplaceSlashesRegex(const std::string& input) const
+{
+	std::string output = input;
+
+	for (std::string::size_type pos = output.find("/");
+		pos != std::string::npos; 
+		pos = output.find("/"))
+	{
+		output.replace(pos, 1, "\\" DIRECTORY_SEPARATOR);
+	}
+
+	for (std::string::iterator i = output.begin(); i != output.end(); i++)
+	{
+		*i = tolower(*i);
+	}
+
+	return output;
+}
+#endif
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -88,7 +127,16 @@
 	{
 		if(i->size() > 0)
 		{
-			mDefinite.insert(*i);
+			std::string entry = *i;
+
+			// Convert any forward slashes in the string
+			// to backslashes
+
+			#ifdef WIN32
+			entry = ReplaceSlashesDefinite(entry);
+			#endif
+
+			mDefinite.insert(entry);
 		}
 	}
 }
@@ -123,8 +171,18 @@
 			
 			try
 			{
+				std::string entry = *i;
+
+				// Convert any forward slashes in the string
+				// to appropriately escaped backslashes
+
+				#ifdef WIN32
+				entry = ReplaceSlashesRegex(entry);
+				#endif
+
 				// Compile
-				if(::regcomp(pregex, i->c_str(), REG_EXTENDED | REG_NOSUB) != 0)
+				if(::regcomp(pregex, entry.c_str(), 
+					REG_EXTENDED | REG_NOSUB) != 0)
 				{
 					THROW_EXCEPTION(CommonException, BadRegularExpression)
 				}
@@ -132,7 +190,7 @@
 				// Store in list of regular expressions
 				mRegex.push_back(pregex);
 				// Store in list of regular expression string for Serialize
-				mRegexStr.push_back(i->c_str());
+				mRegexStr.push_back(entry.c_str());
 			}
 			catch(...)
 			{
@@ -158,10 +216,16 @@
 // --------------------------------------------------------------------------
 bool ExcludeList::IsExcluded(const std::string &rTest) const
 {
+	std::string test = rTest;
+
+	#ifdef WIN32
+	test = ReplaceSlashesDefinite(test);
+	#endif
+
 	// Check against the always include list
 	if(mpAlwaysInclude != 0)
 	{
-		if(mpAlwaysInclude->IsExcluded(rTest))
+		if(mpAlwaysInclude->IsExcluded(test))
 		{
 			// Because the "always include" list says it's 'excluded'
 			// this means it should actually be included.
@@ -170,7 +234,7 @@
 	}
 
 	// Is it in the set of definite entries?
-	if(mDefinite.find(rTest) != mDefinite.end())
+	if(mDefinite.find(test) != mDefinite.end())
 	{
 		return true;
 	}
@@ -180,7 +244,7 @@
 	for(std::vector<regex_t *>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i)
 	{
 		// Test against this expression
-		if(regexec(*i, rTest.c_str(), 0, 0 /* no match information required */, 0 /* no flags */) == 0)
+		if(regexec(*i, test.c_str(), 0, 0 /* no match information required */, 0 /* no flags */) == 0)
 		{
 			// match happened
 			return true;

Modified: box/chris/merge/lib/common/ExcludeList.h
===================================================================
--- box/chris/merge/lib/common/ExcludeList.h	2006-10-16 23:22:17 UTC (rev 1088)
+++ box/chris/merge/lib/common/ExcludeList.h	2006-10-16 23:23:03 UTC (rev 1089)
@@ -63,6 +63,11 @@
 	std::vector<std::string> mRegexStr;	// save original regular expression string-based source for Serialize
 #endif
 
+#ifdef WIN32
+	std::string ReplaceSlashesDefinite(const std::string& input) const;
+	std::string ReplaceSlashesRegex   (const std::string& input) const;
+#endif	
+
 	// For exceptions to the excludes
 	ExcludeList *mpAlwaysInclude;
 };




More information about the Boxbackup-commit mailing list