mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
Revert "[ion] Namespace Ion::UTF8Helper and Ion::UTF8Decoder"
This reverts commit 23da0d3f2c.
This commit is contained in:
@@ -48,7 +48,7 @@ bool App::Snapshot::lockOnConsole() const {
|
||||
void App::Snapshot::setOpt(const char * name, char * value) {
|
||||
if (strcmp(name, "script") == 0) {
|
||||
m_scriptStore.deleteAllScripts();
|
||||
char * separator = const_cast<char *>(Ion::UTF8Helper::CodePointSearch(value, ':'));
|
||||
char * separator = const_cast<char *>(UTF8Helper::CodePointSearch(value, ':'));
|
||||
if (!separator) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,9 +70,9 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
|
||||
/* If the cursor is on the left of the text of a line, backspace one
|
||||
* indentation space at a time. */
|
||||
const char * text = textArea->text();
|
||||
const char * firstNonSpace = Ion::UTF8Helper::NotCodePointSearch(text, ' ', true, textArea->cursorLocation());
|
||||
const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' ', true, textArea->cursorLocation());
|
||||
assert(firstNonSpace >= text);
|
||||
if (Ion::UTF8Helper::CodePointIs(firstNonSpace, '\n') && ((text - firstNonSpace)/Ion::UTF8Decoder::CharSizeOfCodePoint(' ')) >= k_indentationSpacesNumber) {
|
||||
if (UTF8Helper::CodePointIs(firstNonSpace, '\n') && ((text - firstNonSpace)/UTF8Decoder::CharSizeOfCodePoint(' ')) >= k_indentationSpacesNumber) {
|
||||
for (int i = 0; i < k_indentationSpacesNumber; i++) {
|
||||
textArea->removeCodePoint();
|
||||
}
|
||||
@@ -82,10 +82,10 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
|
||||
/* If the cursor is on the left of the text of a line, a space triggers an
|
||||
* indentation. */
|
||||
const char * text = textArea->text();
|
||||
const char * firstNonSpace = Ion::UTF8Helper::NotCodePointSearch(text, ' ', true, textArea->cursorLocation());
|
||||
const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' ', true, textArea->cursorLocation());
|
||||
assert(firstNonSpace >= text);
|
||||
if (Ion::UTF8Helper::CodePointIs(firstNonSpace, '\n')) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
if (UTF8Helper::CodePointIs(firstNonSpace, '\n')) {
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
char indentationBuffer[k_indentationSpacesNumber+1];
|
||||
for (int i = 0; i < k_indentationSpacesNumber; i++) {
|
||||
indentationBuffer[i] = ' ';
|
||||
|
||||
@@ -313,7 +313,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
|
||||
bool foundDefaultName = Script::DefaultName(numberedDefaultName, Script::k_defaultScriptNameMaxSize);
|
||||
int defaultNameLength = strlen(numberedDefaultName);
|
||||
assert(defaultNameLength < bufferSize);
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
numberedDefaultName[defaultNameLength++] = '.';
|
||||
strlcpy(numberedDefaultName + defaultNameLength, ScriptStore::k_scriptExtension, bufferSize - defaultNameLength);
|
||||
/* If there are already scripts named script1.py, script2.py,... until
|
||||
|
||||
@@ -99,8 +99,8 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
LOG_DRAW("Drawing \"%.*s\"\n", byteLength, text);
|
||||
|
||||
if (!m_pythonDelegate->isPythonUser(this)) {
|
||||
const char * lineStart = Ion::UTF8Helper::CodePointAtGlyphOffset(text, fromColumn);
|
||||
const char * lineEnd = Ion::UTF8Helper::CodePointAtGlyphOffset(text, toColumn);
|
||||
const char * lineStart = UTF8Helper::CodePointAtGlyphOffset(text, fromColumn);
|
||||
const char * lineEnd = UTF8Helper::CodePointAtGlyphOffset(text, toColumn);
|
||||
drawStringAt(
|
||||
ctx,
|
||||
line,
|
||||
@@ -119,8 +119,8 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
* basis. This can work, however the MicroPython lexer won't accept a line
|
||||
* starting with a whitespace. So we're discarding leading whitespaces
|
||||
* beforehand. */
|
||||
const char * firstNonSpace = Ion::UTF8Helper::NotCodePointSearch(text, ' ');
|
||||
if (Ion::UTF8Helper::CodePointIs(firstNonSpace, UCodePointNull)) {
|
||||
const char * firstNonSpace = UTF8Helper::NotCodePointSearch(text, ' ');
|
||||
if (UTF8Helper::CodePointIs(firstNonSpace, UCodePointNull)) {
|
||||
nlr_pop();
|
||||
return;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
tokenLength = TokenLength(lex);
|
||||
LOG_DRAW("Draw \"%.*s\" for token %d\n", tokenLength, tokenFrom, lex->tok_kind);
|
||||
drawStringAt(ctx, line,
|
||||
Ion::UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom),
|
||||
UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom),
|
||||
tokenFrom,
|
||||
tokenLength,
|
||||
TokenColor(lex->tok_kind),
|
||||
@@ -151,7 +151,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
if (tokenFrom < text + byteLength) {
|
||||
LOG_DRAW("Draw comment \"%.*s\" from %d\n", byteLength - (tokenFrom - text), firstNonSpace, tokenFrom);
|
||||
drawStringAt(ctx, line,
|
||||
Ion::UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom),
|
||||
UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom),
|
||||
tokenFrom,
|
||||
text + byteLength - tokenFrom,
|
||||
CommentColor,
|
||||
|
||||
@@ -330,7 +330,7 @@ bool PythonToolbox::handleEvent(Ion::Events::Event event) {
|
||||
}
|
||||
if (event.hasText() && strlen(event.text()) == 1 ) {
|
||||
char c = event.text()[0];
|
||||
if (Ion::UTF8Helper::CodePointIsLetter(c)) {
|
||||
if (UTF8Helper::CodePointIsLetter(c)) {
|
||||
scrollToLetter(c);
|
||||
return true;
|
||||
}
|
||||
@@ -390,7 +390,7 @@ int PythonToolbox::maxNumberOfDisplayedRows() {
|
||||
}
|
||||
|
||||
void PythonToolbox::scrollToLetter(char letter) {
|
||||
assert(Ion::UTF8Helper::CodePointIsLetter(letter));
|
||||
assert(UTF8Helper::CodePointIsLetter(letter));
|
||||
/* We look for a child MessageTree that starts with the wanted letter. If we
|
||||
* do not find one, we scroll to the first child MessageTree that starts with
|
||||
* a letter higher than the wanted letter. */
|
||||
@@ -402,7 +402,7 @@ void PythonToolbox::scrollToLetter(char letter) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
if (index < 0 && l >= lowerLetter && Ion::UTF8Helper::CodePointIsLowerCaseLetter(l)) {
|
||||
if (index < 0 && l >= lowerLetter && UTF8Helper::CodePointIsLowerCaseLetter(l)) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ bool Script::nameCompliant(const char * name) {
|
||||
* We do not allow upper cases in the script names because script names are
|
||||
* used in the URLs of the NumWorks workshop website and we do not want
|
||||
* problems with case sensitivity. */
|
||||
Ion::UTF8Decoder decoder(name);
|
||||
UTF8Decoder decoder(name);
|
||||
CodePoint c = decoder.nextCodePoint();
|
||||
if (c == UCodePointNull || !(Ion::UTF8Helper::CodePointIsLowerCaseLetter(c) || c == '_' || c == '.')) {
|
||||
if (c == UCodePointNull || !(UTF8Helper::CodePointIsLowerCaseLetter(c) || c == '_' || c == '.')) {
|
||||
/* The name cannot be empty. Its first letter must be in [a-z_] or the
|
||||
* extension dot. */
|
||||
return false;
|
||||
@@ -57,7 +57,7 @@ bool Script::nameCompliant(const char * name) {
|
||||
if (c == '.' && strcmp(decoder.stringPosition(), ScriptStore::k_scriptExtension) == 0) {
|
||||
return true;
|
||||
}
|
||||
if (!(Ion::UTF8Helper::CodePointIsLowerCaseLetter(c) || c == '_' || Ion::UTF8Helper::CodePointIsNumber(c))) {
|
||||
if (!(UTF8Helper::CodePointIsLowerCaseLetter(c) || c == '_' || UTF8Helper::CodePointIsNumber(c))) {
|
||||
return false;
|
||||
}
|
||||
c = decoder.nextCodePoint();
|
||||
|
||||
@@ -41,7 +41,7 @@ static bool shouldAddObject(const char * name, int maxLength) {
|
||||
return false;
|
||||
}
|
||||
assert(name != nullptr);
|
||||
if (Ion::UTF8Helper::CodePointIs(name, '_')) {
|
||||
if (UTF8Helper::CodePointIs(name, '_')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -298,7 +298,7 @@ void CalculationController::updateTitle() {
|
||||
if (currentChar >= k_titleBufferSize) {
|
||||
break;
|
||||
}
|
||||
currentChar += Ion::UTF8Decoder::CodePointToChars(' ', m_titleBuffer + currentChar, k_titleBufferSize - currentChar);
|
||||
currentChar += UTF8Decoder::CodePointToChars(' ', m_titleBuffer + currentChar, k_titleBufferSize - currentChar);
|
||||
}
|
||||
m_titleBuffer[minInt(currentChar, k_titleBufferSize) - 1] = 0;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ void GraphController::reloadBannerView() {
|
||||
}
|
||||
numberOfChar += strlcpy(buffer, legend, bufferSize);
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(x, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
for (int i = numberOfChar; i < k_maxLegendLength; i++) {
|
||||
buffer[numberOfChar++] = ' ';
|
||||
}
|
||||
|
||||
@@ -67,15 +67,15 @@ CartesianFunction CartesianFunction::NewModel(Ion::Storage::Record::ErrorStatus
|
||||
|
||||
int CartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, CodePoint arg) {
|
||||
// Fill buffer with f(x). Keep size for derivative sign.
|
||||
int derivativeSize = Ion::UTF8Decoder::CharSizeOfCodePoint('\'');
|
||||
int derivativeSize = UTF8Decoder::CharSizeOfCodePoint('\'');
|
||||
int numberOfChars = nameWithArgument(buffer, bufferSize - derivativeSize, arg);
|
||||
assert(numberOfChars + derivativeSize < bufferSize);
|
||||
char * firstParenthesis = const_cast<char *>(Ion::UTF8Helper::CodePointSearch(buffer, '('));
|
||||
if (!Ion::UTF8Helper::CodePointIs(firstParenthesis, '(')) {
|
||||
char * firstParenthesis = const_cast<char *>(UTF8Helper::CodePointSearch(buffer, '('));
|
||||
if (!UTF8Helper::CodePointIs(firstParenthesis, '(')) {
|
||||
return numberOfChars;
|
||||
}
|
||||
memmove(firstParenthesis + derivativeSize, firstParenthesis, buffer + numberOfChars - firstParenthesis);
|
||||
Ion::UTF8Decoder::CodePointToChars('\'', firstParenthesis, derivativeSize);
|
||||
UTF8Decoder::CodePointToChars('\'', firstParenthesis, derivativeSize);
|
||||
return numberOfChars + derivativeSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ constexpr char Function::k_parenthesedArgument[];
|
||||
bool Function::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) {
|
||||
assert(baseName[0] != 0);
|
||||
|
||||
Ion::UTF8Decoder decoder(baseName);
|
||||
UTF8Decoder decoder(baseName);
|
||||
CodePoint c = decoder.nextCodePoint();
|
||||
if (Ion::UTF8Helper::CodePointIsNumber(c)) {
|
||||
if (UTF8Helper::CodePointIsNumber(c)) {
|
||||
// The name cannot start with a number
|
||||
if (error != nullptr) {
|
||||
*error = NameNotCompliantError::NameCannotStartWithNumber;
|
||||
@@ -29,9 +29,9 @@ bool Function::BaseNameCompliant(const char * baseName, NameNotCompliantError *
|
||||
|
||||
// The name should only have allowed characters
|
||||
while (c != UCodePointNull) {
|
||||
if (!(Ion::UTF8Helper::CodePointIsUpperCaseLetter(c)
|
||||
|| Ion::UTF8Helper::CodePointIsLowerCaseLetter(c)
|
||||
|| Ion::UTF8Helper::CodePointIsNumber(c))
|
||||
if (!(UTF8Helper::CodePointIsUpperCaseLetter(c)
|
||||
|| UTF8Helper::CodePointIsLowerCaseLetter(c)
|
||||
|| UTF8Helper::CodePointIsNumber(c))
|
||||
|| c == '_')
|
||||
{
|
||||
if (error != nullptr) {
|
||||
@@ -65,13 +65,13 @@ void Function::setActive(bool active) {
|
||||
}
|
||||
|
||||
int Function::nameWithArgument(char * buffer, size_t bufferSize, CodePoint arg) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(arg) == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(arg) == 1);
|
||||
const char * functionName = fullName();
|
||||
size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength);
|
||||
int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength);
|
||||
int bufferRemainingSize = bufferSize - (baseNameLength+1);
|
||||
if (bufferRemainingSize > 0) {
|
||||
Ion::UTF8Decoder::CodePointToChars(arg, buffer+baseNameLength+1, bufferRemainingSize);
|
||||
UTF8Decoder::CodePointToChars(arg, buffer+baseNameLength+1, bufferRemainingSize);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ bool TextFieldDelegateApp::fieldDidReceiveEvent(EditableField * field, Responder
|
||||
/* TODO decode here to encode again in handleEventWithText? */
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength+1;
|
||||
char buffer[bufferSize];
|
||||
size_t length = Ion::UTF8Decoder::CodePointToChars(field->XNTCodePoint(XNT()), buffer, bufferSize);
|
||||
size_t length = UTF8Decoder::CodePointToChars(field->XNTCodePoint(XNT()), buffer, bufferSize);
|
||||
assert(length < bufferSize - 1);
|
||||
buffer[length] = 0;
|
||||
return field->handleEventWithText(buffer);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Shared {
|
||||
namespace ToolboxHelpers {
|
||||
|
||||
int CursorIndexInCommandText(const char * text) {
|
||||
Ion::UTF8Decoder decoder(text);
|
||||
UTF8Decoder decoder(text);
|
||||
size_t index = 0;
|
||||
const char * currentPointer = text;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
@@ -39,7 +39,7 @@ void TextToInsertForCommandText(const char * command, char * buffer, int bufferS
|
||||
bool insideQuote = false;
|
||||
bool argumentAlreadyReplaced = false;
|
||||
|
||||
Ion::UTF8Decoder decoder(command);
|
||||
UTF8Decoder decoder(command);
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != UCodePointNull) {
|
||||
if (codePoint == ')') {
|
||||
@@ -59,10 +59,10 @@ void TextToInsertForCommandText(const char * command, char * buffer, int bufferS
|
||||
if (argumentAlreadyReplaced) {
|
||||
argumentAlreadyReplaced = false;
|
||||
}
|
||||
index += Ion::UTF8Decoder::CodePointToChars(codePoint, buffer + index, bufferSize - index);
|
||||
index += UTF8Decoder::CodePointToChars(codePoint, buffer + index, bufferSize - index);
|
||||
} else {
|
||||
if (replaceArgsWithEmptyChar && !argumentAlreadyReplaced) {
|
||||
index += Ion::UTF8Decoder::CodePointToChars(UCodePointEmpty, buffer + index, bufferSize - index);
|
||||
index += UTF8Decoder::CodePointToChars(UCodePointEmpty, buffer + index, bufferSize - index);
|
||||
argumentAlreadyReplaced = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ void ListController::didEnterResponderChain(Responder * previousFirstResponder)
|
||||
|
||||
bool textRepresentsAnEquality(const char * text) {
|
||||
char equal = '=';
|
||||
return Ion::UTF8Helper::CodePointIs(Ion::UTF8Helper::CodePointSearch(text, equal), equal);
|
||||
return UTF8Helper::CodePointIs(UTF8Helper::CodePointSearch(text, equal), equal);
|
||||
}
|
||||
|
||||
bool layoutRepresentsAnEquality(Poincare::Layout l) {
|
||||
|
||||
@@ -51,7 +51,7 @@ void BoxController::reloadBannerView() {
|
||||
m_view.editableBannerView()->setMessageAtIndex(calculationName[selectedQuantile], 1);
|
||||
|
||||
// Set calculation result
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
constexpr int bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits) + 1;
|
||||
char buffer[bufferSize];
|
||||
CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
|
||||
|
||||
@@ -110,18 +110,18 @@ void HistogramController::reloadBannerView() {
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(lowerBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
}
|
||||
|
||||
numberOfChar+= Ion::UTF8Decoder::CodePointToChars(';', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar+= UTF8Decoder::CodePointToChars(';', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
|
||||
// Add upper bound
|
||||
if (selectedSeriesIndex() >= 0) {
|
||||
double upperBound = m_store->endOfBarAtIndex(selectedSeriesIndex(), *m_selectedBarIndex);
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(upperBound, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
}
|
||||
numberOfChar+= Ion::UTF8Decoder::CodePointToChars('[', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar+= UTF8Decoder::CodePointToChars('[', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
|
||||
// Padding
|
||||
for (int i = numberOfChar; i < k_maxIntervalLegendLength; i++) {
|
||||
numberOfChar+= Ion::UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar+= UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
}
|
||||
buffer[k_maxIntervalLegendLength] = 0;
|
||||
m_view.editableBannerView()->setLegendAtIndex(buffer, 1);
|
||||
@@ -139,7 +139,7 @@ void HistogramController::reloadBannerView() {
|
||||
}
|
||||
// Padding
|
||||
for (int i = numberOfChar; i < k_maxLegendLength; i++) {
|
||||
numberOfChar+= Ion::UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar+= UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
}
|
||||
buffer[k_maxLegendLength] = 0;
|
||||
m_view.editableBannerView()->setLegendAtIndex(buffer, 3);
|
||||
@@ -156,7 +156,7 @@ void HistogramController::reloadBannerView() {
|
||||
}
|
||||
// Padding
|
||||
for (int i = numberOfChar; i < k_maxLegendLength; i++) {
|
||||
numberOfChar+= Ion::UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar+= UTF8Decoder::CodePointToChars(' ', buffer + numberOfChar, bufferSize - numberOfChar);
|
||||
}
|
||||
buffer[k_maxLegendLength] = 0;
|
||||
m_view.editableBannerView()->setLegendAtIndex(buffer, 5);
|
||||
|
||||
@@ -200,11 +200,11 @@ bool VariableBoxController::selectLeaf(int selectedRow) {
|
||||
if (m_currentPage == Page::Function) {
|
||||
// Add parentheses to a function name
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameLength += Ion::UTF8Decoder::CodePointToChars('(', nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
nameLength += UTF8Decoder::CodePointToChars('(', nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameLength+= Ion::UTF8Decoder::CodePointToChars(UCodePointEmpty, nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
nameLength+= UTF8Decoder::CodePointToChars(UCodePointEmpty, nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameLength += Ion::UTF8Decoder::CodePointToChars(')', nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
nameLength += UTF8Decoder::CodePointToChars(')', nameToHandle+nameLength, nameToHandleMaxSize - nameLength);
|
||||
assert(nameLength < nameToHandleMaxSize);
|
||||
nameToHandle[nameLength] = 0;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ static inline void InsertSpacesAtLocation(int spacesCount, char * buffer, int bu
|
||||
assert(strlen(buffer) + spacesCount < bufferSize);
|
||||
|
||||
size_t sizeToMove = strlen(buffer) + 1;
|
||||
size_t spaceCharSize = Ion::UTF8Decoder::CharSizeOfCodePoint(' ');
|
||||
size_t spaceCharSize = UTF8Decoder::CharSizeOfCodePoint(' ');
|
||||
size_t spacesLength = spacesCount * spaceCharSize;
|
||||
memmove(buffer + spacesLength, buffer, sizeToMove);
|
||||
for (int i = 0; i < spacesCount; i++) {
|
||||
int spaceOffset = i * spaceCharSize;
|
||||
Ion::UTF8Decoder::CodePointToChars(' ', buffer + spaceOffset, bufferSize - spaceOffset);
|
||||
UTF8Decoder::CodePointToChars(' ', buffer + spaceOffset, bufferSize - spaceOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,20 +44,20 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
|
||||
// Compute the indentation
|
||||
int spacesCount = indentationBeforeCursor();
|
||||
const char * teaxtAreaBuffer = contentView()->text();
|
||||
if (cursorLocation() > teaxtAreaBuffer && Ion::UTF8Helper::PreviousCodePointIs(teaxtAreaBuffer, cursorLocation(), ':')) {
|
||||
if (cursorLocation() > teaxtAreaBuffer && UTF8Helper::PreviousCodePointIs(teaxtAreaBuffer, cursorLocation(), ':')) {
|
||||
spacesCount += k_indentationSpaces;
|
||||
}
|
||||
|
||||
// Check the text will not overflow the buffer
|
||||
int totalIndentationSize = Ion::UTF8Helper::CountOccurrences(text, '\n') * spacesCount;
|
||||
int totalIndentationSize = UTF8Helper::CountOccurrences(text, '\n') * spacesCount;
|
||||
if (contentView()->getText()->textLength() + textLength + totalIndentationSize >= contentView()->getText()->bufferSize() || textLength == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ion::UTF8Helper::PerformAtCodePoints(
|
||||
UTF8Helper::PerformAtCodePoints(
|
||||
buffer, '\n',
|
||||
[](int codePointOffset, void * text, int indentation) {
|
||||
int offset = codePointOffset + Ion::UTF8Decoder::CharSizeOfCodePoint('\n');
|
||||
int offset = codePointOffset + UTF8Decoder::CharSizeOfCodePoint('\n');
|
||||
InsertSpacesAtLocation(indentation, (char *)text + offset, TextField::maxBufferSize() - offset); //TODO
|
||||
},
|
||||
[](int c1, void * c2, int c3) {},
|
||||
@@ -67,7 +67,7 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
|
||||
const char * cursorPositionInCommand = TextInputHelpers::CursorPositionInCommand(buffer);
|
||||
|
||||
// Remove the Empty code points
|
||||
Ion::UTF8Helper::RemoveCodePoint(buffer, UCodePointEmpty, &cursorPositionInCommand);
|
||||
UTF8Helper::RemoveCodePoint(buffer, UCodePointEmpty, &cursorPositionInCommand);
|
||||
|
||||
// Insert the text
|
||||
if (insertTextAtLocation(buffer, cursorLocation())) {
|
||||
@@ -88,14 +88,14 @@ bool TextArea::handleEvent(Ion::Events::Event event) {
|
||||
assert(cursorLocation() == text());
|
||||
return false;
|
||||
}
|
||||
Ion::UTF8Decoder decoder(text(), cursorLocation());
|
||||
UTF8Decoder decoder(text(), cursorLocation());
|
||||
decoder.previousCodePoint();
|
||||
return setCursorLocation(decoder.stringPosition());
|
||||
} else if (event == Ion::Events::Right) {
|
||||
if (Ion::UTF8Helper::CodePointIs(cursorLocation(), UCodePointNull)) {
|
||||
if (UTF8Helper::CodePointIs(cursorLocation(), UCodePointNull)) {
|
||||
return false;
|
||||
}
|
||||
Ion::UTF8Decoder decoder(cursorLocation());
|
||||
UTF8Decoder decoder(cursorLocation());
|
||||
decoder.nextCodePoint();
|
||||
return setCursorLocation(decoder.stringPosition());
|
||||
} else if (event == Ion::Events::Up) {
|
||||
@@ -135,7 +135,7 @@ int TextArea::indentationBeforeCursor() const {
|
||||
/* Compute the number of spaces at the beginning of the line. Increase the
|
||||
* indentation size when encountering spaces, reset it to 0 when encountering
|
||||
* another code point, until reaching the beginning of the line. */
|
||||
Ion::UTF8Helper::PerformAtCodePoints(const_cast<TextArea *>(this)->contentView()->text(), ' ',
|
||||
UTF8Helper::PerformAtCodePoints(const_cast<TextArea *>(this)->contentView()->text(), ' ',
|
||||
[](int codePointOffset, void * indentationSize, int context){
|
||||
int * castedSize = (int *) indentationSize;
|
||||
*castedSize = *castedSize + 1;
|
||||
@@ -157,7 +157,7 @@ const char * TextArea::Text::pointerAtPosition(Position p) {
|
||||
int y = 0;
|
||||
for (Line l : *this) {
|
||||
if (p.line() == y) {
|
||||
const char * result = Ion::UTF8Helper::CodePointAtGlyphOffset(l.text(), p.column());
|
||||
const char * result = UTF8Helper::CodePointAtGlyphOffset(l.text(), p.column());
|
||||
return minPointer(result, l.text() + l.charLength());
|
||||
}
|
||||
y++;
|
||||
@@ -171,7 +171,7 @@ TextArea::Text::Position TextArea::Text::positionAtPointer(const char * p) const
|
||||
size_t y = 0;
|
||||
for (Line l : *this) {
|
||||
if (l.contains(p)) {
|
||||
size_t x = Ion::UTF8Helper::GlyphOffsetAtCodePoint(l.text(), p);
|
||||
size_t x = UTF8Helper::GlyphOffsetAtCodePoint(l.text(), p);
|
||||
return Position(x, y);
|
||||
}
|
||||
y++;
|
||||
@@ -197,12 +197,12 @@ void TextArea::Text::insertSpacesAtLocation(int numberOfSpaces, char * location)
|
||||
assert(strlen(m_buffer) + numberOfSpaces < m_bufferSize);
|
||||
|
||||
size_t sizeToMove = strlen(location) + 1;
|
||||
size_t spaceCharSize = Ion::UTF8Decoder::CharSizeOfCodePoint(' ');
|
||||
size_t spaceCharSize = UTF8Decoder::CharSizeOfCodePoint(' ');
|
||||
size_t spacesSize = numberOfSpaces * spaceCharSize;
|
||||
assert(location + spacesSize + sizeToMove <= m_buffer + m_bufferSize);
|
||||
memmove(location + spacesSize, location, sizeToMove);
|
||||
for (int i = 0; i < numberOfSpaces; i++) {
|
||||
Ion::UTF8Decoder::CodePointToChars(' ', location+i*spaceCharSize, (m_buffer + m_bufferSize) - location);
|
||||
UTF8Decoder::CodePointToChars(' ', location+i*spaceCharSize, (m_buffer + m_bufferSize) - location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ CodePoint TextArea::Text::removeCodePoint(char * * position) {
|
||||
assert(m_buffer <= *position && *position < m_buffer + m_bufferSize);
|
||||
|
||||
CodePoint removedCodePoint = 0;
|
||||
int removedSize = Ion::UTF8Helper::RemovePreviousCodePoint(m_buffer, *position, &removedCodePoint);
|
||||
int removedSize = UTF8Helper::RemovePreviousCodePoint(m_buffer, *position, &removedCodePoint);
|
||||
assert(removedSize > 0);
|
||||
|
||||
// Set the new cursor position
|
||||
@@ -225,7 +225,7 @@ size_t TextArea::Text::removeRemainingLine(const char * location, int direction)
|
||||
assert(direction > 0 || location > m_buffer);
|
||||
assert(direction < 0 || location < m_buffer + m_bufferSize);
|
||||
|
||||
Ion::UTF8Decoder decoder(m_buffer, location);
|
||||
UTF8Decoder decoder(m_buffer, location);
|
||||
const char * codePointPosition = decoder.stringPosition();
|
||||
CodePoint nextCodePoint = direction > 0 ? decoder.nextCodePoint() : decoder.previousCodePoint();
|
||||
if (direction < 0) {
|
||||
@@ -271,7 +271,7 @@ TextArea::Text::Line::Line(const char * text) :
|
||||
m_charLength(0)
|
||||
{
|
||||
if (m_text != nullptr) {
|
||||
m_charLength = Ion::UTF8Helper::CodePointSearch(text, '\n') - m_text;
|
||||
m_charLength = UTF8Helper::CodePointSearch(text, '\n') - m_text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,17 +283,17 @@ bool TextArea::Text::Line::contains(const char * c) const {
|
||||
return (c >= m_text)
|
||||
&& ((c < m_text + m_charLength)
|
||||
|| (c == m_text + m_charLength
|
||||
&& (Ion::UTF8Helper::CodePointIs(c, 0)
|
||||
|| Ion::UTF8Helper::CodePointIs(c, '\n')))) ;
|
||||
&& (UTF8Helper::CodePointIs(c, 0)
|
||||
|| UTF8Helper::CodePointIs(c, '\n')))) ;
|
||||
}
|
||||
|
||||
/* TextArea::Text::LineIterator */
|
||||
|
||||
TextArea::Text::LineIterator & TextArea::Text::LineIterator::operator++() {
|
||||
const char * last = m_line.text() + m_line.charLength();
|
||||
assert(Ion::UTF8Helper::CodePointIs(last, 0) || Ion::UTF8Helper::CodePointIs(last, '\n'));
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('\n') == 1);
|
||||
m_line = Line(Ion::UTF8Helper::CodePointIs(last, 0) ? nullptr : last + 1);
|
||||
assert(UTF8Helper::CodePointIs(last, 0) || UTF8Helper::CodePointIs(last, '\n'));
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('\n') == 1);
|
||||
m_line = Line(UTF8Helper::CodePointIs(last, 0) ? nullptr : last + 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ bool TextArea::TextArea::ContentView::insertTextAtLocation(const char * text, co
|
||||
bool lineBreak = false;
|
||||
|
||||
// Scan for \n and 0
|
||||
const char * nullLocation = Ion::UTF8Helper::PerformAtCodePoints(
|
||||
const char * nullLocation = UTF8Helper::PerformAtCodePoints(
|
||||
text, '\n',
|
||||
[](int codePointOffset, void * lineBreak, int indentation) {
|
||||
*((bool *)lineBreak) = true;
|
||||
@@ -386,7 +386,7 @@ bool TextArea::TextArea::ContentView::insertTextAtLocation(const char * text, co
|
||||
[](int c1, void * c2, int c3) { },
|
||||
&lineBreak, 0);
|
||||
|
||||
assert(Ion::UTF8Helper::CodePointIs(nullLocation, 0));
|
||||
assert(UTF8Helper::CodePointIs(nullLocation, 0));
|
||||
m_text.insertText(text, nullLocation - text, const_cast<char *>(location));
|
||||
reloadRectFromPosition(location, lineBreak);
|
||||
return true;
|
||||
|
||||
@@ -115,14 +115,14 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, const char
|
||||
*overridenByteLocation = overridenByte;
|
||||
m_currentDraftTextLength += textSize;
|
||||
|
||||
Ion::UTF8Decoder decoder(m_draftTextBuffer);
|
||||
UTF8Decoder decoder(m_draftTextBuffer);
|
||||
const char * codePointPointer = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
assert(!codePoint.isCombining());
|
||||
while (codePoint != UCodePointNull) {
|
||||
assert(codePointPointer < m_draftTextBuffer + m_textBufferSize);
|
||||
if (codePoint == '\n') {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('\n') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('\n') == 1);
|
||||
*(const_cast<char *>(codePointPointer)) = 0;
|
||||
m_currentDraftTextLength = codePointPointer - m_draftTextBuffer;
|
||||
break;
|
||||
@@ -154,7 +154,7 @@ bool TextField::ContentView::removeCodePoint() {
|
||||
}
|
||||
// Remove the code point if possible
|
||||
CodePoint removedCodePoint = 0;
|
||||
int removedSize = Ion::UTF8Helper::RemovePreviousCodePoint(m_draftTextBuffer, const_cast<char *>(cursorLocation()), &removedCodePoint);
|
||||
int removedSize = UTF8Helper::RemovePreviousCodePoint(m_draftTextBuffer, const_cast<char *>(cursorLocation()), &removedCodePoint);
|
||||
if (removedSize == 0) {
|
||||
assert(cursorLocation() == m_draftTextBuffer);
|
||||
return false;
|
||||
@@ -360,7 +360,7 @@ CodePoint TextField::XNTCodePoint(CodePoint defaultXNTCodePoint) {
|
||||
* reasonable if the expression is being entered left-to-right. */
|
||||
const char * text = this->text();
|
||||
const char * location = cursorLocation();
|
||||
Ion::UTF8Decoder decoder(text, text + (location - m_contentView.draftTextBuffer()));
|
||||
UTF8Decoder decoder(text, text + (location - m_contentView.draftTextBuffer()));
|
||||
unsigned level = 0;
|
||||
while (location > m_contentView.draftTextBuffer()) {
|
||||
CodePoint c = decoder.previousCodePoint();
|
||||
@@ -433,7 +433,7 @@ void TextField::scrollToCursor() {
|
||||
bool TextField::privateHandleMoveEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Left && isEditing() && cursorLocation() > m_contentView.draftTextBuffer()) {
|
||||
assert(isEditing());
|
||||
Ion::UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorLocation());
|
||||
UTF8Decoder decoder(m_contentView.draftTextBuffer(), cursorLocation());
|
||||
decoder.previousCodePoint();
|
||||
return setCursorLocation(decoder.stringPosition());
|
||||
}
|
||||
@@ -443,7 +443,7 @@ bool TextField::privateHandleMoveEvent(Ion::Events::Event event) {
|
||||
}
|
||||
if (event == Ion::Events::Right && isEditing() && cursorLocation() < m_contentView.draftTextBuffer() + draftTextLength()) {
|
||||
assert(isEditing());
|
||||
Ion::UTF8Decoder decoder(cursorLocation());
|
||||
UTF8Decoder decoder(cursorLocation());
|
||||
decoder.nextCodePoint();
|
||||
return setCursorLocation(decoder.stringPosition());
|
||||
}
|
||||
@@ -473,7 +473,7 @@ bool TextField::handleEventWithText(const char * eventText, bool indentation, bo
|
||||
// Remove the Empty code points
|
||||
constexpr int bufferSize = TextField::maxBufferSize();
|
||||
char buffer[bufferSize];
|
||||
Ion::UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, UCodePointEmpty);
|
||||
UTF8Helper::CopyAndRemoveCodePoint(buffer, bufferSize, eventText, UCodePointEmpty);
|
||||
|
||||
const char * nextCursorLocation = m_contentView.draftTextBuffer() + draftTextLength();
|
||||
if (insertTextAtLocation(buffer, cursorLocation())) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace TextInputHelpers {
|
||||
|
||||
const char * CursorPositionInCommand(const char * text) {
|
||||
Ion::UTF8Decoder decoder(text);
|
||||
UTF8Decoder decoder(text);
|
||||
const char * currentPointer = text;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != UCodePointNull) {
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
* glyphs such as accentuated letters.
|
||||
*/
|
||||
|
||||
namespace Ion {
|
||||
|
||||
class UTF8Decoder {
|
||||
public:
|
||||
UTF8Decoder(const char * string, const char * initialPosition = nullptr) :
|
||||
@@ -48,6 +46,4 @@ private:
|
||||
const char * m_stringPosition;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "code_point.h"
|
||||
#include <stddef.h>
|
||||
|
||||
namespace Ion {
|
||||
|
||||
namespace UTF8Helper {
|
||||
|
||||
// Returns the number of occurences of a code point in a string
|
||||
@@ -72,6 +70,4 @@ size_t GlyphOffsetAtCodePoint(const char * buffer, const char * position);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Ion {
|
||||
|
||||
static inline int leading_ones(uint8_t value) {
|
||||
for (int i=0; i<8; i++) {
|
||||
if (!(value & 0x80)) {
|
||||
@@ -109,5 +107,3 @@ size_t UTF8Decoder::CodePointToChars(CodePoint c, char * buffer, size_t bufferSi
|
||||
assert(i == charCount);
|
||||
return charCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Ion {
|
||||
|
||||
namespace UTF8Helper {
|
||||
|
||||
static inline int minInt(int x, int y) { return x < y ? x : y; }
|
||||
@@ -329,6 +327,4 @@ size_t GlyphOffsetAtCodePoint(const char * buffer, const char * position) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
|
||||
void assert_decodes_to(const char * string, CodePoint c) {
|
||||
Ion::UTF8Decoder d(string);
|
||||
UTF8Decoder d(string);
|
||||
quiz_assert(d.nextCodePoint() == c);
|
||||
quiz_assert(d.nextCodePoint() == 0);
|
||||
}
|
||||
|
||||
void assert_previous_code_point_is_to(const char * string, const char * stringPosition, CodePoint c) {
|
||||
Ion::UTF8Decoder d(string, stringPosition);
|
||||
UTF8Decoder d(string, stringPosition);
|
||||
quiz_assert(d.previousCodePoint() == c);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ KDPoint KDContext::drawString(const char * text, KDPoint p, const KDFont * font,
|
||||
|
||||
KDFont::GlyphBuffer glyphBuffer;
|
||||
|
||||
Ion::UTF8Decoder decoder(text);
|
||||
UTF8Decoder decoder(text);
|
||||
const char * codePointPointer = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != UCodePointNull && (maxByteLength < 0 || codePointPointer < text + maxByteLength)) {
|
||||
|
||||
@@ -12,7 +12,7 @@ KDSize KDFont::stringSizeUntil(const char * text, const char * limit) const {
|
||||
}
|
||||
KDSize stringSize = KDSize(0, m_glyphSize.height());
|
||||
|
||||
Ion::UTF8Decoder decoder(text);
|
||||
UTF8Decoder decoder(text);
|
||||
const char * currentStringPosition = decoder.stringPosition();
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
while (codePoint != UCodePointNull && (limit == nullptr || currentStringPosition < limit)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ int rankOfConstant(CodePoint c) {
|
||||
}
|
||||
|
||||
CodePoint ConstantNode::codePoint() const {
|
||||
Ion::UTF8Decoder decoder = Ion::UTF8Decoder(m_name);
|
||||
UTF8Decoder decoder = UTF8Decoder(m_name);
|
||||
CodePoint result = decoder.nextCodePoint();
|
||||
assert(decoder.nextCodePoint() == UCodePointNull);
|
||||
return result;
|
||||
@@ -86,7 +86,7 @@ Expression ConstantNode::shallowReduce(Context & context, Preferences::ComplexFo
|
||||
}
|
||||
|
||||
bool ConstantNode::isConstantCodePoint(CodePoint c) const {
|
||||
Ion::UTF8Decoder decoder(m_name);
|
||||
UTF8Decoder decoder(m_name);
|
||||
bool result = (decoder.nextCodePoint() == c);
|
||||
assert(decoder.nextCodePoint() == UCodePointNull);
|
||||
return result;
|
||||
|
||||
@@ -143,7 +143,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
|
||||
// Assert that m is not +/-inf
|
||||
assert(strcmp(tempBuffer, Infinity::Name()) != 0);
|
||||
assert(!(Ion::UTF8Helper::CodePointIs(tempBuffer, '-') && strcmp(&tempBuffer[1], Infinity::Name()) == 0));
|
||||
assert(!(UTF8Helper::CodePointIs(tempBuffer, '-') && strcmp(&tempBuffer[1], Infinity::Name()) == 0));
|
||||
|
||||
if (strcmp(tempBuffer, Undefined::Name()) == 0) {
|
||||
currentChar += strlcpy(buffer+currentChar, tempBuffer, bufferSize-currentChar);
|
||||
@@ -176,12 +176,12 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
* We should use the UTF8Helper to manipulate chars, but it is clearer to
|
||||
* manipulate chars directly, so we just put assumptions on the char size
|
||||
* of the code points we manipuate. */
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
currentChar++;
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
int decimalMarkerPosition = currentChar;
|
||||
currentChar += strlcpy(buffer+currentChar, tempBuffer, bufferSize-currentChar);
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(buffer[decimalMarkerPosition]) == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(buffer[decimalMarkerPosition]) == 1);
|
||||
buffer[decimalMarkerPosition-1] = buffer[decimalMarkerPosition];
|
||||
buffer[decimalMarkerPosition] = '.';
|
||||
}
|
||||
@@ -195,8 +195,8 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
return currentChar;
|
||||
}
|
||||
/* Case 1: Decimal mode */
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
int deltaCharMantissa = exponent < 0 ? -exponent+1 : 0;
|
||||
strlcpy(buffer+currentChar+deltaCharMantissa, tempBuffer, maxInt(0, bufferSize-deltaCharMantissa-currentChar));
|
||||
if (exponent < 0) {
|
||||
@@ -213,7 +213,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print
|
||||
buffer[i+1] = buffer[i];
|
||||
}
|
||||
if (currentChar >= bufferSize-1) { return bufferSize-1; }
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
buffer[decimalMarkerPosition+1] = '.';
|
||||
currentChar++;
|
||||
}
|
||||
@@ -237,7 +237,7 @@ template<typename T> T DecimalNode::templatedApproximate() const {
|
||||
}
|
||||
|
||||
int Decimal::Exponent(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentNegative) {
|
||||
if (exponentLength > 0 && Ion::UTF8Helper::CodePointIs(exponent, '-')) {
|
||||
if (exponentLength > 0 && UTF8Helper::CodePointIs(exponent, '-')) {
|
||||
exponent++;
|
||||
exponentNegative = true;
|
||||
exponentLength--;
|
||||
@@ -263,7 +263,7 @@ int Decimal::Exponent(const char * integralPart, int integralPartLength, const c
|
||||
if (integralPart == integralPartEnd) {
|
||||
const char * fractionalPartEnd = fractionalPart + fractionalPartLength;
|
||||
if (fractionalPart != nullptr) {
|
||||
while (Ion::UTF8Helper::CodePointIs(fractionalPart, '0') && fractionalPart < fractionalPartEnd) {
|
||||
while (UTF8Helper::CodePointIs(fractionalPart, '0') && fractionalPart < fractionalPartEnd) {
|
||||
fractionalPart++;
|
||||
exp--;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ Decimal Decimal::Builder(const char * integralPart, int integralPartLength, cons
|
||||
Integer zero(0);
|
||||
Integer base(10);
|
||||
// Get rid of useless preceeding 0s
|
||||
while (Ion::UTF8Helper::CodePointIs(integralPart, '0') && integralPartLength > 1) {
|
||||
while (UTF8Helper::CodePointIs(integralPart, '0') && integralPartLength > 1) {
|
||||
integralPart++;
|
||||
integralPartLength--;
|
||||
}
|
||||
@@ -292,9 +292,9 @@ Decimal Decimal::Builder(const char * integralPart, int integralPartLength, cons
|
||||
Integer numerator(integralPart, integralPartLength, false);
|
||||
assert(!numerator.isOverflow());
|
||||
// Special case for 0.??? : get rid of useless 0s in front of the integralPartLength
|
||||
if (fractionalPart != nullptr && integralPartLength == 1 && Ion::UTF8Helper::CodePointIs(integralPart, '0')) {
|
||||
if (fractionalPart != nullptr && integralPartLength == 1 && UTF8Helper::CodePointIs(integralPart, '0')) {
|
||||
integralPartLength = 0;
|
||||
while (Ion::UTF8Helper::CodePointIs(fractionalPart, '0')) {
|
||||
while (UTF8Helper::CodePointIs(fractionalPart, '0')) {
|
||||
fractionalPart++;
|
||||
fractionalPartLength--;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ void Expression::SetEncounteredComplex(bool encounterComplex) {
|
||||
}
|
||||
|
||||
Preferences::ComplexFormat Expression::UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && *(Ion::UTF8Helper::CodePointSearch(textInput, UCodePointMathematicalBoldSmallI)) != 0) {
|
||||
if (complexFormat == Preferences::ComplexFormat::Real && *(UTF8Helper::CodePointSearch(textInput, UCodePointMathematicalBoldSmallI)) != 0) {
|
||||
return Preferences::ComplexFormat::Cartesian;
|
||||
}
|
||||
return complexFormat;
|
||||
|
||||
@@ -213,7 +213,7 @@ void print_expression(const Expression e, int indentationLevel) {
|
||||
break;
|
||||
case ExpressionNode::Type::Symbol:
|
||||
std::cout << "Symbol(";
|
||||
Ion::UTF8Decoder decoder(static_cast<const Symbol &>(e).name());
|
||||
UTF8Decoder decoder(static_cast<const Symbol &>(e).name());
|
||||
CodePoint firstCodePoint = decoder.nextCodePoint();
|
||||
switch (firstCodePoint) {
|
||||
case UCodePointGreekSmallLetterPi:
|
||||
|
||||
@@ -139,7 +139,7 @@ Integer::Integer(double_native_int_t i) {
|
||||
Integer::Integer(const char * digits, size_t length, bool negative) :
|
||||
Integer(0)
|
||||
{
|
||||
if (digits != nullptr && Ion::UTF8Helper::CodePointIs(digits, '-')) {
|
||||
if (digits != nullptr && UTF8Helper::CodePointIs(digits, '-')) {
|
||||
negative = true;
|
||||
digits++;
|
||||
length--;
|
||||
@@ -208,8 +208,8 @@ Layout Integer::createLayout() const {
|
||||
char buffer[k_maxNumberOfDigitsBase10];
|
||||
int numberOfChars = serialize(buffer, k_maxNumberOfDigitsBase10);
|
||||
assert(numberOfChars >= 1);
|
||||
if ((int)Ion::UTF8Decoder::CharSizeOfCodePoint(buffer[0]) == numberOfChars) {
|
||||
Ion::UTF8Decoder decoder = Ion::UTF8Decoder(buffer);
|
||||
if ((int)UTF8Decoder::CharSizeOfCodePoint(buffer[0]) == numberOfChars) {
|
||||
UTF8Decoder decoder = UTF8Decoder(buffer);
|
||||
return CodePointLayout::Builder(decoder.nextCodePoint());
|
||||
}
|
||||
return LayoutHelper::String(buffer, numberOfChars);
|
||||
|
||||
@@ -141,7 +141,7 @@ void LayoutCursor::addXNTCodePointLayout() {
|
||||
void LayoutCursor::insertText(const char * text) {
|
||||
Layout newChild;
|
||||
Layout pointedChild;
|
||||
Ion::UTF8Decoder decoder(text);
|
||||
UTF8Decoder decoder(text);
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
if (codePoint == UCodePointNull) {
|
||||
return;
|
||||
|
||||
@@ -57,7 +57,7 @@ Layout LayoutHelper::Parentheses(Layout layout, bool cloneLayout) {
|
||||
HorizontalLayout LayoutHelper::String(const char * buffer, int bufferLen, const KDFont * font) {
|
||||
assert(bufferLen > 0);
|
||||
HorizontalLayout resultLayout = HorizontalLayout::Builder();
|
||||
Ion::UTF8Decoder decoder(buffer);
|
||||
UTF8Decoder decoder(buffer);
|
||||
const char * currentPointer = buffer;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
|
||||
@@ -14,7 +14,7 @@ static inline bool isDigit(const CodePoint c) {
|
||||
}
|
||||
|
||||
const CodePoint Tokenizer::nextCodePoint(PopTest popTest, CodePoint context, bool * testResult) {
|
||||
Ion::UTF8Decoder decoder(m_text);
|
||||
UTF8Decoder decoder(m_text);
|
||||
CodePoint c = decoder.nextCodePoint();
|
||||
const char * nextTextPosition = decoder.stringPosition();
|
||||
bool shouldPop = popTest(c, context);
|
||||
@@ -68,7 +68,7 @@ Token Tokenizer::popNumber() {
|
||||
const char * fractionalPartText = m_text;
|
||||
size_t fractionalPartLength = 0;
|
||||
|
||||
assert(integralPartLength > 0 || Ion::UTF8Helper::CodePointIs(m_text, '.'));
|
||||
assert(integralPartLength > 0 || UTF8Helper::CodePointIs(m_text, '.'));
|
||||
if (canPopCodePoint('.')) {
|
||||
fractionalPartText = m_text;
|
||||
fractionalPartLength = popDigits();
|
||||
@@ -177,7 +177,7 @@ Token Tokenizer::popToken() {
|
||||
Token result(Token::Identifier);
|
||||
// TODO compute size manually?
|
||||
constexpr int squareRootCharLength = 3;
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(UCodePointSquareRoot) == squareRootCharLength);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointSquareRoot) == squareRootCharLength);
|
||||
result.setString(start, squareRootCharLength);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -26,26 +26,26 @@ void PrintFloat::printBase10IntegerWithDecimalMarker(char * buffer, int bufferLe
|
||||
constexpr int tempBufferSize = PrintFloat::k_maxFloatBufferLength;
|
||||
char tempBuffer[tempBufferSize];
|
||||
int intLength = i.serialize(tempBuffer, tempBufferSize);
|
||||
int firstDigitChar = Ion::UTF8Helper::CodePointIs(tempBuffer, '-') ? 1 : 0;
|
||||
/* We should use the Ion::UTF8Decoder to write code points in buffers, but it is
|
||||
int firstDigitChar = UTF8Helper::CodePointIs(tempBuffer, '-') ? 1 : 0;
|
||||
/* We should use the UTF8Decoder to write code points in buffers, but it is
|
||||
* much clearer to manipulate chars directly as we know that the code point we
|
||||
* use ('.', '0, '1', '2', ...) are only one char long. */
|
||||
for (int k = bufferLength-1; k >= firstDigitChar; k--) {
|
||||
if (k == decimalMarkerPosition) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
buffer[k] = '.';
|
||||
continue;
|
||||
}
|
||||
if (intLength > firstDigitChar) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(tempBuffer[intLength-1]) == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(tempBuffer[intLength-1]) == 1);
|
||||
buffer[k] = tempBuffer[--intLength];
|
||||
continue;
|
||||
}
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
buffer[k] = '0';
|
||||
}
|
||||
if (firstDigitChar == 1) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint(tempBuffer[0]) == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(tempBuffer[0]) == 1);
|
||||
buffer[0] = tempBuffer[0];
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
|
||||
int numberOfZerosRemoved = 0;
|
||||
while (digit.isZero() && numberOfCharsForMantissaWithoutSign > minimumNumberOfCharsInMantissa &&
|
||||
(numberOfCharsForMantissaWithoutSign > exponentInBase10+1 || mode == Preferences::PrintFloatMode::Scientific)) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('0') == 1);
|
||||
numberOfCharsForMantissaWithoutSign--;
|
||||
dividend = quotient;
|
||||
quotient = Integer::Division(dividend, Integer(10)).quotient;
|
||||
@@ -174,14 +174,14 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
|
||||
// Force a decimal marker if there is fractional part
|
||||
bool decimalMarker = (mode == Preferences::PrintFloatMode::Scientific && numberOfCharsForMantissaWithoutSign > 1) || (mode == Preferences::PrintFloatMode::Decimal && numberOfCharsForMantissaWithoutSign > exponentInBase10 +1);
|
||||
if (decimalMarker) {
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1);
|
||||
numberOfCharsForMantissaWithoutSign++;
|
||||
}
|
||||
|
||||
/* Find the position of the decimal marker position */
|
||||
int decimalMarkerPosition = exponentInBase10 < 0 || mode == Preferences::PrintFloatMode::Scientific ? 1 : exponentInBase10+1;
|
||||
decimalMarkerPosition = f < 0 ? decimalMarkerPosition+1 : decimalMarkerPosition;
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
|
||||
/* Part III: Exponent */
|
||||
|
||||
@@ -189,12 +189,12 @@ int PrintFloat::convertFloatToTextPrivate(T f, char * buffer, int bufferSize, in
|
||||
if (exponentInBase10 < 0){
|
||||
// If the exponent is < 0, we need a additional char for the sign
|
||||
numberOfCharExponent++;
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
}
|
||||
|
||||
/* Part III: print mantissa*10^exponent */
|
||||
int numberOfCharsForMantissaWithSign = f >= 0 ? numberOfCharsForMantissaWithoutSign : numberOfCharsForMantissaWithoutSign + 1;
|
||||
assert(Ion::UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint('-') == 1);
|
||||
// Print mantissa
|
||||
assert(!dividend.isOverflow());
|
||||
if (numberOfCharsForMantissaWithSign >= bufferSize) {
|
||||
|
||||
@@ -39,7 +39,7 @@ static int serializeChild(
|
||||
// Write the child with parentheses if needed
|
||||
bool addParentheses = parentNode->childNeedsParenthesis(childNode);
|
||||
if (addParentheses) {
|
||||
numberOfChar += Ion::UTF8Decoder::CodePointToChars('(', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar += UTF8Decoder::CodePointToChars('(', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
return bufferSize-1;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ static int serializeChild(
|
||||
return bufferSize-1;
|
||||
}
|
||||
if (addParentheses) {
|
||||
numberOfChar += Ion::UTF8Decoder::CodePointToChars(')', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar += UTF8Decoder::CodePointToChars(')', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
}
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
assert(buffer[bufferSize - 1] == 0);
|
||||
@@ -134,7 +134,7 @@ int SerializationHelper::Prefix(
|
||||
}
|
||||
|
||||
// Add the opening parenthese
|
||||
numberOfChar += Ion::UTF8Decoder::CodePointToChars('(', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar += UTF8Decoder::CodePointToChars('(', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
return bufferSize-1;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ int SerializationHelper::Prefix(
|
||||
|
||||
// Write the remaining children, separated with commas
|
||||
for (int i = firstChildIndex + 1; i < childrenCount; i++) {
|
||||
numberOfChar += Ion::UTF8Decoder::CodePointToChars(',', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar += UTF8Decoder::CodePointToChars(',', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
return bufferSize-1;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ int SerializationHelper::Prefix(
|
||||
}
|
||||
|
||||
// Add the closing parenthese
|
||||
numberOfChar += Ion::UTF8Decoder::CodePointToChars(')', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
numberOfChar += UTF8Decoder::CodePointToChars(')', buffer+numberOfChar, bufferSize - numberOfChar);
|
||||
if (numberOfChar >= bufferSize-1) {
|
||||
return bufferSize-1;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ int SerializationHelper::CodePoint(char * buffer, int bufferSize, class CodePoin
|
||||
return result;
|
||||
}
|
||||
}
|
||||
size_t size = Ion::UTF8Decoder::CodePointToChars(c, buffer, bufferSize);
|
||||
size_t size = UTF8Decoder::CodePointToChars(c, buffer, bufferSize);
|
||||
if (size <= bufferSize - 1) {
|
||||
buffer[size] = 0;
|
||||
} else {
|
||||
|
||||
@@ -151,7 +151,7 @@ Expression Symbol::UntypedBuilder(const char * name, size_t length, Context * co
|
||||
}
|
||||
|
||||
bool SymbolNode::isUnknown(CodePoint unknownSymbol) const {
|
||||
bool result = Ion::UTF8Helper::CodePointIs(m_name, unknownSymbol);
|
||||
bool result = UTF8Helper::CodePointIs(m_name, unknownSymbol);
|
||||
if (result) {
|
||||
assert(m_name[1] == 0);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ bool SymbolNode::isUnknown(CodePoint unknownSymbol) const {
|
||||
Symbol Symbol::Builder(CodePoint name) {
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char buffer[bufferSize];
|
||||
int codePointSize = Ion::UTF8Decoder::CodePointToChars(name, buffer, bufferSize);
|
||||
int codePointSize = UTF8Decoder::CodePointToChars(name, buffer, bufferSize);
|
||||
assert(codePointSize <= bufferSize);
|
||||
return Symbol::Builder(buffer, codePointSize);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ T SymbolAbstract::Builder(const char * name, int length) {
|
||||
}
|
||||
|
||||
size_t SymbolAbstract::TruncateExtension(char * dst, const char * src, size_t len) {
|
||||
return Ion::UTF8Helper::CopyUntilCodePoint(dst, len, src, '.');
|
||||
return UTF8Helper::CopyUntilCodePoint(dst, len, src, '.');
|
||||
}
|
||||
|
||||
bool SymbolAbstract::matches(const SymbolAbstract & symbol, ExpressionTest test, Context & context) {
|
||||
|
||||
Reference in New Issue
Block a user