[gimp/gimp-2-6] First part of fixes for handling UTF-8 coded strings (Bugs 572865 & 628893)



commit 136bfb61cc655d51b0ee7066f5126ceb33cf56c5
Author: Kevin Cozens <kcozens cvs gnome org>
Date:   Sun Sep 19 17:50:49 2010 -0400

    First part of fixes for handling UTF-8 coded strings (Bugs 572865 & 628893)
    
    Fixed string-set! and string-append due to mixup of chars vs. bytes.
    Fixed calculation of pointer to past end of string in open-*-string
    routines.
    (Cherry picked of commit d06a4ee4c37912557fce5a7e2e24b8015c6ccf9b)

 plug-ins/script-fu/tinyscheme/scheme.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/script-fu/tinyscheme/scheme.c b/plug-ins/script-fu/tinyscheme/scheme.c
index 4755993..ba40918 100644
--- a/plug-ins/script-fu/tinyscheme/scheme.c
+++ b/plug-ins/script-fu/tinyscheme/scheme.c
@@ -1018,6 +1018,8 @@ pointer foreign_error (scheme *sc, const char *s, pointer a) {
 /* char_cnt is length of string in chars. */
 /* str points to a NUL terminated string. */
 /* Only uses fill_char if str is NULL.    */
+/* This routine automatically adds 1 byte */
+/* to allow space for terminating NUL.    */
 static char *store_string(scheme *sc, int char_cnt,
                           const char *str, gunichar fill) {
      int  len;
@@ -3426,7 +3428,7 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
 
           free(strvalue(a));
           strvalue(a)=newstr;
-          strlength(a)=newlen;
+          strlength(a)=g_utf8_strlen(newstr, -1);
 
           s_return(sc,a);
      }
@@ -3437,18 +3439,24 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
        pointer newstr;
        pointer car_x;
        char *pos;
+       char *end;
 
        /* compute needed length for new string */
        for (x = sc->args; x != sc->NIL; x = cdr(x)) {
-          len += strlength(car(x));
+          car_x = car(x);
+          end = g_utf8_offset_to_pointer(strvalue(car_x), (long)strlength(car_x));
+          len += end - strvalue(car_x);
        }
        newstr = mk_empty_string(sc, len, ' ');
+
        /* store the contents of the argument strings into the new string */
        pos = strvalue(newstr);
        for (x = sc->args; x != sc->NIL; x = cdr(x)) {
            car_x = car(x);
-           memcpy(pos, strvalue(car_x), strlength(car_x));
-           pos += strlength(car_x);
+           end = g_utf8_offset_to_pointer(strvalue(car_x), (long)strlength(car_x));
+           len = end - strvalue(car_x);
+           memcpy(pos, strvalue(car_x), len);
+           pos += len;
        }
        *pos = '\0';
        s_return(sc, newstr);
@@ -3889,7 +3897,8 @@ static pointer opexe_4(scheme *sc, enum scheme_opcodes op) {
                default:                   break;  /* Quiet the compiler */
           }
           p=port_from_string(sc, strvalue(car(sc->args)),
-                     strvalue(car(sc->args))+strlength(car(sc->args)), prop);
+                     g_utf8_offset_to_pointer(strvalue(car(sc->args)),
+                                              strlength(car(sc->args))), prop);
           if(p==sc->NIL) {
                s_return(sc,sc->F);
           }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]