aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/view.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-06-01 02:38:25 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-06-01 03:06:13 +0300
commit442268285a5f8b1d53052b6c7b0566d9200e71c7 (patch)
tree90fb62e9157445aebc2253ece0ec96b0934d1932 /src/view.c
parent6e3da17a2fae11af9ae00d9b59bd0d752022e16b (diff)
downloadsciteco-442268285a5f8b1d53052b6c7b0566d9200e71c7.tar.gz
<nA> and <nQq> now return -1 in case the index n is out of range
* The old behavior of throwing an error was inherited from Video TECO. * The command is now more similar to TECO-11. * Since -1 is taken, invalid and incomplete UTF-8 byte sequences are now reported as -2/-3. I wasn't really able to provoke -3, though.
Diffstat (limited to 'src/view.c')
-rw-r--r--src/view.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/view.c b/src/view.c
index 71d74e2..e21d53a 100644
--- a/src/view.c
+++ b/src/view.c
@@ -628,8 +628,8 @@ teco_view_glyphs2bytes_relative(teco_view_t *ctx, gsize pos, teco_int_t n)
* @param pos The glyph's byte position
* @param len The length of the document in bytes
* @return The requested codepoint.
- * In UTF-8 encoded documents, this might be -1 (incomplete sequence)
- * or -2 (invalid byte sequence).
+ * In UTF-8 encoded documents, this might be -2 (invalid byte sequence)
+ * or -3 (incomplete sequence).
*/
teco_int_t
teco_view_get_character(teco_view_t *ctx, gsize pos, gsize len)
@@ -653,12 +653,15 @@ teco_view_get_character(teco_view_t *ctx, gsize pos, gsize len)
* or repeatedly calling SCI_GETCHARAT.
*/
teco_view_ssm(ctx, SCI_GETTEXTRANGEFULL, 0, (sptr_t)&range);
+ if (!*buf)
+ return 0;
/*
* Make sure that the -1/-2 error values are preserved.
* The sign bit in UCS-4/UTF-32 is unused, so this will even
* suffice if TECO_INTEGER == 32.
*/
- return *buf ? (gint32)g_utf8_get_char_validated(buf, -1) : 0;
+ gint32 rc = g_utf8_get_char_validated(buf, -1);
+ return rc < 0 ? rc-1 : rc;
}
void