mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/utf8_decoder] nextCodePointPointer is now stringPosition
This commit is contained in:
@@ -11,8 +11,8 @@ int CursorIndexInCommandText(const char * text) {
|
||||
UTF8Decoder decoder(text);
|
||||
size_t index = 0;
|
||||
const char * currentPointer = text;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
while (codePoint != KDCodePointNull) {
|
||||
if (codePoint == '(' || codePoint == '\'') {
|
||||
return index + 1;
|
||||
@@ -22,8 +22,8 @@ int CursorIndexInCommandText(const char * text) {
|
||||
}
|
||||
index+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ size_t CursorIndexInCommand(const char * text) {
|
||||
size_t index = 0;
|
||||
UTF8Decoder decoder(text);
|
||||
const char * currentPointer = text;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
while (codePoint != KDCodePointNull) {
|
||||
if (codePoint == KDCodePointEmpty) {
|
||||
return index;
|
||||
@@ -18,8 +18,8 @@ size_t CursorIndexInCommand(const char * text) {
|
||||
if (codePoint == '\'') {
|
||||
index+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
if (codePoint == '\'') {
|
||||
return index;
|
||||
}
|
||||
@@ -28,8 +28,8 @@ size_t CursorIndexInCommand(const char * text) {
|
||||
}
|
||||
index+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
class UTF8Decoder {
|
||||
public:
|
||||
UTF8Decoder(const char * string) : m_string(string) {}
|
||||
/* TODO: Rename methods? nextCodePoint increases m_string but
|
||||
* nextCodePointPointer does not */
|
||||
CodePoint nextCodePoint();
|
||||
const char * nextCodePointPointer();
|
||||
const char * stringPosition() const { return m_string; }
|
||||
static size_t CharSizeOfCodePoint(CodePoint c);
|
||||
static size_t CodePointToChars(CodePoint c, char * buffer, int bufferSize);
|
||||
private:
|
||||
|
||||
@@ -25,10 +25,6 @@ CodePoint UTF8Decoder::nextCodePoint() {
|
||||
return CodePoint(result);
|
||||
}
|
||||
|
||||
const char * UTF8Decoder::nextCodePointPointer() {
|
||||
return m_string + leading_ones(*m_string);
|
||||
}
|
||||
|
||||
size_t UTF8Decoder::CharSizeOfCodePoint(CodePoint c) {
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength;
|
||||
char buffer[bufferSize];
|
||||
|
||||
@@ -10,12 +10,12 @@ static inline int min(int x, int y) { return x < y ? x : y; }
|
||||
const char * CodePointSearch(const char * s, CodePoint c) {
|
||||
UTF8Decoder decoder(s);
|
||||
const char * currentPointer = s;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
while (codePoint != KDCodePointNull && codePoint != c) {
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
if (codePoint == c) {
|
||||
return currentPointer;
|
||||
@@ -26,9 +26,9 @@ const char * CodePointSearch(const char * s, CodePoint c) {
|
||||
void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c, size_t * indexToUpdate) {
|
||||
UTF8Decoder decoder(src);
|
||||
const char * currentPointer = src;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
const char * maxPointer = src + strlen(src) + 1;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
size_t bufferIndex = 0;
|
||||
size_t codePointCharSize = UTF8Decoder::CharSizeOfCodePoint(c);
|
||||
|
||||
@@ -43,8 +43,8 @@ void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePo
|
||||
*indexToUpdate-= codePointCharSize;
|
||||
}
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const
|
||||
HorizontalLayout resultLayout = HorizontalLayout::Builder();
|
||||
UTF8Decoder decoder(buffer);
|
||||
const char * currentPointer = buffer;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
assert(!codePoint.isCombining());
|
||||
int layoutIndex = 0;
|
||||
int bufferIndex = 0;
|
||||
@@ -69,13 +69,13 @@ HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const
|
||||
layoutIndex++;
|
||||
bufferIndex+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
while (codePoint.isCombining()) {
|
||||
bufferIndex+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
}
|
||||
return resultLayout;
|
||||
|
||||
@@ -15,18 +15,18 @@ static inline bool isDigit(const CodePoint c) {
|
||||
const CodePoint Tokenizer::nextCodePoint(PopTest popTest, CodePoint context, bool * testResult) {
|
||||
UTF8Decoder decoder(m_text);
|
||||
const char * currentPointer = m_text;
|
||||
const char * nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint firstCodePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
size_t numberOfBytesForCodePoint = nextPointer - currentPointer;
|
||||
if (firstCodePoint != KDCodePointNull) {
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
while (codePoint.isCombining()) {
|
||||
numberOfBytesForCodePoint+= nextPointer - currentPointer;
|
||||
currentPointer = nextPointer;
|
||||
nextPointer = decoder.nextCodePointPointer();
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
}
|
||||
// TODO handle combined code points? For now the combining codepoints get dropped.
|
||||
|
||||
Reference in New Issue
Block a user