summaryrefslogtreecommitdiff
path: root/src/vteconv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vteconv.c')
-rw-r--r--src/vteconv.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/src/vteconv.c b/src/vteconv.c
index 2b91d33e..ef94880e 100644
--- a/src/vteconv.c
+++ b/src/vteconv.c
@@ -1,19 +1,19 @@
/*
* Copyright (C) 2003 Red Hat, Inc.
*
- * This is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* The interfaces in this file are subject to change at any time. */
@@ -38,7 +38,7 @@ struct _VteConv {
convert_func convert;
gint (*close)(GIConv converter);
gboolean in_unichar, out_unichar;
- VteBuffer *in_scratch, *out_scratch;
+ VteByteArray *in_scratch, *out_scratch;
};
/* We can't use g_utf8_strlen as that's not nul-safe :( */
@@ -66,7 +66,6 @@ _vte_conv_utf8_utf8(GIConv converter,
gboolean validated;
const gchar *endptr;
size_t bytes;
- guint skip;
/* We don't tolerate shenanigans! */
g_assert(*outbytes_left >= *inbytes_left);
@@ -88,29 +87,9 @@ _vte_conv_utf8_utf8(GIConv converter,
return 0;
}
- /* Determine why the end of the string is not valid.
- * We are pur b@stards for running g_utf8_next_char() on an
- * invalid sequence. */
- skip = g_utf8_next_char(*inbuf) - *inbuf;
- if (skip > *inbytes_left) {
- /* We didn't have enough bytes to validate the character.
- * That qualifies for EINVAL, but only if the part of the
- * character that we have is a valid prefix to a character.
- * Differentiating those requires verifying that all the
- * remaining bytes after this one are UTF-8 continuation
- * bytes. Actually even that is not quite enough as not
- * all continuation bytes are valid in the most strict
- * interpretation of UTF-8, but we don't care about that.
- */
- size_t i;
-
- for (i = 1; i < *inbytes_left; i++)
- if (((*inbuf)[i] & 0xC0) != 0x80) {
- /* Not a continuation byte */
- errno = EILSEQ;
- return (size_t) -1;
- }
-
+ /* Determine why the end of the string is not valid. */
+ if (g_utf8_get_char_validated(*inbuf, *inbytes_left) == (gunichar) -2) {
+ /* Prefix of a valid UTF-8 */
errno = EINVAL;
} else {
/* We had enough bytes to validate the character, and
@@ -192,8 +171,8 @@ _vte_conv_open(const char *target, const char *source)
ret->out_unichar = out_unichar;
/* Create scratch buffers. */
- ret->in_scratch = _vte_buffer_new();
- ret->out_scratch = _vte_buffer_new();
+ ret->in_scratch = _vte_byte_array_new();
+ ret->out_scratch = _vte_byte_array_new();
return ret;
}
@@ -211,8 +190,8 @@ _vte_conv_close(VteConv converter)
}
/* Free the scratch buffers. */
- _vte_buffer_free(converter->in_scratch);
- _vte_buffer_free(converter->out_scratch);
+ _vte_byte_array_free(converter->in_scratch);
+ _vte_byte_array_free(converter->out_scratch);
/* Free the structure itself. */
g_slice_free(struct _VteConv, converter);
@@ -229,7 +208,6 @@ _vte_conv(VteConv converter,
const guchar *work_inbuf_start, *work_inbuf_working;
guchar *work_outbuf_start, *work_outbuf_working;
gsize work_inbytes, work_outbytes;
- gsize in_converted, out_converted;
g_assert(converter != NULL);
g_assert(converter != VTE_INVALID_CONV);
@@ -238,8 +216,6 @@ _vte_conv(VteConv converter,
work_outbuf_start = work_outbuf_working = *outbuf;
work_inbytes = *inbytes_left;
work_outbytes = *outbytes_left;
- in_converted = 0;
- out_converted = 0;
/* Possibly convert the input data from gunichars to UTF-8. */
if (converter->in_unichar) {
@@ -248,7 +224,7 @@ _vte_conv(VteConv converter,
gunichar *g;
/* Make sure the scratch buffer has enough space. */
char_count = *inbytes_left / sizeof(gunichar);
- _vte_buffer_set_minimum_size(converter->in_scratch,
+ _vte_byte_array_set_minimum_size(converter->in_scratch,
(char_count + 1) * VTE_UTF8_BPC);
/* Convert the incoming text. */
g = (gunichar*) *inbuf;
@@ -267,7 +243,7 @@ _vte_conv(VteConv converter,
/* Possibly set the output pointers to point at our scratch buffer. */
if (converter->out_unichar) {
work_outbytes = *outbytes_left * VTE_UTF8_BPC;
- _vte_buffer_set_minimum_size(converter->out_scratch,
+ _vte_byte_array_set_minimum_size(converter->out_scratch,
work_outbytes);
work_outbuf_start = converter->out_scratch->data;
work_outbuf_working = work_outbuf_start;