1 /*
2 * pluma-spell-utils.c
3 * This file is part of pluma
4 *
5 * Copyright (C) 2010 - Jesse van den Kieboom
6 * Copyright (C) 2012-2021 MATE Developers
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301 USA
22 */
23
24 #include <string.h>
25
26 #include "pluma-spell-utils.h"
27 #include <gtksourceview/gtksource.h>
28
29 gboolean
pluma_spell_utils_is_digit(const char * text,gssize length)30 pluma_spell_utils_is_digit (const char *text, gssize length)
31 {
32 gunichar c;
33 const gchar *p;
34 const gchar *end;
35
36 g_return_val_if_fail (text != NULL, FALSE);
37
38 if (length < 0)
39 length = strlen (text);
40
41 p = text;
42 end = text + length;
43
44 while (p != end) {
45 const gchar *next;
46 next = g_utf8_next_char (p);
47
48 c = g_utf8_get_char (p);
49
50 if (!g_unichar_isdigit (c) && c != '.' && c != ',')
51 return FALSE;
52
53 p = next;
54 }
55
56 return TRUE;
57 }
58
59 gboolean
pluma_spell_utils_skip_no_spell_check(GtkTextIter * start,GtkTextIter * end)60 pluma_spell_utils_skip_no_spell_check (GtkTextIter *start,
61 GtkTextIter *end)
62 {
63 GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gtk_text_iter_get_buffer (start));
64
65 while (gtk_source_buffer_iter_has_context_class (buffer, start, "no-spell-check"))
66 {
67 GtkTextIter last = *start;
68
69 if (!gtk_source_buffer_iter_forward_to_context_class_toggle (buffer, start, "no-spell-check"))
70 {
71 return FALSE;
72 }
73
74 if (gtk_text_iter_compare (start, &last) <= 0)
75 {
76 return FALSE;
77 }
78
79 gtk_text_iter_forward_word_end (start);
80 gtk_text_iter_backward_word_start (start);
81
82 if (gtk_text_iter_compare (start, &last) <= 0)
83 {
84 return FALSE;
85 }
86
87 if (gtk_text_iter_compare (start, end) >= 0)
88 {
89 return FALSE;
90 }
91 }
92
93 return TRUE;
94 }
95
96