2018-10-12 02:29:11 +08:00
|
|
|
#include "extension.h"
|
2018-10-10 05:43:33 +08:00
|
|
|
|
2018-09-23 03:08:31 +08:00
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
|
2018-09-01 16:24:22 +08:00
|
|
|
|
|
|
|
/**
|
2018-09-23 03:08:31 +08:00
|
|
|
* You shouldn't mess with this or even look at it unless you're certain you know what you're doing.
|
2018-09-30 04:05:08 +08:00
|
|
|
* Param sentence: pointer to sentence received by Textractor (UTF-16).
|
|
|
|
* You should not modify this sentence. If you want Textractor to receive a modified sentence, copy it into your own buffer and return that.
|
2018-10-07 23:02:00 +08:00
|
|
|
* Please allocate the buffer using HeapAlloc() and not new[] or malloc() or something else: Textractor uses HeapFree() to free it.
|
2018-09-01 16:24:22 +08:00
|
|
|
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
2018-10-10 18:16:47 +08:00
|
|
|
* Return value: pointer to sentence Textractor takes for future processing and display. If nullptr, Textractor will destroy the sentence.
|
2018-09-01 16:24:22 +08:00
|
|
|
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
2018-09-30 04:05:08 +08:00
|
|
|
* Textractor will display the sentence after all extensions have had a chance to process and/or modify it.
|
2018-09-01 16:24:22 +08:00
|
|
|
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
|
|
|
*/
|
2019-01-24 02:59:34 +08:00
|
|
|
extern "C" __declspec(dllexport) wchar_t* OnNewSentence(wchar_t* sentence, const InfoForExtension* miscInfo)
|
2018-09-01 16:24:22 +08:00
|
|
|
{
|
2018-10-10 05:43:33 +08:00
|
|
|
try
|
2018-09-01 16:24:22 +08:00
|
|
|
{
|
2018-10-10 05:43:33 +08:00
|
|
|
std::wstring sentenceStr(sentence);
|
2019-01-24 02:59:34 +08:00
|
|
|
int origLength = sentenceStr.size();
|
2018-10-10 05:43:33 +08:00
|
|
|
if (ProcessSentence(sentenceStr, SentenceInfo{ miscInfo }))
|
|
|
|
{
|
2019-01-31 03:51:08 +08:00
|
|
|
if (sentenceStr.empty()) return nullptr;
|
2018-10-10 05:43:33 +08:00
|
|
|
// No need to worry about freeing this: Textractor does it for you.
|
2019-01-24 02:59:34 +08:00
|
|
|
wchar_t* newSentence = sentenceStr.size() > origLength ? (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentenceStr.size() + 1) * sizeof(wchar_t)) : sentence;
|
2018-10-10 05:43:33 +08:00
|
|
|
wcscpy_s(newSentence, sentenceStr.size() + 1, sentenceStr.c_str());
|
|
|
|
return newSentence;
|
|
|
|
}
|
|
|
|
else return sentence;
|
2018-09-01 16:24:22 +08:00
|
|
|
}
|
2018-10-12 02:29:11 +08:00
|
|
|
catch (SKIP) { return nullptr; }
|
2018-09-23 03:08:31 +08:00
|
|
|
}
|