From 05f4d202fa25a9b6beb23e097cc15c16c2e51f96 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 16 Jul 2021 09:40:45 +1000 Subject: Feature [feature-requests:#1381] Fix position returned when in 2nd segment. --- src/Document.cxx | 2 +- test/unit/testDocument.cxx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Document.cxx b/src/Document.cxx index b39779c54..6194f772e 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1999,7 +1999,7 @@ ptrdiff_t SplitFindChar(const SplitView &view, size_t start, size_t length, int } const char *match2 = static_cast(memchr(view.segment2 + start, ch, length - range1Length)); if (match2) { - return match2 - view.segment2 + view.length1; + return match2 - view.segment2; } return -1; } diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx index a48ab3fcb..97db6d9a2 100644 --- a/test/unit/testDocument.cxx +++ b/test/unit/testDocument.cxx @@ -119,6 +119,12 @@ struct DocPlus { assert(*length == static_cast(needle.length())); return document.FindText(document.Length(), 0, needle.c_str(), options, length); } + void MoveGap(Sci::Position gapNew) { + // Move gap to gapNew by inserting + document.InsertString(gapNew, "!", 1); + // Remove insertion + document.DeleteChars(gapNew, 1); + } }; void TimeTrace(std::string_view sv, const Catch::Timer &tikka) { @@ -161,6 +167,19 @@ TEST_CASE("Document") { REQUIRE(location == -1); } + SECTION("SearchInBothSegments") { + DocPlus doc("ab-ab", 0); // a b - a b + std::string finding = "ab"; + for (int gapPos = 0; gapPos <= 5; gapPos++) { + doc.MoveGap(gapPos); + Sci::Position lengthFinding = finding.length(); + Sci::Position location = doc.document.FindText(0, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding); + REQUIRE(location == 0); + location = doc.document.FindText(2, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding); + REQUIRE(location == 3); + } + } + SECTION("InsensitiveSearchInLatin") { DocPlus doc("abcde", 0); // a b c d e std::string finding = "B"; -- cgit v1.2.3