Преглед изворни кода

fixed issue AsciiTextReplaceRegex not working

Scott Brogden пре 4 година
родитељ
комит
817e8496f2
2 измењених фајлова са 25 додато и 18 уклоњено
  1. 18 17
      DittoChaiScript.cpp
  2. 7 1
      ScriptEditor.cpp

+ 18 - 17
DittoChaiScript.cpp

@@ -170,7 +170,9 @@ BOOL CDittoChaiScript::SetParentId(int parentId)
 		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE lID = %d"), parentId);
 		if (q.eof() == false)
 		{
-			m_pClip->Parent(parentId);			
+			m_pClip->Parent(parentId);		
+
+			set = TRUE;
 		}
 	}
 
@@ -181,9 +183,9 @@ BOOL CDittoChaiScript::AsciiTextMatchesRegex(std::string regex)
 {
 	BOOL matches = false;
 
-	auto ascii = GetUnicodeString();
+	std::wstring unicode = GetUnicodeString();
 	std::wregex integer(CTextConvert::AnsiToUnicode(regex.c_str()));
-	if (regex_match(ascii, integer))
+	if (regex_match(unicode, integer))
 	{
 		matches = true;
 	}
@@ -192,13 +194,13 @@ BOOL CDittoChaiScript::AsciiTextMatchesRegex(std::string regex)
 
 void CDittoChaiScript::AsciiTextReplaceRegex(std::string regex, std::string replaceWith)
 {
-	if (AsciiTextMatchesRegex(regex))
-	{
-		CStringA ascii = CTextConvert::UnicodeToUTF8(GetUnicodeString().c_str());
-		std::regex integer(regex.c_str());
+	CStringA utf8 = CTextConvert::UnicodeToUTF8(GetUnicodeString().c_str());
+	std::regex integer(regex.c_str());
 
-		auto newAscii = std::regex_replace(ascii.GetBuffer(), integer, replaceWith);
-		SetUnicodeString(CTextConvert::Utf8ToUnicode(newAscii.c_str()).GetBuffer());
+	CStringA newUtf8 = std::regex_replace(utf8.GetBuffer(), integer, replaceWith).c_str();
+	if (utf8 != newUtf8)
+	{
+		SetUnicodeString(CTextConvert::Utf8ToUnicode(newUtf8).GetBuffer());
 	}
 }
 
@@ -224,9 +226,9 @@ BOOL CDittoChaiScript::DescriptionMatchesRegex(std::string regex)
 
 	if (m_pClip)
 	{
-		std:string ascii(CTextConvert::UnicodeToAnsi(m_pClip->Description()).GetBuffer());
-		std::regex integer(regex);
-		if (regex_match(ascii, integer))
+		std::wstring unicode = m_pClip->Description();
+		std::wregex integer(CTextConvert::AnsiToUnicode(regex.c_str()));
+		if (regex_match(unicode, integer))
 		{
 			matches = true;
 		}
@@ -239,12 +241,11 @@ void CDittoChaiScript::DescriptionReplaceRegex(std::string regex, std::string re
 {
 	if (m_pClip)
 	{
-		std:string ascii(CTextConvert::UnicodeToAnsi(m_pClip->Description()).GetBuffer());
-		std::regex integer(regex);
+		CStringA utf8 = CTextConvert::UnicodeToUTF8(m_pClip->Description());
+		std::regex integer(regex.c_str());
 
-		auto newAscii = regex_replace(ascii, integer, replaceWith);
+		auto newAscii = std::regex_replace(utf8.GetBuffer(), integer, replaceWith);
 
-		CString cstr(newAscii.c_str());
-		m_pClip->Description(cstr);
+		m_pClip->Description(CTextConvert::Utf8ToUnicode(newAscii.c_str()).GetBuffer());
 	}
 }

+ 7 - 1
ScriptEditor.cpp

@@ -291,7 +291,13 @@ void CScriptEditor::OnBnClickedButtonRun()
 
 	if (test.m_lastError == _T(""))
 	{
-		SetDlgItemText(IDC_EDIT_OUTPUT, _T("returned false\r\n") + CTextConvert::AnsiToUnicode(clipData.GetAsciiString().c_str()));
+		CString currentString = CTextConvert::AnsiToUnicode(clipData.GetAsciiString().c_str());
+		if (currentString == _T(""))
+		{
+			currentString = clipData.GetUnicodeString().c_str();
+		}
+
+		SetDlgItemText(IDC_EDIT_OUTPUT, _T("returned false\r\n") + currentString);
 	}
 	else
 	{