mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 08:47:28 +01:00
We used a small buffer to preprocess a text to insert in text area (add indentation, remove empty code points, compute the next cursor location), but the size of this buffer was sometimes too small and caused a crash. Now we do all the text odification in place in the text area buffer.
33 lines
1.0 KiB
C++
33 lines
1.0 KiB
C++
#include <escher/text_input_helpers.h>
|
|
#include <ion/unicode/utf8_decoder.h>
|
|
#include <string.h>
|
|
|
|
namespace TextInputHelpers {
|
|
|
|
const char * CursorPositionInCommand(const char * text, const char * stoppingPosition) {
|
|
assert(stoppingPosition == nullptr || text <= stoppingPosition);
|
|
UTF8Decoder decoder(text);
|
|
const char * currentPointer = text;
|
|
CodePoint codePoint = decoder.nextCodePoint();
|
|
while ((stoppingPosition == nullptr || currentPointer < stoppingPosition) && codePoint != UCodePointNull) {
|
|
if (codePoint == UCodePointEmpty) {
|
|
return currentPointer;
|
|
}
|
|
//TODO make sure changing empty / ' order was OK
|
|
if (codePoint == '\'') {
|
|
currentPointer = decoder.stringPosition();
|
|
codePoint = decoder.nextCodePoint();
|
|
if (codePoint == '\'') {
|
|
return currentPointer;
|
|
}
|
|
// Continue because we already incremented codePoint
|
|
continue;
|
|
}
|
|
currentPointer = decoder.stringPosition();
|
|
codePoint = decoder.nextCodePoint();
|
|
}
|
|
return currentPointer;
|
|
}
|
|
|
|
}
|