From 1185d9324050ebea77379d100a550adb6ab08fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 11 Nov 2007 12:56:46 +0000 Subject: [PATCH] * patch by vzsolt which really fixes the problem with zero byte buffers git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22895 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../translators/stxt/STXTTranslator.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/add-ons/translators/stxt/STXTTranslator.cpp b/src/add-ons/translators/stxt/STXTTranslator.cpp index 71a1fabe52..3da62c8c91 100644 --- a/src/add-ons/translators/stxt/STXTTranslator.cpp +++ b/src/add-ons/translators/stxt/STXTTranslator.cpp @@ -214,21 +214,23 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType, * the text converted into one-my_unichar-per-character Unicode in * ubuf, and the number of characters converted in ulen. */ - if (looks_ascii(buf, nbytes, ubuf, &ulen)) { - code = "ASCII"; - encoding = NULL; //"us-ascii"; - type = "text"; - if (nbytes == 1) - rv = 1; - } else if (nbytes == 0 || looks_utf8(buf, nbytes, ubuf, &ulen)) { + if (nbytes == 0) { code = "UTF-8 Unicode"; encoding = NULL; // "UTF-8"; type = "text"; - if (nbytes == 0) { - // this is also the Haiku default encoding - // in case we have an empty buffer + rv = 1; + } else if (looks_ascii(buf, nbytes, ubuf, &ulen)) { + code = "ASCII"; + encoding = NULL; //"us-ascii"; + type = "text"; + if (nbytes == 1) { + // no further tests rv = 1; } + } else if (looks_utf8(buf, nbytes, ubuf, &ulen)) { + code = "UTF-8 Unicode"; + encoding = NULL; // "UTF-8"; + type = "text"; } else if ((i = looks_unicode(buf, nbytes, ubuf, &ulen)) != 0) { if (i == 1) { code = "Little-endian UTF-16 Unicode";