| 537 | } |
| 538 | |
| 539 | sptr<Atom> TeXParser::getScripts(wchar_t f) throw(ex_parse) { |
| 540 | _pos++; |
| 541 | // get the first script |
| 542 | sptr<Atom> first = getArgument(); |
| 543 | sptr<Atom> second(nullptr); |
| 544 | wchar_t s = '\0'; |
| 545 | |
| 546 | if (_pos < _len) s = _parseString[_pos]; |
| 547 | |
| 548 | /* |
| 549 | * 4 conditions |
| 550 | * |
| 551 | * \cmd_{\sub}^{\super} |
| 552 | * |
| 553 | * \cmd_{\sub} |
| 554 | * |
| 555 | * \cmd^{\super}_{\sub} |
| 556 | * |
| 557 | * \cmd^{\super} |
| 558 | */ |
| 559 | if (f == SUPER_SCRIPT && s == SUPER_SCRIPT) { |
| 560 | second = first; |
| 561 | first = nullptr; |
| 562 | } else if (f == SUB_SCRIPT && s == SUPER_SCRIPT) { |
| 563 | _pos++; |
| 564 | second = getArgument(); |
| 565 | } else if (f == SUPER_SCRIPT && s == SUB_SCRIPT) { |
| 566 | _pos++; |
| 567 | second = first; |
| 568 | first = getArgument(); |
| 569 | } else if (f == SUPER_SCRIPT && s != SUB_SCRIPT) { |
| 570 | second = first; |
| 571 | first = nullptr; |
| 572 | } |
| 573 | |
| 574 | sptr<Atom> atom; |
| 575 | RowAtom* rm = nullptr; |
| 576 | if (_formula->_root == nullptr) { |
| 577 | /* |
| 578 | * If there's no root exists, passing a null atom to ScriptsAtom as base is OK, |
| 579 | * the ScriptsAtom will handle it |
| 580 | */ |
| 581 | return sptr<Atom>(new ScriptsAtom(nullptr, first, second)); |
| 582 | } else if (rm = dynamic_cast<RowAtom*>(_formula->_root.get())) { |
| 583 | atom = rm->popLastAtom(); |
| 584 | } else { |
| 585 | atom = _formula->_root; |
| 586 | _formula->_root = nullptr; |
| 587 | } |
| 588 | |
| 589 | // Check if previous atom is CumulativeScriptsAtom |
| 590 | CumulativeScriptsAtom* ca = dynamic_cast<CumulativeScriptsAtom*>(atom.get()); |
| 591 | if (ca != nullptr) { |
| 592 | ca->addSubscript(first); |
| 593 | ca->addSuperscript(second); |
| 594 | return atom; |
| 595 | } |
| 596 |
nothing calls this directly
no test coverage detected