From b90c8a7fefe82750f6515a67b6e367c2fbbcaeca Mon Sep 17 00:00:00 2001 From: Syed Daanish Date: Wed, 29 Jul 2026 07:03:21 +0100 Subject: [PATCH] Cleanup --- include/ed/ed.h | 0 include/pch.h | 2 -- include/vase/search.h | 6 +++++- include/vase/vase.h | 14 +++++++++++++- src/main.cc | 23 +++++++++++------------ src/vase/search.cc | 37 ++++++++++++++++++++++++++++++++++++- src/vase/vase.cc | 34 ++++++---------------------------- 7 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 include/ed/ed.h diff --git a/include/ed/ed.h b/include/ed/ed.h new file mode 100644 index 0000000..e69de29 diff --git a/include/pch.h b/include/pch.h index cc8bc55..6d3f2b1 100644 --- a/include/pch.h +++ b/include/pch.h @@ -52,5 +52,3 @@ extern "C" { #include #include #include - -using namespace std::chrono_literals; diff --git a/include/vase/search.h b/include/vase/search.h index 4db59b9..c60e35c 100644 --- a/include/vase/search.h +++ b/include/vase/search.h @@ -15,5 +15,9 @@ struct RegexMatch { std::vector groups{}; }; -const std::vector regex_search(Shard *root, std::string_view pattern_str, uint32_t start_offset, uint32_t end_offset, uint32_t flags, bool global); +const std::vector regex_search( + Shard *root, std::string_view pattern_str, + uint32_t start_offset, uint32_t end_offset, + std::string_view options +); void print_regex(const std::vector &matches); diff --git a/include/vase/vase.h b/include/vase/vase.h index 647e421..770c4a6 100644 --- a/include/vase/vase.h +++ b/include/vase/vase.h @@ -31,5 +31,17 @@ struct Vase { void insert(uint32_t offset, const char *data, uint32_t len); void erase(uint32_t cursor, int64_t amount); - void regex_search_replace(std::string_view pattern, uint32_t start_offset, uint32_t end_offset, std::string_view replace, std::string_view options); + // Grapheme clusters or the specail cluster "\r\n' + void erase_clusters(uint32_t cursor, int64_t amount); + + // moves in clusters from line,col and sets new position to line,col returns false if not enough space to jump. + bool jump_clusters(uint32_t *line, uint32_t *col, int64_t amount); + + // need to also make helpers for line width. + + void regex_search_replace( + std::string_view pattern, + uint32_t start_offset, uint32_t end_offset, + std::string_view replace, std::string_view options + ); }; diff --git a/src/main.cc b/src/main.cc index afcf676..2cee90b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -5,7 +5,10 @@ int main() { const char *text_o = - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; uint32_t len = strlen(text_o); char *text = strdup(text_o); @@ -25,30 +28,26 @@ int main() { vase.erase(offset_of(vase.root, 7, 3), -3); - std::vector matches = regex_search(vase.root, "a(.)c", 0, vase.length(), PCRE2_MULTILINE, false); - print_regex(matches); - std::cout << "\n\n"; + // supports gisxUn and m as inverse (as multiline is default.) + std::vector matches = regex_search(vase.root, "a(.)c", 0, vase.length(), "s"); + print_regex(matches); // debug - std::cout << "\n\n" - << vase.to_string(); - - // supports gisxUn - vase.regex_search_replace("a(.)c", 0, vase.length(), "|$1|", "g"); - - /*print_shard(vase.root); + print_shard(vase.root); // debug LineIterator it(vase.root, 0); std::string line; while (it.next(line)) std::cout << line << "\n"; + vase.regex_search_replace("a(.)c", 0, vase.length(), "|$1|", "g"); + std::cout << "\n\n"; ChunkIterator it2(vase.root); const char *data; uint32_t length; while (it2.next(&data, &length)) - std::cout << std::string(data, length) << "\n|\n";*/ + std::cout << std::string(data, length); std::cout << "\n\n" << vase.to_string(); diff --git a/src/vase/search.cc b/src/vase/search.cc index c586de9..f1f8120 100644 --- a/src/vase/search.cc +++ b/src/vase/search.cc @@ -1,7 +1,40 @@ #include "vase/search.h" #include "vase/iterators/chunk.h" -const std::vector regex_search(Shard *root, std::string_view pattern_str, uint32_t start_offset, uint32_t end_offset, uint32_t flags, bool global) { +const std::vector regex_search( + Shard *root, std::string_view pattern_str, + uint32_t start_offset, uint32_t end_offset, + std::string_view options +) { + bool global = false; + uint32_t flags = PCRE2_MULTILINE; + + for (char c : options) { + switch (c) { + case 'g': + global = true; + break; + case 'i': + flags |= PCRE2_CASELESS; + break; + case 's': + flags |= PCRE2_DOTALL; + break; + case 'x': + flags |= PCRE2_EXTENDED; + break; + case 'U': + flags |= PCRE2_UNGREEDY; + break; + case 'n': + flags |= PCRE2_NO_AUTO_CAPTURE; + break; + case 'm': + flags &= ~PCRE2_MULTILINE; + break; + } + } + std::vector results; int errornumber; @@ -242,4 +275,6 @@ void print_regex(const std::vector &matches) { std::cout << " }\n"; } + + std::cout << "\n\n"; } diff --git a/src/vase/vase.cc b/src/vase/vase.cc index 2a22b7d..d7a16d5 100644 --- a/src/vase/vase.cc +++ b/src/vase/vase.cc @@ -177,34 +177,12 @@ static void append_piece(Shard *&accum, Shard *piece) { accum = combined; } -void Vase::regex_search_replace(std::string_view pattern, uint32_t start_offset, uint32_t end_offset, std::string_view replace, std::string_view options) { - bool global = false; - uint32_t flags = 0; - - for (char c : options) { - switch (c) { - case 'g': - global = true; - break; - case 'i': - flags |= PCRE2_CASELESS; - break; - case 's': - flags |= PCRE2_DOTALL; - break; - case 'x': - flags |= PCRE2_EXTENDED; - break; - case 'U': - flags |= PCRE2_UNGREEDY; - break; - case 'n': - flags |= PCRE2_NO_AUTO_CAPTURE; - break; - } - } - - const std::vector matches = regex_search(root, pattern, start_offset, end_offset, flags | PCRE2_MULTILINE, global); +void Vase::regex_search_replace( + std::string_view pattern, + uint32_t start_offset, uint32_t end_offset, + std::string_view replace, std::string_view options +) { + const std::vector matches = regex_search(root, pattern, start_offset, end_offset, options); if (matches.empty()) return;