2014-09-26 16:15:07 -07:00
|
|
|
#ifndef RUNTIME_LENGTH_H_
|
|
|
|
|
#define RUNTIME_LENGTH_H_
|
|
|
|
|
|
|
|
|
|
#include "tree_sitter/runtime.h"
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
static inline TSLength ts_length_add(TSLength len1, TSLength len2) {
|
2014-09-26 16:31:30 -07:00
|
|
|
TSLength result;
|
|
|
|
|
result.bytes = len1.bytes + len2.bytes;
|
|
|
|
|
result.chars = len1.chars + len2.chars;
|
2015-09-15 16:00:16 -07:00
|
|
|
|
|
|
|
|
if ((len1.chars > 0 && len1.bytes == 0) || (len2.chars > 0 && len2.bytes == 0))
|
|
|
|
|
result.bytes = 0;
|
|
|
|
|
|
2014-09-26 16:31:30 -07:00
|
|
|
return result;
|
2014-09-26 16:15:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline TSLength ts_length_sub(TSLength len1, TSLength len2) {
|
2014-09-26 16:31:30 -07:00
|
|
|
TSLength result;
|
|
|
|
|
result.bytes = len1.bytes - len2.bytes;
|
|
|
|
|
result.chars = len1.chars - len2.chars;
|
2015-09-15 16:00:16 -07:00
|
|
|
|
|
|
|
|
if ((len1.chars > 0 && len1.bytes == 0) || (len2.chars > 0 && len2.bytes == 0))
|
|
|
|
|
result.bytes = 0;
|
|
|
|
|
|
2014-09-26 16:31:30 -07:00
|
|
|
return result;
|
2014-09-26 16:15:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline TSLength ts_length_zero() {
|
2014-09-26 16:31:30 -07:00
|
|
|
TSLength result;
|
|
|
|
|
result.bytes = result.chars = 0;
|
|
|
|
|
return result;
|
2014-09-26 16:15:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_length_eq(TSLength len1, TSLength len2) {
|
|
|
|
|
return len1.bytes == len2.bytes && len1.chars == len2.chars;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 16:31:30 -07:00
|
|
|
static inline TSLength ts_length_make(size_t bytes, size_t chars) {
|
|
|
|
|
TSLength result;
|
|
|
|
|
result.bytes = bytes;
|
|
|
|
|
result.chars = chars;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 16:15:07 -07:00
|
|
|
#endif
|