24#include "UTF8Util.hpp"
36inline constexpr size_t kDefaultStreamKeepChars = 16;
52inline size_t FlushableByteCount(std::string_view pending,
53 size_t maxKeepChars) {
54 if (pending.empty()) {
58 const char* bufferBegin = pending.data();
59 const char* bufferEnd = bufferBegin + pending.size();
60 const char* completeEnd = bufferBegin;
61 while (completeEnd < bufferEnd) {
63 if (completeEnd + nextCharLen > bufferEnd) {
66 completeEnd += nextCharLen;
69 const char* keepStart = completeEnd;
71 while (keepStart > bufferBegin && charsKept < maxKeepChars) {
73 keepStart -= prevCharLen;
77 const char* idsKeepStart = completeEnd;
78 const char* idsCandidate = completeEnd;
79 size_t idsCharsScanned = 0;
80 const size_t kMaxIDSCodePoints = 64;
81 while (idsCandidate > bufferBegin && idsCharsScanned < kMaxIDSCodePoints) {
84 if (UTF8Util::IsIncompleteIdeographicDescriptionSequencePrefix(
85 idsCandidate, completeEnd - idsCandidate)) {
86 idsKeepStart = idsCandidate;
89 if (idsKeepStart < keepStart) {
90 keepStart = idsKeepStart;
93 return static_cast<size_t>(keepStart - bufferBegin);
static size_t PrevCharLength(const char *str)
Returns the length in byte for the previous UTF8 character.
Definition UTF8Util.hpp:82
static size_t NextCharLength(const char *str)
Returns the length in byte for the next UTF8 character.
Definition UTF8Util.hpp:71