From acdf38f6630c2fffa81e3ccb788e3b9d838d53fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 11 Nov 2007 10:21:29 +0000 Subject: [PATCH] * fixed a bug researched by Varadi Zsolt Gyula, if the buffer is one byte long or empty, assume text anyways, fixes Styled Edit opening empty files (#1610) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22892 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/translators/stxt/STXTTranslator.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/add-ons/translators/stxt/STXTTranslator.cpp b/src/add-ons/translators/stxt/STXTTranslator.cpp index f62bc9bd1c..96820a0419 100644 --- a/src/add-ons/translators/stxt/STXTTranslator.cpp +++ b/src/add-ons/translators/stxt/STXTTranslator.cpp @@ -218,10 +218,15 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType, code = "ASCII"; encoding = NULL; //"us-ascii"; type = "text"; - } else if (looks_utf8(buf, nbytes, ubuf, &ulen)) { + } else if (nbytes == 0 || looks_utf8(buf, nbytes, ubuf, &ulen)) { 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 ((i = looks_unicode(buf, nbytes, ubuf, &ulen)) != 0) { if (i == 1) { code = "Little-endian UTF-16 Unicode"; @@ -258,7 +263,6 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType, } if (nbytes <= 1) { - rv = 0; goto done; }