changeset 923:6a4d08e239bd

Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence, thanks Thomas for the algorithm.
author Sebastien Decugis <sdecugis@freediameter.net>
date Thu, 14 Feb 2013 15:58:55 +0100
parents c7bf1a7a4e90
children 877592751fee
files libfdproto/dictionary_functions.c
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libfdproto/dictionary_functions.c	Thu Feb 14 15:43:36 2013 +0100
+++ b/libfdproto/dictionary_functions.c	Thu Feb 14 15:58:55 2013 +0100
@@ -227,7 +227,19 @@
 
 		char * end = strchr(ret, '\0');
 		
-	
+		while (end > ret) {
+			end--;
+			char b = *end;
+			/* after the position pointed by end, we have only \0s */
+			if ((b & 0x80) == 0) {
+				break; /* this is a single byte char, no problem */
+			} else {
+				/* this byte is start or cont. of multibyte sequence, as we do not know the next byte we need to delete it. */
+				*end = '\0';
+				if (b & 0x40)
+					break; /* This was a start byte, we can stop the loop */
+			}
+		}
 	}	
 	return ret;
 }
"Welcome to our mercurial repository"