2018-08-22 12:24:55 -04:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-19 00:13:19 -04:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
2018-09-20 22:32:47 -04:00
|
|
|
#include <cstdint>
|
2018-08-19 00:13:19 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
struct InfoForExtension
|
|
|
|
{
|
2018-09-22 15:08:31 -04:00
|
|
|
const char* name;
|
|
|
|
int64_t value;
|
|
|
|
InfoForExtension* next;
|
2018-08-19 00:13:19 -04:00
|
|
|
};
|
|
|
|
|
2018-09-22 15:08:31 -04:00
|
|
|
struct SentenceInfo
|
2018-08-19 00:13:19 -04:00
|
|
|
{
|
2018-09-22 15:08:31 -04:00
|
|
|
const InfoForExtension* list;
|
|
|
|
// Traverse linked list to find info.
|
|
|
|
int64_t operator[](std::string propertyName)
|
|
|
|
{
|
|
|
|
for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value;
|
2018-10-07 11:02:00 -04:00
|
|
|
throw;
|
2018-09-22 15:08:31 -04:00
|
|
|
}
|
|
|
|
};
|
2018-08-19 00:13:19 -04:00
|
|
|
|
2018-10-09 17:43:33 -04:00
|
|
|
struct InvalidSentence {};
|
|
|
|
|
2018-09-22 15:08:31 -04:00
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
|
2018-09-01 04:24:22 -04:00
|
|
|
|
|
|
|
/**
|
2018-09-22 15:08:31 -04:00
|
|
|
* You shouldn't mess with this or even look at it unless you're certain you know what you're doing.
|
2018-09-29 16:05:08 -04: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 11:02:00 -04:00
|
|
|
* Please allocate the buffer using HeapAlloc() and not new[] or malloc() or something else: Textractor uses HeapFree() to free it.
|
2018-09-01 04:24:22 -04:00
|
|
|
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
2018-10-10 06:16:47 -04:00
|
|
|
* Return value: pointer to sentence Textractor takes for future processing and display. If nullptr, Textractor will destroy the sentence.
|
2018-09-01 04:24:22 -04:00
|
|
|
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
2018-09-29 16:05:08 -04:00
|
|
|
* Textractor will display the sentence after all extensions have had a chance to process and/or modify it.
|
2018-09-01 04:24:22 -04:00
|
|
|
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
|
|
|
*/
|
2018-10-09 17:43:33 -04:00
|
|
|
extern "C" __declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
|
2018-09-01 04:24:22 -04:00
|
|
|
{
|
2018-10-09 17:43:33 -04:00
|
|
|
try
|
2018-09-01 04:24:22 -04:00
|
|
|
{
|
2018-10-09 17:43:33 -04:00
|
|
|
std::wstring sentenceStr(sentence);
|
|
|
|
if (ProcessSentence(sentenceStr, SentenceInfo{ miscInfo }))
|
|
|
|
{
|
|
|
|
// No need to worry about freeing this: Textractor does it for you.
|
|
|
|
wchar_t* newSentence = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentenceStr.size() + 1) * sizeof(wchar_t));
|
|
|
|
wcscpy_s(newSentence, sentenceStr.size() + 1, sentenceStr.c_str());
|
|
|
|
return newSentence;
|
|
|
|
}
|
|
|
|
else return sentence;
|
2018-09-01 04:24:22 -04:00
|
|
|
}
|
2018-10-09 17:43:33 -04:00
|
|
|
catch (InvalidSentence) { return nullptr; }
|
2018-09-22 15:08:31 -04:00
|
|
|
}
|