diff options
author | David Robillard <d@drobilla.net> | 2022-10-23 22:11:35 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:07 -0500 |
commit | 38f85ad8c53c618033e3d0b7cb1fe782c38cf0a3 (patch) | |
tree | 8f5f1e7be38d98c9e354a67bdf7b94a3e35c3a60 /src/caret.c | |
parent | 3b89559e4c08202bee228e25ea42a4371e333c9b (diff) | |
download | serd-38f85ad8c53c618033e3d0b7cb1fe782c38cf0a3.tar.gz serd-38f85ad8c53c618033e3d0b7cb1fe782c38cf0a3.tar.bz2 serd-38f85ad8c53c618033e3d0b7cb1fe782c38cf0a3.zip |
Add SerdCaret
Diffstat (limited to 'src/caret.c')
-rw-r--r-- | src/caret.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/caret.c b/src/caret.c new file mode 100644 index 00000000..1b0de444 --- /dev/null +++ b/src/caret.c @@ -0,0 +1,69 @@ +// Copyright 2018-2020 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include "caret.h" + +#include "serd/caret.h" + +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +SerdCaret* +serd_caret_new(const SerdNode* const document, + const unsigned line, + const unsigned column) +{ + SerdCaret* caret = (SerdCaret*)malloc(sizeof(SerdCaret)); + + if (caret) { + caret->document = document; + caret->line = line; + caret->col = column; + } + + return caret; +} + +SerdCaret* +serd_caret_copy(const SerdCaret* const caret) +{ + if (!caret) { + return NULL; + } + + SerdCaret* copy = (SerdCaret*)malloc(sizeof(SerdCaret)); + memcpy(copy, caret, sizeof(SerdCaret)); + return copy; +} + +void +serd_caret_free(SerdCaret* const caret) +{ + free(caret); +} + +bool +serd_caret_equals(const SerdCaret* const l, const SerdCaret* const r) +{ + return (l == r || (l && r && serd_node_equals(l->document, r->document) && + l->line == r->line && l->col == r->col)); +} + +const SerdNode* +serd_caret_document(const SerdCaret* const caret) +{ + return caret->document; +} + +unsigned +serd_caret_line(const SerdCaret* const caret) +{ + return caret->line; +} + +unsigned +serd_caret_column(const SerdCaret* const caret) +{ + return caret->col; +} |