• R/O
  • HTTP
  • SSH
  • HTTPS

winmerge-jp: 提交


Commit MetaInfo

修订版74e12673ed60642aaf23cd47a38bfc0d0c9de5a8 (tree)
时间2021-11-26 23:47:42
作者Takashi Sawanaka <sdottaka@user...>
CommiterTakashi Sawanaka

Log Message

Fix issue #1057: Source Files Comparison doesn't seem to Work properly

更改概述

差异

--- a/Src/DiffWrapper.cpp
+++ b/Src/DiffWrapper.cpp
@@ -56,6 +56,8 @@ using Poco::Exception;
5656
5757 extern int recursive;
5858
59+extern "C" int is_blank_line(char const* pch, char const* limit);
60+
5961 static void CopyTextStats(const file_data * inf, FileTextStats * myTextStats);
6062 static void CopyDiffutilTextStats(file_data *inf, DiffFileData * diffData);
6163
@@ -291,37 +293,39 @@ static unsigned GetCommentsFilteredText(unsigned dwCookie, int startLine, int en
291293 }
292294
293295 /**
294- * @brief Replace spaces in a string
295- * @param [in] str - String to search
296- * @param [in] rep - String to replace
296+ * @brief Replace a string inside a string with another string.
297+ * This function searches for a string inside another string an if found,
298+ * replaces it with another string. Function can replace several instances
299+ * of the string inside one string.
300+ * @param [in,out] target A string containing another string to replace.
301+ * @param [in] find A string to search and replace with another (@p replace).
302+ * @param [in] replace A string used to replace original (@p find).
297303 */
298-static void ReplaceSpaces(std::string & str, const char *rep)
304+void Replace(std::string &target, const std::string &find, const std::string &replace)
299305 {
306+ const std::string::size_type find_len = find.length();
307+ const std::string::size_type replace_len = replace.length();
300308 std::string::size_type pos = 0;
301- size_t replen = strlen(rep);
302- while ((pos = str.find_first_of(" \t", pos)) != std::string::npos)
309+ while ((pos = target.find(find, pos)) != std::string::npos)
303310 {
304- std::string::size_type posend = str.find_first_not_of(" \t", pos);
305- if (posend != String::npos)
306- str.replace(pos, posend - pos, rep);
307- else
308- str.replace(pos, str.length() - pos, rep);
309- pos += replen;
311+ target.replace(pos, find_len, replace);
312+ pos += replace_len;
310313 }
311314 }
312315
313316 /**
314- * @brief Replace spaces in a string
315- * @param [in] str - String to search
317+ * @brief Replace the characters that matche characters specified in its arguments
318+ * @param [in,out] str - A string containing another string to replace.
319+ * @param [in] chars - characters to search for
316320 * @param [in] rep - String to replace
317321 */
318-static void ReplaceNumbers(std::string& str, const char* rep)
322+static void ReplaceChars(std::string & str, const char* chars, const char *rep)
319323 {
320324 std::string::size_type pos = 0;
321325 size_t replen = strlen(rep);
322- while ((pos = str.find_first_of("0123456789", pos)) != std::string::npos)
326+ while ((pos = str.find_first_of(chars, pos)) != std::string::npos)
323327 {
324- std::string::size_type posend = str.find_first_not_of("0123456789", pos);
328+ std::string::size_type posend = str.find_first_not_of(chars, pos);
325329 if (posend != String::npos)
326330 str.replace(pos, posend - pos, rep);
327331 else
@@ -331,6 +335,26 @@ static void ReplaceNumbers(std::string& str, const char* rep)
331335 }
332336
333337 /**
338+ * @brief Remove blank lines
339+ */
340+void RemoveBlankLines(std::string &str)
341+{
342+ size_t pos = 0;
343+ while (pos < str.length())
344+ {
345+ size_t posend = str.find_first_of("\r\n", pos);
346+ if (posend != std::string::npos)
347+ posend = str.find_first_not_of("\r\n", posend);
348+ if (posend == std::string::npos)
349+ posend = str.length();
350+ if (is_blank_line(str.data() + pos, str.data() + posend))
351+ str.erase(pos, posend - pos);
352+ else
353+ pos = posend;
354+ }
355+}
356+
357+/**
334358 @brief The main entry for post filtering. Performs post-filtering, by setting comment blocks to trivial
335359 @param [in] LineNumberLeft - First line number to read from left file
336360 @param [in] QtyLinesLeft - Number of lines in the block for left file
@@ -380,23 +404,22 @@ void CDiffWrapper::PostFilter(PostFilterContext& ctxt, int LineNumberLeft, int Q
380404 if (m_options.m_ignoreWhitespace == WHITESPACE_IGNORE_ALL)
381405 {
382406 //Ignore character case
383- ReplaceSpaces(LineDataLeft, "");
384- ReplaceSpaces(LineDataRight, "");
407+ ReplaceChars(LineDataLeft, " \t", "");
408+ ReplaceChars(LineDataRight, " \t", "");
385409 }
386410 else if (m_options.m_ignoreWhitespace == WHITESPACE_IGNORE_CHANGE)
387411 {
388412 //Ignore change in whitespace char count
389- ReplaceSpaces(LineDataLeft, " ");
390- ReplaceSpaces(LineDataRight, " ");
413+ ReplaceChars(LineDataLeft, " \t", " ");
414+ ReplaceChars(LineDataRight, " \t", " ");
391415 }
392416
393417 if (m_options.m_bIgnoreNumbers )
394418 {
395419 //Ignore number character case
396- ReplaceNumbers(LineDataLeft, "");
397- ReplaceNumbers(LineDataRight, "");
420+ ReplaceChars(LineDataLeft, "0123456789", "");
421+ ReplaceChars(LineDataRight, "0123456789", "");
398422 }
399-
400423 if (m_options.m_bIgnoreCase)
401424 {
402425 //ignore case
@@ -407,6 +430,18 @@ void CDiffWrapper::PostFilter(PostFilterContext& ctxt, int LineNumberLeft, int Q
407430 for (std::string::iterator pb = LineDataRight.begin(), pe = LineDataRight.end(); pb != pe; ++pb)
408431 *pb = static_cast<char>(::toupper(*pb));
409432 }
433+ if (m_options.m_bIgnoreEOLDifference)
434+ {
435+ Replace(LineDataLeft, "\r\n", "\n");
436+ Replace(LineDataLeft, "\r", "\n");
437+ Replace(LineDataRight, "\r\n", "\n");
438+ Replace(LineDataRight, "\r", "\n");
439+ }
440+ if (m_options.m_bIgnoreBlankLines)
441+ {
442+ RemoveBlankLines(LineDataLeft);
443+ RemoveBlankLines(LineDataRight);
444+ }
410445 if (LineDataLeft != LineDataRight)
411446 return;
412447 //only difference is trival
Show on old repository browser