Setup ed the posix line editor.
This commit is contained in:
@@ -24,8 +24,8 @@ struct Iterator {
|
||||
Shard *root;
|
||||
std::string line;
|
||||
|
||||
Iterator(Shard *root, uint64_t line_num)
|
||||
: root(root), it(root, line_num, Direction::Forward) {
|
||||
Iterator(Shard *root, uint64_t line_num, Direction dir)
|
||||
: root(root), it(root, line_num, dir) {
|
||||
Shard::retain(root);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,8 @@ struct Iterator {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string &next() {
|
||||
it.next(&line);
|
||||
return line;
|
||||
bool next() {
|
||||
return it.next(&line);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -25,7 +25,7 @@ struct Shard {
|
||||
static void retain(Shard *n);
|
||||
static void release(Shard *n);
|
||||
|
||||
static Shard *from_file(std::filesystem::path path, OriginalBuffer *b);
|
||||
static Shard *from_file(std::filesystem::path path, OriginalBuffer *b, bool posix_ending);
|
||||
static std::vector<Shard *> from_swap(std::filesystem::path path, OriginalBuffer *b);
|
||||
|
||||
static std::pair<Shard *, Shard *> split(Shard *n, uint64_t offset);
|
||||
@@ -34,6 +34,7 @@ struct Shard {
|
||||
static Shard *merge_leaves(Shard *a, Shard *b);
|
||||
static Shard *append(Shard *root, Shard *leaf);
|
||||
static Shard *build(Shard **pieces, uint64_t lo, uint64_t hi);
|
||||
static void dump(Shard *node, int depth = 0);
|
||||
};
|
||||
|
||||
struct Branch : Shard {
|
||||
@@ -62,54 +63,4 @@ struct Petal : Shard {
|
||||
source(source), pos(pos) {};
|
||||
};
|
||||
|
||||
extern inline void dump_shard(Shard *node, int depth = 0) {
|
||||
if (!node) {
|
||||
std::cout << std::string(depth * 2, ' ') << "<null>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string indent(depth * 2, ' ');
|
||||
|
||||
std::cout << indent
|
||||
<< "Shard@" << node
|
||||
<< " kind=";
|
||||
|
||||
switch (node->kind) {
|
||||
case Shard::Kind::Branch:
|
||||
std::cout << "Branch";
|
||||
break;
|
||||
case Shard::Kind::Petal:
|
||||
std::cout << "Petal";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout
|
||||
<< " height=" << unsigned(node->height)
|
||||
<< " length=" << node->length
|
||||
<< " lines=" << node->lines
|
||||
<< " refs=" << node->refs.load()
|
||||
<< "\n";
|
||||
|
||||
if (node->kind == Shard::Kind::Branch) {
|
||||
auto *branch = static_cast<Branch *>(node);
|
||||
|
||||
std::cout << indent << " left:\n";
|
||||
dump_shard(branch->left, depth + 2);
|
||||
|
||||
std::cout << indent << " right:\n";
|
||||
dump_shard(branch->right, depth + 2);
|
||||
} else {
|
||||
auto *petal = static_cast<Petal *>(node);
|
||||
|
||||
std::cout
|
||||
<< indent << " source=" << petal->source
|
||||
<< " pos=" << petal->pos
|
||||
<< " length=" << petal->length
|
||||
<< " lines=" << petal->lines
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
if (!depth)
|
||||
std::cout << "\n\n";
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -43,6 +43,15 @@ struct Vase {
|
||||
OriginalBuffer *original;
|
||||
AppendBuffer *append;
|
||||
Shard *root;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool posix_ending = false;
|
||||
bool using_crlf = true;
|
||||
#else
|
||||
bool posix_ending = true;
|
||||
bool using_crlf = false;
|
||||
#endif
|
||||
|
||||
std::filesystem::path path;
|
||||
std::filesystem::path swapdir;
|
||||
|
||||
@@ -50,15 +59,18 @@ struct Vase {
|
||||
~Vase();
|
||||
|
||||
uint64_t length();
|
||||
uint64_t lines();
|
||||
std::string to_string();
|
||||
std::string to_string(Range range);
|
||||
|
||||
Iterator iterate(uint64_t line);
|
||||
Iterator iterate(uint64_t line, Direction dir);
|
||||
|
||||
void insert(Point *point, char key);
|
||||
void insert(Point *point, std::string_view str);
|
||||
void insert(Point *point, const char *data, uint64_t len);
|
||||
void erase(Point *point, uint64_t amount, Direction dir);
|
||||
void erase(Range range);
|
||||
void replace(Range range, std::string_view str);
|
||||
void replace(Range range, const char *data, uint64_t len);
|
||||
|
||||
void move_clusters(Point *point, uint64_t amount, Direction dir);
|
||||
|
||||
Reference in New Issue
Block a user