Browse Source

added a way through add ins to get/set the description

scott brogden 5 years ago
parent
commit
72b6ff25a5
4 changed files with 10 additions and 7 deletions
  1. 1 1
      ChaiScriptOnCopy.cpp
  2. 7 4
      DittoChaiScript.cpp
  3. 1 1
      DittoChaiScript.h
  4. 1 1
      ScriptEditor.cpp

+ 1 - 1
ChaiScriptOnCopy.cpp

@@ -50,7 +50,7 @@ bool ChaiScriptOnCopy::ProcessScript(CDittoChaiScript &clipData, std::string scr
 		chai.add(chaiscript::fun(&CDittoChaiScript::AsciiTextReplaceRegex), "AsciiTextReplaceRegex");
 
 		chai.add(chaiscript::fun(&CDittoChaiScript::DescriptionMatchesRegex), "DescriptionMatchesRegex");
-		chai.add(chaiscript::fun(&CDittoChaiScript::SetDescription), "SetDescription");
+		chai.add(chaiscript::fun(&CDittoChaiScript::DescriptionReplaceRegex), "DescriptionReplaceRegex");
 
 		chai.add(chaiscript::fun(&FormatCurrentTime), "FormatCurrentTime");
 

+ 7 - 4
DittoChaiScript.cpp

@@ -165,8 +165,6 @@ BOOL CDittoChaiScript::AsciiTextMatchesRegex(std::string regex)
 
 void CDittoChaiScript::AsciiTextReplaceRegex(std::string regex, std::string replaceWith)
 {
-	BOOL matches = false;
-
 	auto ascii = GetAsciiString();
 	std::regex integer(regex);
 
@@ -206,11 +204,16 @@ BOOL CDittoChaiScript::DescriptionMatchesRegex(std::string regex)
 	}
 }
 
-void CDittoChaiScript::SetDescription(std::string stringVal)
+void CDittoChaiScript::DescriptionReplaceRegex(std::string regex, std::string replaceWith)
 {
 	if (m_pClip)
 	{
-		CString cstr(stringVal.c_str());
+		std:string ascii(CTextConvert::ConvertToChar(m_pClip->Description()).GetBuffer());
+		std::regex integer(regex);
+
+		auto newAscii = regex_replace(ascii, integer, replaceWith);
+
+		CString cstr(newAscii.c_str());
 		m_pClip->Description(cstr);
 	}
 }

+ 1 - 1
DittoChaiScript.h

@@ -30,7 +30,7 @@ public:
 	void AsciiTextReplaceRegex(std::string regex, std::string replaceWith);
 
 	BOOL DescriptionMatchesRegex(std::string regex);
-	void SetDescription(std::string stringVal);
+	void DescriptionReplaceRegex(std::string regex, std::string replaceWith);
 
 	void SetMakeTopSticky();
 	void SetMakeLastSticky();

+ 1 - 1
ScriptEditor.cpp

@@ -285,7 +285,7 @@ void CScriptEditor::OnBnClickedButtonRun()
 	ChaiScriptOnCopy test;
 	CDittoChaiScript clipData(&clip, (LPCSTR)CTextConvert::UnicodeStringToMultiByte(app), (LPCSTR)CTextConvert::UnicodeStringToMultiByte(appTitle));
 	clipData.SetAsciiString((LPCSTR)CTextConvert::UnicodeStringToMultiByte(input));
-	clipData.SetDescription((LPCSTR)CTextConvert::UnicodeStringToMultiByte(input));
+	clipData.DescriptionReplaceRegex(".*", (LPCSTR)CTextConvert::UnicodeStringToMultiByte(input));
 	
 	test.ProcessScript(clipData, (LPCSTR)CTextConvert::UnicodeStringToMultiByte(script));