diff options
author | Neil <nyamatongwe@gmail.com> | 2020-05-04 08:51:17 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-05-04 08:51:17 +1000 |
commit | 2175e34a7449f59ee6f9fa2466cbe13b6a92232e (patch) | |
tree | 4f79f04036f88905bea500406c8443db1545eee9 | |
parent | 4b450a69452a14fd9af6c426b91d04165fedc94a (diff) | |
download | scintilla-mirror-2175e34a7449f59ee6f9fa2466cbe13b6a92232e.tar.gz |
Feature [feature-requests:1347]. Add methods to insert multiple partitions.
-rw-r--r-- | src/Partitioning.h | 20 | ||||
-rw-r--r-- | test/unit/testPartitioning.cxx | 26 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/Partitioning.h b/src/Partitioning.h index 11c64bc83..195daae9b 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -122,6 +122,26 @@ public: stepPartition++; } + void InsertPartitions(T partition, const T *positions, size_t length) { + if (stepPartition < partition) { + ApplyStep(partition); + } + body->InsertFromArray(partition, positions, 0, length); + stepPartition += static_cast<T>(length); + } + + void InsertPartitionsWithCast(T partition, const ptrdiff_t *positions, size_t length) { + // Used for 64-bit builds when T is 32-bits + if (stepPartition < partition) { + ApplyStep(partition); + } + T *pInsertion = body->InsertEmpty(partition, length); + for (size_t i = 0; i < length; i++) { + pInsertion[i] = static_cast<T>(positions[i]); + } + stepPartition += static_cast<T>(length); + } + void SetPartitionStartPosition(T partition, T pos) noexcept { ApplyStep(partition+1); if ((partition < 0) || (partition > body->Length())) { diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx index 5a416f799..6abb6da44 100644 --- a/test/unit/testPartitioning.cxx +++ b/test/unit/testPartitioning.cxx @@ -95,6 +95,32 @@ TEST_CASE("Partitioning") { REQUIRE(8 == part.PositionFromPartition(2)); } + SECTION("InsertMultiple") { + part.InsertText(0, 10); + const Sci::Position positions[] { 2, 5, 7 }; + part.InsertPartitions(1, positions, std::size(positions)); + REQUIRE(4 == part.Partitions()); + REQUIRE(0 == part.PositionFromPartition(0)); + REQUIRE(2 == part.PositionFromPartition(1)); + REQUIRE(5 == part.PositionFromPartition(2)); + REQUIRE(7 == part.PositionFromPartition(3)); + REQUIRE(10 == part.PositionFromPartition(4)); + } + + SECTION("InsertMultipleWithCast") { + part.InsertText(0, 9); + REQUIRE(1 == part.Partitions()); + const ptrdiff_t positionsp[]{ 2, 4, 6, 8 }; + part.InsertPartitionsWithCast(1, positionsp, std::size(positionsp)); + REQUIRE(5 == part.Partitions()); + REQUIRE(0 == part.PositionFromPartition(0)); + REQUIRE(2 == part.PositionFromPartition(1)); + REQUIRE(4 == part.PositionFromPartition(2)); + REQUIRE(6 == part.PositionFromPartition(3)); + REQUIRE(8 == part.PositionFromPartition(4)); + REQUIRE(9 == part.PositionFromPartition(5)); + } + SECTION("InsertReversed") { part.InsertText(0, 3); part.InsertPartition(1, 2); |