diff --git a/kitty/options/to-c.h b/kitty/options/to-c.h index 8e2ce4bf4..5c8126ae4 100644 --- a/kitty/options/to-c.h +++ b/kitty/options/to-c.h @@ -124,22 +124,28 @@ url_prefixes(PyObject *up, Options *opts) { } } +static char_type* +list_of_chars(PyObject *chars) { + if (!PyUnicode_Check(chars)) { PyErr_SetString(PyExc_TypeError, "list_of_chars must be a string"); return NULL; } + char_type *ans = calloc(PyUnicode_GET_LENGTH(chars) + 1, sizeof(char_type)); + if (ans) { + for (ssize_t i = 0; i < PyUnicode_GET_LENGTH(chars); i++) { + ans[i] = PyUnicode_READ(PyUnicode_KIND(chars), PyUnicode_DATA(chars), i); + } + } + return ans; +} + static void url_excluded_characters(PyObject *chars, Options *opts) { - if (!PyUnicode_Check(chars)) { PyErr_SetString(PyExc_TypeError, "url_excluded_characters must be a string"); return; } - for (size_t i = 0; i < MIN((size_t)PyUnicode_GET_LENGTH(chars), arraysz(opts->url_excluded_characters)); i++) { - opts->url_excluded_characters[i] = PyUnicode_READ(PyUnicode_KIND(chars), PyUnicode_DATA(chars), i); - } - opts->url_excluded_characters_count = PyUnicode_GET_LENGTH(chars); + free(opts->url_excluded_characters); + opts->url_excluded_characters = list_of_chars(chars); } static void select_by_word_characters(PyObject *chars, Options *opts) { - if (!PyUnicode_Check(chars)) { PyErr_SetString(PyExc_TypeError, "select_by_word_characters must be a string"); return; } - for (size_t i = 0; i < MIN((size_t)PyUnicode_GET_LENGTH(chars), arraysz(opts->select_by_word_characters)); i++) { - opts->select_by_word_characters[i] = PyUnicode_READ(PyUnicode_KIND(chars), PyUnicode_DATA(chars), i); - } - opts->select_by_word_characters_count = PyUnicode_GET_LENGTH(chars); + free(opts->select_by_word_characters); + opts->select_by_word_characters = list_of_chars(chars); } static void diff --git a/kitty/screen.c b/kitty/screen.c index 90b7c8df1..f7f83fa6a 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2563,8 +2563,10 @@ screen_selection_range_for_line(Screen *self, index_type y, index_type *start, i static inline bool is_opt_word_char(char_type ch) { - for (size_t i = 0; i < OPT(select_by_word_characters_count); i++) { - if (OPT(select_by_word_characters[i]) == ch) return true; + if (OPT(select_by_word_characters)) { + for (const char_type *p = OPT(select_by_word_characters); *p; p++) { + if (ch == *p) return true; + } } return false; } diff --git a/kitty/state.c b/kitty/state.c index 99febdfc5..ba0d6e56c 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -1091,6 +1091,8 @@ finalize(void) { free_bgimage(&global_state.bgimage, false); global_state.bgimage = NULL; free_url_prefixes(); + free(OPT(select_by_word_characters)); OPT(select_by_word_characters) = NULL; + free(OPT(url_excluded_characters)); OPT(url_excluded_characters) = NULL; } bool diff --git a/kitty/state.h b/kitty/state.h index 84a4463f8..698695cc2 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -30,7 +30,7 @@ typedef struct { unsigned int url_style; unsigned int scrollback_pager_history_size; bool scrollback_fill_enlarged_window; - char_type select_by_word_characters[256]; size_t select_by_word_characters_count; + char_type *select_by_word_characters; color_type url_color, background, foreground, active_border_color, inactive_border_color, bell_border_color; color_type mark1_foreground, mark1_background, mark2_foreground, mark2_background, mark3_foreground, mark3_background; monotonic_t repaint_delay, input_delay; @@ -70,7 +70,7 @@ typedef struct { UrlPrefix *values; size_t num, max_prefix_len; } url_prefixes; - char_type url_excluded_characters[256]; size_t url_excluded_characters_count; + char_type *url_excluded_characters; bool detect_urls; bool tab_bar_hidden; double font_size; diff --git a/kitty/unicode-data.h b/kitty/unicode-data.h index 89fe8605a..54e31ab92 100644 --- a/kitty/unicode-data.h +++ b/kitty/unicode-data.h @@ -14,8 +14,10 @@ combining_type mark_for_codepoint(char_type c); static inline bool is_excluded_from_url(uint32_t ch) { - for (size_t i = 0; i < OPT(url_excluded_characters_count); i++) { - if (ch == OPT(url_excluded_characters)[i]) return true; + if (OPT(url_excluded_characters)) { + for (const char_type *p = OPT(url_excluded_characters); *p; p++) { + if (ch == *p) return true; + } } return false; }