diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-08-29 01:56:50 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-09-09 18:22:21 +0200 |
commit | 7c592561af3bbbad2eaf865247811ba2bd590c2e (patch) | |
tree | 75b27cf40fb9ba8d646eb00e05be5f91d116b493 /src/qreg-commands.c | |
parent | c71ed30cf0c554d288edfe87842082cc9ec393a7 (diff) | |
download | sciteco-7c592561af3bbbad2eaf865247811ba2bd590c2e.tar.gz |
Glyph to byte offset mapping is now using the line character index (refs #5)
* This works reasonably well unless lines are exceedingly long
(as on a line we always count characters).
The following test case is still slow (on Unicode buffers):
10000<@I/XX/> <%a-1:J;>
While the following is now also fast:
10000<@I/X^J/> <%a-1:J;>
* Commands with relative character offsets (C, R, A, D) have
a special optimization where they always count characters beginning
at dot, as long as the argument is now exceedingly large.
This means they are fast even on exceedingly long lines.
* The remaining commands (search, EC/EG, Xq) now accept glyph indexes.
Diffstat (limited to 'src/qreg-commands.c')
-rw-r--r-- | src/qreg-commands.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 1131c96..34f3164 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -678,7 +678,7 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, if (ctx->mode > TECO_MODE_NORMAL) return &teco_state_start; - teco_int_t from, len; + gssize from, len; /* in bytes */ if (!teco_expressions_eval(FALSE, error)) return NULL; @@ -702,12 +702,11 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, len *= -1; } } else { - teco_int_t to = teco_expressions_pop_num(0); - from = teco_expressions_pop_num(0); - + gssize to = teco_glyphs2bytes(teco_expressions_pop_num(0)); + from = teco_glyphs2bytes(teco_expressions_pop_num(0)); len = to - from; - if (len < 0 || !teco_validate_pos(from) || !teco_validate_pos(to)) { + if (len < 0 || from < 0 || to < 0) { teco_error_range_set(error, "X"); return NULL; } |