You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
3.7 KiB
189 lines
3.7 KiB
15 years ago
|
/***************************************************************************
|
||
4 years ago
|
mimeio.cpp - description
|
||
15 years ago
|
-------------------
|
||
|
begin : Wed Oct 25 2000
|
||
|
copyright : (C) 2000 by Sven Carstens
|
||
|
email : s.carstens@gmx.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
#include "mimeio.h"
|
||
|
|
||
|
mimeIO::mimeIO ()
|
||
|
{
|
||
|
theCRLF = "\r\n";
|
||
|
crlfLen = 2;
|
||
|
}
|
||
|
|
||
|
mimeIO::~mimeIO ()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int
|
||
15 years ago
|
mimeIO::inputLine (TQCString & aLine)
|
||
15 years ago
|
{
|
||
|
char input;
|
||
|
|
||
|
aLine = (const char *) NULL;
|
||
|
while (inputChar (input))
|
||
|
{
|
||
|
aLine += input;
|
||
|
if (input == '\n')
|
||
|
break;
|
||
|
}
|
||
|
// cout << aLine.length() << " - " << aLine;
|
||
|
return aLine.length ();
|
||
|
}
|
||
|
|
||
|
int
|
||
15 years ago
|
mimeIO::outputLine (const TQCString & aLine, int len)
|
||
15 years ago
|
{
|
||
|
int i;
|
||
|
|
||
|
if (len == -1) {
|
||
|
len = aLine.length();
|
||
|
}
|
||
|
int start = len;
|
||
|
for (i = 0; i < start; i++)
|
||
|
if (!outputChar (aLine[i]))
|
||
|
break;
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
int
|
||
15 years ago
|
mimeIO::outputMimeLine (const TQCString & inLine)
|
||
15 years ago
|
{
|
||
|
int retVal = 0;
|
||
15 years ago
|
TQCString aLine = inLine;
|
||
15 years ago
|
int len = inLine.length();
|
||
|
|
||
14 years ago
|
int theLF = aLine.findRev ('\n');
|
||
15 years ago
|
if (theLF == len - 1 && theLF != -1)
|
||
|
{
|
||
|
//we have a trailing LF, now check for CR
|
||
|
if (aLine[theLF - 1] == '\r')
|
||
|
theLF--;
|
||
|
//truncate the line
|
||
|
aLine.truncate(theLF);
|
||
|
len = theLF;
|
||
|
theLF = -1;
|
||
|
}
|
||
|
//now truncate the line
|
||
|
{
|
||
|
int start, end, offset;
|
||
|
start = 0;
|
||
14 years ago
|
end = aLine.find ('\n', start);
|
||
15 years ago
|
while (end >= 0)
|
||
|
{
|
||
|
offset = 1;
|
||
|
if (end && aLine[end - 1] == '\r')
|
||
|
{
|
||
|
offset++;
|
||
|
end--;
|
||
|
}
|
||
|
outputLine (aLine.mid (start, end - start) + theCRLF, end - start + crlfLen);
|
||
|
start = end + offset;
|
||
14 years ago
|
end = aLine.find ('\n', start);
|
||
15 years ago
|
}
|
||
|
outputLine (aLine.mid (start, len - start) + theCRLF, len - start + crlfLen);
|
||
|
}
|
||
|
return retVal;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
mimeIO::inputChar (char &aChar)
|
||
|
{
|
||
|
if (cin.eof ())
|
||
|
{
|
||
|
// cout << "EOF" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
cin.get (aChar);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
mimeIO::outputChar (char aChar)
|
||
|
{
|
||
|
cout << aChar;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
mimeIO::setCRLF (const char *aCRLF)
|
||
|
{
|
||
|
theCRLF = aCRLF;
|
||
|
crlfLen = strlen(aCRLF);
|
||
|
}
|
||
|
|
||
14 years ago
|
mimeIOTQFile::mimeIOTQFile (const TQString & aName):
|
||
15 years ago
|
mimeIO (),
|
||
|
myFile (aName)
|
||
|
{
|
||
|
myFile.open (IO_ReadOnly);
|
||
|
}
|
||
|
|
||
14 years ago
|
mimeIOTQFile::~mimeIOTQFile ()
|
||
15 years ago
|
{
|
||
|
myFile.close ();
|
||
|
}
|
||
|
|
||
|
int
|
||
14 years ago
|
mimeIOTQFile::outputLine (const TQCString &, int)
|
||
15 years ago
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int
|
||
14 years ago
|
mimeIOTQFile::inputLine (TQCString & data)
|
||
15 years ago
|
{
|
||
|
data.resize( 1024 );
|
||
|
myFile.readLine (data.data(), 1024);
|
||
|
|
||
|
return data.length ();
|
||
|
}
|
||
|
|
||
14 years ago
|
mimeIOTQString::mimeIOTQString ()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
mimeIOTQString::~mimeIOTQString ()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
int
|
||
14 years ago
|
mimeIOTQString::outputLine (const TQCString & _str, int len)
|
||
15 years ago
|
{
|
||
|
if (len == -1) {
|
||
|
len = _str.length();
|
||
|
}
|
||
|
theString += _str;
|
||
|
return len;
|
||
|
}
|
||
|
|
||
|
int
|
||
14 years ago
|
mimeIOTQString::inputLine (TQCString & _str)
|
||
15 years ago
|
{
|
||
|
if (theString.isEmpty ())
|
||
|
return 0;
|
||
|
|
||
14 years ago
|
int i = theString.find ('\n');
|
||
15 years ago
|
|
||
|
if (i == -1)
|
||
|
return 0;
|
||
|
_str = theString.left (i + 1).latin1 ();
|
||
|
theString = theString.right (theString.length () - i - 1);
|
||
|
return _str.length ();
|
||
|
}
|