mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/poincare] Fix "random()" layout creation.
Change-Id: Ic8e12dfba925066fafa172b750162e820eeef82b
This commit is contained in:
@@ -19,15 +19,16 @@ int CursorIndexInCommandText(const char * text) {
|
||||
return strlen(text);
|
||||
}
|
||||
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize) {
|
||||
TextToInsertForCommandText(I18n::translate(message), buffer, bufferSize);
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize, bool replaceArgsWithEmptyChar) {
|
||||
TextToInsertForCommandText(I18n::translate(message), buffer, bufferSize, replaceArgsWithEmptyChar);
|
||||
}
|
||||
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize) {
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize, bool replaceArgsWithEmptyChar) {
|
||||
int currentNewTextIndex = 0;
|
||||
int numberOfOpenParentheses = 0;
|
||||
int numberOfOpenBrackets = 0;
|
||||
bool insideQuote = false;
|
||||
bool argumentAlreadyReplaced = false;
|
||||
size_t commandLength = strlen(command);
|
||||
for (size_t i = 0; i < commandLength; i++) {
|
||||
if (command[i] == ')') {
|
||||
@@ -41,7 +42,15 @@ void TextToInsertForCommandText(const char * command, char * buffer, int bufferS
|
||||
|| (numberOfOpenBrackets > 0 && (command[i] == ',' || command[i] == '[' || command[i] == ']')))
|
||||
&& (!insideQuote || command[i] == '\'')) {
|
||||
assert(currentNewTextIndex < bufferSize);
|
||||
if (argumentAlreadyReplaced) {
|
||||
argumentAlreadyReplaced = false;
|
||||
}
|
||||
buffer[currentNewTextIndex++] = command[i];
|
||||
} else {
|
||||
if (replaceArgsWithEmptyChar && !argumentAlreadyReplaced) {
|
||||
buffer[currentNewTextIndex++] = Ion::Charset::Empty;
|
||||
argumentAlreadyReplaced = true;
|
||||
}
|
||||
}
|
||||
if (command[i] == '(') {
|
||||
numberOfOpenParentheses++;
|
||||
@@ -61,18 +70,7 @@ void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer
|
||||
}
|
||||
|
||||
void TextToParseIntoLayoutForCommandText(const char * command, char * buffer, int bufferSize) {
|
||||
TextToInsertForCommandText(command, buffer, bufferSize);
|
||||
size_t bufferLength = strlen(buffer);
|
||||
for (size_t i = 0; i < bufferLength; i++) {
|
||||
if (buffer[i] == '(' || buffer[i] == ',' || (i < bufferLength - 1 && buffer[i] == '[' && buffer[i+1] == ']')) {
|
||||
// Shift the buffer to make room for the new char. Use memmove to avoid
|
||||
// overwritting.
|
||||
memmove(&buffer[i+2], &buffer[i+1], bufferLength - (i+1) + 1);
|
||||
bufferLength++;
|
||||
i++;
|
||||
buffer[i] = Ion::Charset::Empty;
|
||||
}
|
||||
}
|
||||
TextToInsertForCommandText(command, buffer, bufferSize, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ int CursorIndexInCommandText(const char * text);
|
||||
* - The end of the text */
|
||||
|
||||
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize);
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize);
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize, bool replaceArgsWithEmptyChar = false);
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize, bool replaceArgsWithEmptyChar = false);
|
||||
/* Removes the arguments from a command:
|
||||
* - Removes text between parentheses or brackets, except commas */
|
||||
void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer, int bufferSize);
|
||||
|
||||
@@ -37,13 +37,15 @@ ExpressionLayout * LayoutEngine::createPrefixLayout(const Expression * expressio
|
||||
result->addOrMergeChildAtIndex(createStringLayout(operatorName, strlen(operatorName)), 0, true);
|
||||
|
||||
// Create the layout of arguments separated by commas.
|
||||
HorizontalLayout * args = new HorizontalLayout();
|
||||
ExpressionLayout * args = nullptr;
|
||||
int numberOfOperands = expression->numberOfOperands();
|
||||
if (numberOfOperands > 0) {
|
||||
args->addOrMergeChildAtIndex(expression->operand(0)->createLayout(floatDisplayMode, complexFormat), 0, true);
|
||||
args = new HorizontalLayout();
|
||||
HorizontalLayout * horizontalArgs = static_cast<HorizontalLayout *>(args);
|
||||
horizontalArgs->addOrMergeChildAtIndex(expression->operand(0)->createLayout(floatDisplayMode, complexFormat), 0, true);
|
||||
for (int i = 1; i < numberOfOperands; i++) {
|
||||
args->addChildAtIndex(new CharLayout(','), args->numberOfChildren());
|
||||
args->addOrMergeChildAtIndex(expression->operand(i)->createLayout(floatDisplayMode, complexFormat), args->numberOfChildren(), true);
|
||||
horizontalArgs->addChildAtIndex(new CharLayout(','), args->numberOfChildren());
|
||||
horizontalArgs->addOrMergeChildAtIndex(expression->operand(i)->createLayout(floatDisplayMode, complexFormat), horizontalArgs->numberOfChildren(), true);
|
||||
}
|
||||
}
|
||||
// Add the parenthesed arguments.
|
||||
|
||||
Reference in New Issue
Block a user