[gnome-builder/wip/chergert/grep: 11/15] grep: use utf-8 indexes for columns of matches
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/grep: 11/15] grep: use utf-8 indexes for columns of matches
- Date: Tue, 30 Oct 2018 20:41:12 +0000 (UTC)
commit 8d9003154889d983b75b86ccc3e62b8e2fd5436f
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 29 18:28:28 2018 -0700
grep: use utf-8 indexes for columns of matches
src/plugins/grep/gbp-grep-model.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/grep/gbp-grep-model.c b/src/plugins/grep/gbp-grep-model.c
index 80642e90e..b9ed86f6d 100644
--- a/src/plugins/grep/gbp-grep-model.c
+++ b/src/plugins/grep/gbp-grep-model.c
@@ -175,8 +175,14 @@ gbp_grep_model_line_parse (GbpGrepModelLine *cl,
{
GbpGrepModelMatch cm;
- cm.match_begin = match_begin;
- cm.match_end = match_end;
+ /*
+ * We need to convert match offsets from bytes into the
+ * number of UTF-8 (unichar) characters) so that we get
+ * proper columns into the target file. Otherwise we risk
+ * corrupting non-ASCII files.
+ */
+ cm.match_begin = g_utf8_strlen (cl->start_of_message, match_begin);
+ cm.match_end = g_utf8_strlen (cl->start_of_message, match_end);
g_array_append_val (cl->matches, cm);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]