* 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
This commit is contained in:
Stephan Aßmus 2007-11-11 10:21:29 +00:00
parent 92deda607e
commit acdf38f663
1 changed files with 6 additions and 2 deletions

View File

@ -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;
}