MCPcopy Create free account
hub / github.com/Artikash/Textractor / Push

Method Push

host/textthread.cpp:38–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void TextThread::Push(BYTE* data, int length)
39{
40 if (length < 0) return;
41 std::scoped_lock lock(bufferMutex);
42
43 BYTE doubleByteChar[2];
44 if (length == 1) // doublebyte characters must be processed as pairs
45 {
46 if (leadByte)
47 {
48 doubleByteChar[0] = leadByte;
49 doubleByteChar[1] = data[0];
50 data = doubleByteChar;
51 length = 2;
52 leadByte = 0;
53 }
54 else if (IsDBCSLeadByteEx(hp.codepage ? hp.codepage : Host::defaultCodepage, data[0]))
55 {
56 leadByte = data[0];
57 length = 0;
58 }
59 }
60
61 if (hp.type & HEX_DUMP) for (int i = 0; i < length; i += sizeof(short)) buffer.append(FormatString(L"%04hX ", *(short*)(data + i)));
62 else if (hp.type & USING_UNICODE) buffer.append((wchar_t*)data, length / sizeof(wchar_t));
63 else if (auto converted = StringToWideString(std::string((char*)data, length), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer.append(converted.value());
64 else Host::AddConsoleOutput(INVALID_CODEPAGE);
65 if (hp.type & FULL_STRING) buffer.push_back(L'\n');
66 lastPushTime = GetTickCount64();
67
68 if (filterRepetition)
69 {
70 if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t ch) { return repeatingChars.find(ch) != repeatingChars.end(); })) buffer.clear();
71 if (RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received
72 {
73 repeatingChars = std::unordered_set(buffer.begin(), buffer.end());
74 AddSentence(std::move(buffer));
75 buffer.clear();
76 }
77 }
78
79 if (flushDelay == 0 && hp.type & FULL_STRING)
80 {
81 AddSentence(std::move(buffer));
82 buffer.clear();
83 }
84}
85
86void TextThread::Push(const wchar_t* data)
87{

Callers 2

CreatePipeFunction · 0.80
GetSentenceInfoFunction · 0.80

Calls 4

FormatStringFunction · 0.85
StringToWideStringFunction · 0.85
AddConsoleOutputFunction · 0.85
RemoveRepetitionFunction · 0.85

Tested by

no test coverage detected