Commit 05b6c466 authored by Nuno Sucena Almeida's avatar Nuno Sucena Almeida Committed by David Schulz
Browse files

Fix crash on case-preserving replace



Task-number: QTCREATORBUG-8821

Change-Id: Icb843108bd48dd1266469667f318a5ef32b05e06
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent eb97b2b1
...@@ -352,6 +352,9 @@ namespace Utils { ...@@ -352,6 +352,9 @@ namespace Utils {
namespace Internal { namespace Internal {
QString matchCaseReplacement(const QString &originalText, const QString &replaceText) QString matchCaseReplacement(const QString &originalText, const QString &replaceText)
{ {
if (originalText.isEmpty())
return replaceText;
//Now proceed with actual case matching //Now proceed with actual case matching
bool firstIsUpperCase = originalText.at(0).isUpper(); bool firstIsUpperCase = originalText.at(0).isUpper();
bool firstIsLowerCase = originalText.at(0).isLower(); bool firstIsLowerCase = originalText.at(0).isLower();
...@@ -397,12 +400,12 @@ QString Utils::matchCaseReplacement(const QString &originalText, const QString & ...@@ -397,12 +400,12 @@ QString Utils::matchCaseReplacement(const QString &originalText, const QString &
const int originalTextLen = originalText.length(); const int originalTextLen = originalText.length();
int prefixLen = 0; int prefixLen = 0;
for (; prefixLen <= replaceTextLen && prefixLen <= originalTextLen; prefixLen++) for (; prefixLen < replaceTextLen && prefixLen < originalTextLen; ++prefixLen)
if (replaceText.at(prefixLen).toLower() != originalText.at(prefixLen).toLower()) if (replaceText.at(prefixLen).toLower() != originalText.at(prefixLen).toLower())
break; break;
int suffixLen = 0; int suffixLen = 0;
for (; suffixLen < replaceTextLen - prefixLen && suffixLen < originalTextLen - prefixLen; suffixLen++) for (; suffixLen < replaceTextLen - prefixLen && suffixLen < originalTextLen - prefixLen; ++suffixLen)
if (replaceText.at(replaceTextLen - 1 - suffixLen).toLower() != originalText.at(originalTextLen- 1 - suffixLen).toLower()) if (replaceText.at(replaceTextLen - 1 - suffixLen).toLower() != originalText.at(originalTextLen- 1 - suffixLen).toLower())
break; break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment