No longer returns B_NO_TRANSLATOR if it suspects the data is not text data, instead, it returns B_OK with a low capability rating. This is so that STXTTranslator can be used with OBOS StyledEdit
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4255 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -411,6 +411,7 @@ status_t
|
|||||||
identify_txt_header(uint8 *data, int32 nread,
|
identify_txt_header(uint8 *data, int32 nread,
|
||||||
BPositionIO *inSource, translator_info *outInfo, uint32 outType)
|
BPositionIO *inSource, translator_info *outInfo, uint32 outType)
|
||||||
{
|
{
|
||||||
|
float capability = TEXT_IN_CAPABILITY;
|
||||||
uint8 ch;
|
uint8 ch;
|
||||||
ssize_t readlater = 0;
|
ssize_t readlater = 0;
|
||||||
readlater = inSource->Read(data + nread, DATA_BUFFER_SIZE - nread);
|
readlater = inSource->Read(data + nread, DATA_BUFFER_SIZE - nread);
|
||||||
@@ -420,24 +421,24 @@ identify_txt_header(uint8 *data, int32 nread,
|
|||||||
nread += readlater;
|
nread += readlater;
|
||||||
for (int32 i = 0; i < nread; i++) {
|
for (int32 i = 0; i < nread; i++) {
|
||||||
ch = data[i];
|
ch = data[i];
|
||||||
// if any null characters or
|
// if any null characters or control characters
|
||||||
// control characters (other than a few)
|
// are found, reduce our ability to handle the data
|
||||||
// are found, abort, as the data is
|
|
||||||
// probably not plain text
|
|
||||||
if (ch < 0x20 &&
|
if (ch < 0x20 &&
|
||||||
ch != 0x08 && // backspace
|
ch != 0x08 && // backspace
|
||||||
ch != 0x09 && // tab
|
ch != 0x09 && // tab
|
||||||
ch != 0x0A && // line feed
|
ch != 0x0A && // line feed
|
||||||
ch != 0x0C && // form feed
|
ch != 0x0C && // form feed
|
||||||
ch != 0x0D) // carriage return
|
ch != 0x0D) { // carriage return
|
||||||
return B_NO_TRANSLATOR;
|
capability *= 0.6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return information about the data in the stream
|
// return information about the data in the stream
|
||||||
outInfo->type = B_TRANSLATOR_TEXT;
|
outInfo->type = B_TRANSLATOR_TEXT;
|
||||||
outInfo->group = B_TRANSLATOR_TEXT;
|
outInfo->group = B_TRANSLATOR_TEXT;
|
||||||
outInfo->quality = TEXT_IN_QUALITY;
|
outInfo->quality = TEXT_IN_QUALITY;
|
||||||
outInfo->capability = TEXT_IN_CAPABILITY;
|
outInfo->capability = capability;
|
||||||
strcpy(outInfo->name, "Plain text file");
|
strcpy(outInfo->name, "Plain text file");
|
||||||
strcpy(outInfo->MIME, "text/plain");
|
strcpy(outInfo->MIME, "text/plain");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user