summaryrefslogtreecommitdiff
path: root/src/dged/buffer.h
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-08-23 17:07:27 +0200
committerAlbert Cervin <albert@acervin.com>2024-09-11 16:22:58 +0200
commit4ab7e453e26afc6e9f4938c65f89463fbba9e267 (patch)
tree4745d99e70d645a8134dafc3814dc68bf678daf4 /src/dged/buffer.h
parent991283f684c224db46fe68738470921b8c394f13 (diff)
downloaddged-4ab7e453e26afc6e9f4938c65f89463fbba9e267.tar.gz
dged-4ab7e453e26afc6e9f4938c65f89463fbba9e267.tar.xz
dged-4ab7e453e26afc6e9f4938c65f89463fbba9e267.zip
Overhaul unicode parsing
It now instead iterates the actual unicode code points. This is better than what it was previously doing but it is still not entirely correct w.r.t to unicode sequences. This handling of unicode code points does however make it slightly easier to handle UTF-16 if needed in the future. This also adds some long needed tests for buffer methods.
Diffstat (limited to 'src/dged/buffer.h')
-rw-r--r--src/dged/buffer.h44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/dged/buffer.h b/src/dged/buffer.h
index cd5bd95..c9fe2ca 100644
--- a/src/dged/buffer.h
+++ b/src/dged/buffer.h
@@ -295,13 +295,13 @@ struct location buffer_end(struct buffer *buffer);
uint32_t buffer_num_lines(struct buffer *buffer);
/**
- * Get the number of chars in a given line in buffer.
+ * Get the line length in number of column positions.
*
* @param [in] buffer The buffer to use.
- * @param [in] line The line to get number of chars for.
- * @returns The number of chars in @ref line.
+ * @param [in] line The line to get number of columns for.
+ * @returns The number of column positions in the current line.
*/
-uint32_t buffer_num_chars(struct buffer *buffer, uint32_t line);
+uint32_t buffer_line_length(struct buffer *buffer, uint32_t line);
/**
* Insert a newline in the buffer.
@@ -555,6 +555,13 @@ uint32_t buffer_add_reload_hook(struct buffer *buffer, reload_hook_cb callback,
void buffer_remove_reload_hook(struct buffer *buffer, uint32_t hook_id,
remove_hook_cb callback);
+struct edit_location {
+ struct region coordinates;
+ struct region bytes;
+ uint64_t global_byte_begin;
+ uint64_t global_byte_end;
+};
+
/**
* Buffer insert hook callback function.
*
@@ -565,9 +572,8 @@ void buffer_remove_reload_hook(struct buffer *buffer, uint32_t hook_id,
* @param end_idx The global byte offset to the end of where text was inserted.
* @param userdata The userdata as sent in to @ref buffer_add_insert_hook.
*/
-typedef void (*insert_hook_cb)(struct buffer *buffer, struct region inserted,
- uint32_t begin_idx, uint32_t end_idx,
- void *userdata);
+typedef void (*insert_hook_cb)(struct buffer *buffer,
+ struct edit_location inserted, void *userdata);
/**
* Add an insert hook, called when text is inserted into the @p buffer.
@@ -600,9 +606,8 @@ void buffer_remove_insert_hook(struct buffer *buffer, uint32_t hook_id,
* @param end_idx The global byte offset to the end of the removed text.
* @param userdata The userdata as sent in to @ref buffer_add_delete_hook.
*/
-typedef void (*delete_hook_cb)(struct buffer *buffer, struct region removed,
- uint32_t begin_idx, uint32_t end_idx,
- void *userdata);
+typedef void (*delete_hook_cb)(struct buffer *buffer,
+ struct edit_location removed, void *userdata);
/**
* Add a delete hook, called when text is removed from the @p buffer.
@@ -724,10 +729,6 @@ void buffer_update(struct buffer *buffer, struct buffer_update_params *params);
*/
void buffer_render(struct buffer *buffer, struct buffer_render_params *params);
-// TODO: move this to where it makes sense
-uint32_t visual_string_width(uint8_t *txt, uint32_t len, uint32_t start_col,
- uint32_t end_col);
-
/**
* Sort lines in a buffer alphabetically.
*
@@ -738,4 +739,19 @@ uint32_t visual_string_width(uint8_t *txt, uint32_t len, uint32_t start_col,
void buffer_sort_lines(struct buffer *buffer, uint32_t start_line,
uint32_t end_line);
+struct location buffer_location_to_byte_coords(struct buffer *buffer,
+ struct location coords);
+
+struct match_result {
+ struct location at;
+ bool found;
+};
+
+struct match_result
+buffer_find_prev_in_line(struct buffer *buffer, struct location start,
+ bool (*predicate)(const struct codepoint *c));
+struct match_result
+buffer_find_next_in_line(struct buffer *buffer, struct location start,
+ bool (*predicate)(const struct codepoint *c));
+
#endif