[apps/reader] Ajout du support de \sqrt[n]{x} dans le parser LaTeX

This commit is contained in:
Mino1289
2021-10-22 23:44:10 +02:00
parent 18e7926500
commit 17be5934e0
2 changed files with 26 additions and 4 deletions

View File

@@ -21,12 +21,12 @@ Layout TexParser::getLayout() {
return layout;
}
Layout TexParser::popBlock(char block) {
Layout TexParser::popBlock() {
while (*m_text == ' ') {
m_text ++;
}
if (*m_text == block) {
if (*m_text == '}') {
m_text ++;
return popText('}');
}
@@ -98,12 +98,32 @@ Layout TexParser::popCommand() {
return popFracCommand();
}
}
else if (strcmp(k_sqrtCommand, m_text, strlen(k_fracCommand)) == 0) {
m_text += strlen(k_fracCommand);
if (*m_text == ' ' || *m_text == '{' || *m_text == '[') {
return popSqrtCommand();
}
}
return popFracCommand();
}
Layout TexParser::popSqrtCommand() {
while (*m_text == ' ') {
m_text ++;
}
m_text++;
if (*m_text == '[') {
return NthRootLayout::Builder(popText(']'),popBlock());
}
else {
return NthRootLayout::Builder(popBlock());
}
}
Layout TexParser::popFracCommand() {
Layout firstBlock = popBlock('{');
Layout secondBlock = popBlock('{');
Layout firstBlock = popBlock();
Layout secondBlock = popBlock();
return FractionLayout::Builder(firstBlock, secondBlock);
}

View File

@@ -19,11 +19,13 @@ private:
Layout popText(char stop);
Layout popCommand();
Layout popFracCommand();
Layout popSqrtCommand();
const char * m_text;
const char * m_endOfText;
bool m_hasError;
static constexpr char const * k_fracCommand = "frac";
static constexpr char const * k_sqrtCommand = "sqrt";
};
}