[apps/math_toolbox] Cleaner matrix layout insertion.

Change-Id: I5c51eb353ac848334626e6ffcaf71f3b94534b2e
This commit is contained in:
Léa Saviot
2018-01-19 17:30:47 +01:00
parent 251c4d01af
commit 64efb45c24
3 changed files with 4 additions and 14 deletions

View File

@@ -37,7 +37,7 @@ const ToolboxMessageTree arithmeticChildren[4] = {
#if MATRICES_ARE_DEFINED
const ToolboxMessageTree matricesChildren[6] = {
ToolboxMessageTree(I18n::Message::MatrixCommandWithArg, I18n::Message::NewMatrix, I18n::Message::MatrixCommandWithArg),
ToolboxMessageTree(I18n::Message::MatrixCommandWithArg, I18n::Message::NewMatrix, I18n::Message::MatrixCommand),
ToolboxMessageTree(I18n::Message::InverseCommandWithArg, I18n::Message::Inverse, I18n::Message::InverseCommandWithArg),
ToolboxMessageTree(I18n::Message::DeterminantCommandWithArg, I18n::Message::Determinant, I18n::Message::DeterminantCommandWithArg),
ToolboxMessageTree(I18n::Message::TransposeCommandWithArg, I18n::Message::Transpose, I18n::Message::TransposeCommandWithArg),

View File

@@ -32,6 +32,7 @@ LcmCommandWithArg = "lcm(p,q)"
LeftIntegralFirstLegend = "P(X≤"
LeftIntegralSecondLegend = ")="
LogCommandWithArg = "log(x,a)"
MatrixCommand = "[[]]"
MatrixCommandWithArg = "[[1,2][3,4]]"
MaxCommandWithArg = "max(L)"
MinCommandWithArg = "min(L)"

View File

@@ -13,7 +13,7 @@ int CursorIndexInCommandText(const char * text) {
return i + 1;
}
if (text[i] == ']') {
return (i - 1) > 0 ? i - 1 : 0;
return i;
}
}
return strlen(text);
@@ -61,21 +61,10 @@ void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer
}
void TextToParseIntoLayoutForCommandText(const char * command, char * buffer, int bufferSize) {
if (command == I18n::translate(I18n::Message::MatrixCommandWithArg)) {
assert(bufferSize >= 6);
// Handle a new matrix command.
buffer[0] = '[';
buffer[1] = '[';
buffer[2] = Ion::Charset::Empty;
buffer[3] = ']';
buffer[4] = ']';
buffer[5] = 0;
return;
}
TextToInsertForCommandText(command, buffer, bufferSize);
size_t bufferLength = strlen(buffer);
for (size_t i = 0; i < bufferLength; i++) {
if (buffer[i] == '(' || buffer[i] == '[' || buffer[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);