Navigation


Changeset 923:6a4d08e239bd in freeDiameter


Ignore:
Timestamp:
Feb 14, 2013, 11:58:55 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
thanks Thomas for the algorithm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/dictionary_functions.c

    r922 r923  
    228228                char * end = strchr(ret, '\0');
    229229               
    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                }
    231243        }       
    232244        return ret;
Note: See TracChangeset for help on using the changeset viewer.