Mercurial > hg > freeDiameter
comparison libfdproto/dictionary_functions.c @ 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 | e63de8d76916 |
comparison
equal
deleted
inserted
replaced
922:c7bf1a7a4e90 | 923:6a4d08e239bd |
---|---|
225 We do this whether the string is trucated at TRUNC_LEN or not, to avoid potential problem | 225 We do this whether the string is trucated at TRUNC_LEN or not, to avoid potential problem |
226 with malformed AVP */ | 226 with malformed AVP */ |
227 | 227 |
228 char * end = strchr(ret, '\0'); | 228 char * end = strchr(ret, '\0'); |
229 | 229 |
230 | 230 while (end > ret) { |
231 end--; | |
232 char b = *end; | |
233 /* after the position pointed by end, we have only \0s */ | |
234 if ((b & 0x80) == 0) { | |
235 break; /* this is a single byte char, no problem */ | |
236 } else { | |
237 /* this byte is start or cont. of multibyte sequence, as we do not know the next byte we need to delete it. */ | |
238 *end = '\0'; | |
239 if (b & 0x40) | |
240 break; /* This was a start byte, we can stop the loop */ | |
241 } | |
242 } | |
231 } | 243 } |
232 return ret; | 244 return ret; |
233 } | 245 } |
234 | 246 |
235 | 247 |