aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-commands.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-03 22:42:03 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-09 18:22:21 +0200
commitb85edaa0021c06d63fee6d8904fc822815e8b933 (patch)
treea4ef1f599852ae327660e74c63b09329543fb126 /src/core-commands.c
parenta747cff2b6027d5e013aa84c1db0159c51983a79 (diff)
downloadsciteco-b85edaa0021c06d63fee6d8904fc822815e8b933.tar.gz
<I> command evaluates input codepoints (refs #5)
Diffstat (limited to 'src/core-commands.c')
-rw-r--r--src/core-commands.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 1d060b0..ef4621f 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -2753,24 +2753,31 @@ teco_state_insert_initial(teco_machine_main_t *ctx, GError **error)
if (teco_interface_ssm(SCI_GETCODEPAGE, 0, 0) == SC_CP_UTF8) {
/* detect possible errors before introducing side effects */
- for (int i = args; i > 0; i--) {
- gunichar chr = teco_expressions_peek_num(i-1);
- if (!g_unichar_validate(chr)) {
+ for (gint i = args; i > 0; i--) {
+ teco_int_t chr = teco_expressions_peek_num(i-1);
+ if (chr < 0 || !g_unichar_validate(chr)) {
teco_error_codepoint_set(error, "I");
return FALSE;
}
}
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
- for (int i = args; i > 0; i--) {
- gunichar chr = teco_expressions_peek_num(i-1);
+ for (gint i = args; i > 0; i--) {
+ /* 4 bytes should be enough, but we better follow the documentation */
gchar buf[6];
- teco_interface_ssm(SCI_ADDTEXT,
- g_unichar_to_utf8(chr, buf), (sptr_t)buf);
+ gsize len = g_unichar_to_utf8(teco_expressions_peek_num(i-1), buf);
+ teco_interface_ssm(SCI_ADDTEXT, len, (sptr_t)buf);
}
} else {
- // FIXME: everything else is a single-byte encoding?
+ /* everything else is a single-byte encoding */
+ for (gint i = args; i > 0; i--) {
+ teco_int_t chr = teco_expressions_peek_num(i-1);
+ if (chr < 0 || chr > 0xFF) {
+ teco_error_codepoint_set(error, "I");
+ return FALSE;
+ }
+ }
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
- for (int i = args; i > 0; i--) {
+ for (gint i = args; i > 0; i--) {
gchar chr = (gchar)teco_expressions_peek_num(i-1);
teco_interface_ssm(SCI_ADDTEXT, 1, (sptr_t)&chr);
}
@@ -2781,7 +2788,8 @@ teco_state_insert_initial(teco_machine_main_t *ctx, GError **error)
if (teco_current_doc_must_undo())
undo__teco_interface_ssm(SCI_UNDO, 0, 0);
- for (int i = args; i > 0; i--)
+ /* This is done only now because it can _theoretically_ fail. */
+ for (gint i = args; i > 0; i--)
if (!teco_expressions_pop_num_calc(NULL, 0, error))
return FALSE;