Ticket #1610: stxt-fix-nullbytes.patch

File stxt-fix-nullbytes.patch, 1.2 KB (added by vzsolt, 16 years ago)

A patch separating the (nBytes == 0) condition.

  • src/add-ons/translators/stxt/STXTTranslator.cpp

     
    214214     * the text converted into one-my_unichar-per-character Unicode in
    215215     * ubuf, and the number of characters converted in ulen.
    216216     */
    217     if (looks_ascii(buf, nbytes, ubuf, &ulen)) {
     217    if (nbytes == 0)
     218    {
     219        code = "UTF-8 Unicode";
     220        encoding = NULL; // "UTF-8";
     221        type = "text";
     222        rv = 1;
     223    } else  if (looks_ascii(buf, nbytes, ubuf, &ulen)) {
    218224        code = "ASCII";
    219225        encoding = NULL; //"us-ascii";
    220226        type = "text";
    221227        if (nbytes == 1)
    222228            rv = 1;
    223     } else if (nbytes == 0 || looks_utf8(buf, nbytes, ubuf, &ulen)) {
     229    } else if (looks_utf8(buf, nbytes, ubuf, &ulen)) {
    224230        code = "UTF-8 Unicode";
    225231        encoding = NULL; // "UTF-8";
    226232        type = "text";
    227         if (nbytes == 0) {
    228             // this is also the Haiku default encoding
    229             // in case we have an empty buffer
    230             rv = 1;
    231         }
    232233    } else if ((i = looks_unicode(buf, nbytes, ubuf, &ulen)) != 0) {
    233234        if (i == 1) {
    234235            code = "Little-endian UTF-16 Unicode";