~aleteoryx/muditaos

b7ecdecb300b985127c00a1eb24719d7431e7264 — Przemyslaw Brudny 3 years ago e59cd40
[MOS-152] Added "!?" into sentence detection signs

Added "!?" into sentence detection signs.
M module-gui/gui/widgets/text/core/cursors/TextBlockCursor.cpp => module-gui/gui/widgets/text/core/cursors/TextBlockCursor.cpp +16 -2
@@ 313,8 313,9 @@ namespace gui
            // Iterate through white space
            while (currentBlock()->getText(getPosition() - detectIndex).substr(0, 1) == " ") {

                // If dot with space found return true
                if (currentBlock()->getText(getPosition() - detectIndex - 1).substr(0, 2) == ". ") {
                // If sentence detect signs with space found return true
                if (checkSentenceBeginningSigns(
                        currentBlock()->getText(getPosition() - detectIndex - 1).substr(0, 2))) {
                    return true;
                }
                detectIndex++;


@@ 326,6 327,18 @@ namespace gui
        return false;
    }

    auto BlockCursor::checkSentenceBeginningSigns(const std::string &textToCompare) const -> bool
    {
        auto sentenceDetectSigns = {". ", "? ", "! "};

        for (auto sings : sentenceDetectSigns) {
            if (textToCompare == sings) {
                return true;
            }
        }
        return false;
    }

    const TextBlock &BlockCursor::operator*()
    {
        return *currentBlock();


@@ 361,4 374,5 @@ namespace gui
    {
        return document->blocks.end();
    }

} // namespace gui

M module-gui/gui/widgets/text/core/cursors/TextBlockCursor.hpp => module-gui/gui/widgets/text/core/cursors/TextBlockCursor.hpp +1 -0
@@ 41,6 41,7 @@ namespace gui
        [[nodiscard]] auto checkNpos() const -> bool;
        void resetNpos();
        [[nodiscard]] auto checkDocument() const -> bool;
        [[nodiscard]] auto checkSentenceBeginningSigns(const std::string &textToCompare) const -> bool;

      public:
        /// gets cursor pointing in position in block

M module-gui/test/test-catch-text/test-gui-TextBlockCursor.cpp => module-gui/test/test-catch-text/test-gui-TextBlockCursor.cpp +6 -2
@@ 526,14 526,18 @@ TEST_CASE("check sentence beginning")
    removeNSignsInBlock(1, cursor);
    REQUIRE(!cursor.checkSentenceBeginning());

    // Add string ending with dot and white space
    addStringToBlock("Test. ", cursor);
    // Add string ending with exclamation mark and white space
    addStringToBlock("Test! ", cursor);
    REQUIRE(cursor.checkSentenceBeginning());

    // Add extra sign
    addStringToBlock("P", cursor);
    REQUIRE(!cursor.checkSentenceBeginning());

    // Add string ending with question mark and white space
    addStringToBlock("Test? ", cursor);
    REQUIRE(cursor.checkSentenceBeginning());

    // Check number of blocks
    REQUIRE(cursor.getBlockNumber() == 0);