Cleanup
This commit is contained in:
@@ -52,5 +52,3 @@ extern "C" {
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -15,5 +15,9 @@ struct RegexMatch {
|
||||
std::vector<RegexGroup> groups{};
|
||||
};
|
||||
|
||||
const std::vector<RegexMatch> 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<RegexMatch> 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<RegexMatch> &matches);
|
||||
|
||||
+13
-1
@@ -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
|
||||
);
|
||||
};
|
||||
|
||||
+11
-12
@@ -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<RegexMatch> 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<RegexMatch> 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();
|
||||
|
||||
+36
-1
@@ -1,7 +1,40 @@
|
||||
#include "vase/search.h"
|
||||
#include "vase/iterators/chunk.h"
|
||||
|
||||
const std::vector<RegexMatch> 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<RegexMatch> 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<RegexMatch> results;
|
||||
|
||||
int errornumber;
|
||||
@@ -242,4 +275,6 @@ void print_regex(const std::vector<RegexMatch> &matches) {
|
||||
|
||||
std::cout << " }\n";
|
||||
}
|
||||
|
||||
std::cout << "\n\n";
|
||||
}
|
||||
|
||||
+6
-28
@@ -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<RegexMatch> 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<RegexMatch> matches = regex_search(root, pattern, start_offset, end_offset, options);
|
||||
if (matches.empty())
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user