You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.8 KiB
103 lines
3.8 KiB
From dcaaf89d44ddb463e8be22583080f454fc61d2d9 Mon Sep 17 00:00:00 2001
|
|
From: gnome-commander Fedora maintainer
|
|
<gnome-commander-owner@fedoraproject.org>
|
|
Date: Sun, 21 Nov 2021 11:21:29 +0900
|
|
Subject: [PATCH] unicode2utf8(viewer-utils): fix logic on big endian
|
|
|
|
---
|
|
src/intviewer/inputmodes.cc | 2 +-
|
|
src/intviewer/viewer-utils.cc | 24 ++++++++++++------------
|
|
src/intviewer/viewer-utils.h | 2 +-
|
|
3 files changed, 14 insertions(+), 14 deletions(-)
|
|
|
|
diff --git a/src/intviewer/inputmodes.cc b/src/intviewer/inputmodes.cc
|
|
index 269777e7..7a4d1b5f 100644
|
|
--- a/src/intviewer/inputmodes.cc
|
|
+++ b/src/intviewer/inputmodes.cc
|
|
@@ -223,7 +223,7 @@ static void inputmode_ascii_activate(GVInputModesData *imd, const gchar *encodin
|
|
{
|
|
// these are defined in 'cp437.c'
|
|
unsigned int unicode = ascii_cp437_to_unicode[i];
|
|
- unicode2utf8(unicode, (unsigned char*)&imd->ascii_charset_translation[i]);
|
|
+ unicode2utf8(unicode, &imd->ascii_charset_translation[i]);
|
|
}
|
|
g_free (imd->input_mode_name);
|
|
imd->input_mode_name = g_strdup ("CP437");
|
|
diff --git a/src/intviewer/viewer-utils.cc b/src/intviewer/viewer-utils.cc
|
|
index 40f8819c..6d9c6e59 100644
|
|
--- a/src/intviewer/viewer-utils.cc
|
|
+++ b/src/intviewer/viewer-utils.cc
|
|
@@ -29,36 +29,36 @@
|
|
|
|
using namespace std;
|
|
|
|
-int unicode2utf8 (unsigned int unicode, unsigned char *out)
|
|
+int unicode2utf8 (unsigned int unicode, char_type *out)
|
|
{
|
|
int bytes_needed = 0;
|
|
if (unicode<0x80)
|
|
{
|
|
bytes_needed = 1;
|
|
- out[0] = (unsigned char)(unicode&0xFF);
|
|
+ *out = (unsigned char)(unicode&0xFF);
|
|
}
|
|
else
|
|
if (unicode<0x0800)
|
|
{
|
|
bytes_needed = 2;
|
|
- out[0] = (unsigned char)(unicode>>6 | 0xC0);
|
|
- out[1] = (unsigned char)((unicode&0x3F)| 0x80);
|
|
+ *out = (unsigned char)(unicode>>6 | 0xC0);
|
|
+ *out |= ((unsigned char)((unicode&0x3F)| 0x80) << 8);
|
|
}
|
|
else
|
|
if (unicode<0x10000)
|
|
{
|
|
bytes_needed = 3;
|
|
- out[0] = (unsigned char)((unicode>>12) | 0xE0);
|
|
- out[1] = (unsigned char)(((unicode>>6) & 0x3F) | 0x80);
|
|
- out[2] = (unsigned char)((unicode & 0x3F) | 0x80);
|
|
+ *out = (unsigned char)((unicode>>12) | 0xE0);
|
|
+ *out |= ((unsigned char)(((unicode>>6) & 0x3F) | 0x80) << 8);
|
|
+ *out |= ((unsigned char)((unicode & 0x3F) | 0x80) << 16);
|
|
}
|
|
else
|
|
{
|
|
bytes_needed = 4;
|
|
- out[0] = (unsigned char)((unicode>>18) | 0xE0);
|
|
- out[1] = (unsigned char)(((unicode>>12) & 0x3F) | 0x80);
|
|
- out[2] = (unsigned char)(((unicode>>6) & 0x3F) | 0x80);
|
|
- out[3] = (unsigned char)((unicode & 0x3F) | 0x80);
|
|
+ *out = (unsigned char)((unicode>>18) | 0xE0);
|
|
+ *out |= ((unsigned char)(((unicode>>12) & 0x3F) | 0x80) << 8);
|
|
+ *out |= ((unsigned char)(((unicode>>6) & 0x3F) | 0x80) << 16);
|
|
+ *out |= ((unsigned char)((unicode & 0x3F) | 0x80) << 24);
|
|
}
|
|
|
|
return bytes_needed;
|
|
@@ -84,7 +84,7 @@ char_type *convert_utf8_to_chartype_array (const gchar *utf8text, /*out*/ int &a
|
|
{
|
|
unicode_char = g_utf8_get_char(pos);
|
|
|
|
- unicode2utf8(unicode_char, (unsigned char*)&result[index]);
|
|
+ unicode2utf8(unicode_char, &result[index]);
|
|
|
|
pos = g_utf8_next_char(pos);
|
|
if (!pos)
|
|
diff --git a/src/intviewer/viewer-utils.h b/src/intviewer/viewer-utils.h
|
|
index eb06fedc..c561e698 100644
|
|
--- a/src/intviewer/viewer-utils.h
|
|
+++ b/src/intviewer/viewer-utils.h
|
|
@@ -26,7 +26,7 @@
|
|
|
|
#define GVIEWER_DEFAULT_PATH_PREFIX "/gnome-commander/internal_viewer/"
|
|
|
|
-int unicode2utf8(unsigned int unicode, unsigned char *out);
|
|
+int unicode2utf8(unsigned int unicode, char_type *out);
|
|
char_type *convert_utf8_to_chartype_array(const gchar *utf8text, /*out*/ int &array_length);
|
|
|
|
guint8 *mem_reverse(const guint8 *buffer, guint buflen);
|
|
--
|
|
2.33.1
|
|
|