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).
|
2019-02-19 09:57:10 +08:00
|
|
|
* This can be modified. Textractor uses the modified sentence for future processing and display. If empty (starts with null terminator), Textractor will destroy it.
|
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.
|
2019-02-19 09:57:10 +08:00
|
|
|
* The buffer is allocated using HeapAlloc(). If you want to make it larger, please use HeapReAlloc().
|
|
|
|
* Param miscInfo: pointer to array containing misc info about the sentence. End of array is marked with name being nullptr.
|
|
|
|
* Return value: the buffer used for the sentence. Remember to return a new pointer if HeapReAlloc() gave you one.
|
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-02-19 09:57:10 +08:00
|
|
|
if (sentenceStr.size() > origLength) sentence = (wchar_t*)HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sentence, (sentenceStr.size() + 1) * sizeof(wchar_t));
|
|
|
|
wcscpy_s(sentence, sentenceStr.size() + 1, sentenceStr.c_str());
|
2018-10-10 05:43:33 +08:00
|
|
|
}
|
2018-09-01 16:24:22 +08:00
|
|
|
}
|
2019-02-19 09:57:10 +08:00
|
|
|
catch (SKIP)
|
|
|
|
{
|
|
|
|
*sentence = L'\0';
|
|
|
|
}
|
|
|
|
return sentence;
|
2018-09-23 03:08:31 +08:00
|
|
|
}
|