[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] [PATCH] Linebreaks in KOrganizer's encoding (local8Bit ->
From:       Reinhold Kainhofer <reinhold () kainhofer ! com>
Date:       2003-10-31 12:29:31
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> There is still one problem left: libkcal seems to insert a line break and a
> space into long summaries/descriptions of events. This leads to a broken
> character every 25 letters or so (see
> http://reinhold.kainhofer.com/Linux/pictures/Unicode1.png). Any idea how to
> prevent this?
> I suspect that I have to add some property to the calendar to indicate utf8
> encoding, but I have no ideas where, what and how.

Okay, I found the cause of this problem. It was inside libical, which just 
inserted the "\n " folding marker when 75 chars were reached. If this was 
inside a utf-8 character, that character was messed up. The attached patch 
fixes this by folding long lines only between utf-8 characters: The "\n " is 
inserted only before bytes incidating a US-ASCII (bit struct 0xxxxxxx) or the 
first byte of a multi-byte utf-8 character (bit struct 11xxxxxx), thus 
ensuring the line break never occurs inside a utf-8 encoded char.
 
After 75 chars the line break is inserted in any case, but if we ever get to 
75 characters in a line, we can't have to do with utf-8 but with some "weird" 
encoding which uses at least 8 bytes with bit structure 10xxxxxx in a row.


With these two patches (this one and the previous) the ics files generated by 
korganizer now tread unicode characters (e.g. Russion, etc.) exactly like 
evolution does, so it can't be that wrong ;-)

Okay to apply this patch and the previous? 

Reinhold
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/olWrTqjEwhXvPN0RArXZAKCkh7Kleg+J09eUzQ9hL2JmYv9+zACfapRR
dq9AIwv/miyia2wr8WEkYyw=
=PO5J
-----END PGP SIGNATURE-----

["2003-10-31_LibICal_utf8_LineBreaks.patch" (text/x-diff)]

Index: src/libical/icalvalue.c
===================================================================
RCS file: /home/kde/kdepim/libical/src/libical/icalvalue.c,v
retrieving revision 1.9
diff -u -p -3 -w -b -B -r1.9 icalvalue.c
--- src/libical/icalvalue.c	24 Jun 2002 22:02:34 -0000	1.9
+++ src/libical/icalvalue.c	31 Oct 2003 12:05:57 -0000
@@ -656,8 +656,13 @@ char* icalvalue_text_as_ical_string(ical
     if (str_p == 0){
       return 0;
     }
-
     for(p=((struct icalvalue_impl*)value)->data.v_string; *p!=0; p++){
+      /* If length>=68, check for beginning of a utf-8 char. */
+        if ( ( line_length >= 65 && *p == ' ') || (line_length >= 75) || 
+       ( line_length >= 68 && ((unsigned char)(*p)>=192 || (unsigned char)(*p)<128) ) ) {
+            icalmemory_append_string(&str,&str_p,&buf_sz,"\n ");
+            line_length=0;
+        }
 
 	switch(*p){
 	    case '\n': {
@@ -701,17 +706,6 @@ char* icalvalue_text_as_ical_string(ical
 	    }
 	}
 
-	if (line_length > 65 && *p == ' '){
-	    icalmemory_append_string(&str,&str_p,&buf_sz,"\n ");
-	    line_length=0;
-	}
-
-
-	if (line_length > 75){
-	    icalmemory_append_string(&str,&str_p,&buf_sz,"\n ");
-	    line_length=0;
-	}
-
     }
 
     /* Assume the last character is not a '\0' and add one. We could


_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic