Sha256: fa21f5fc138d650c90e545f780b7d42af9ccd0a4d91d25b5a6e21e75be6fb05b
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
#include "runtime/string_input.h" #include "runtime/alloc.h" #include <string.h> typedef struct { const char *string; uint32_t position; uint32_t length; } TSStringInput; const char *ts_string_input_read(void *payload, uint32_t *bytes_read) { TSStringInput *input = (TSStringInput *)payload; if (input->position >= input->length) { *bytes_read = 0; return ""; } uint32_t previous_position = input->position; input->position = input->length; *bytes_read = input->position - previous_position; return input->string + previous_position; } int ts_string_input_seek(void *payload, uint32_t character, uint32_t byte) { TSStringInput *input = (TSStringInput *)payload; input->position = byte; return (byte < input->length); } TSInput ts_string_input_make(const char *string) { return ts_string_input_make_with_length(string, strlen(string)); } TSInput ts_string_input_make_with_length(const char *string, uint32_t length) { TSStringInput *input = ts_malloc(sizeof(TSStringInput)); if (!input) goto error; input->string = string; input->position = 0; input->length = length; return (TSInput){ .payload = input, .read = ts_string_input_read, .seek = ts_string_input_seek, .encoding = TSInputEncodingUTF8, }; error: return (TSInput){ NULL, NULL, NULL, TSInputEncodingUTF8 }; }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tree-sitter-0.0.1 | ext/tree-sitter/tree-sitter/src/runtime/string_input.c |