ByteString->rtl::OString

This commit is contained in:
Caolán McNamara 2012-01-27 20:27:18 +00:00
parent 74ded8e619
commit 89dc836918
4 changed files with 68 additions and 65 deletions

View file

@ -45,10 +45,11 @@ class SvStream;
#define SBSTRM_APPEND 0x0008
#define SBSTRM_BINARY 0x0010
class SbiStream {
class SbiStream
{
SvStream* pStrm;
sal_uIntPtr nExpandOnWriteTo; // during writing access expand the stream to this size
ByteString aLine;
rtl::OString aLine;
sal_uIntPtr nLine;
short nLen; // buffer length
short nMode;
@ -59,11 +60,11 @@ class SbiStream {
public:
SbiStream();
~SbiStream();
SbError Open( short, const ByteString&, short, short, short );
SbError Open( short, const rtl::OString&, short, short, short );
SbError Close();
SbError Read( ByteString&, sal_uInt16 = 0, bool bForceReadingPerByte=false );
SbError Read(rtl::OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
SbError Read( char& );
SbError Write( const ByteString&, sal_uInt16 = 0 );
SbError Write( const rtl::OString&, sal_uInt16 = 0 );
bool IsText() const { return (nMode & SBSTRM_BINARY) == 0; }
bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; }
@ -78,28 +79,30 @@ public:
SvStream* GetStrm() { return pStrm; }
};
class SbiIoSystem {
class SbiIoSystem
{
SbiStream* pChan[ CHANNELS ];
ByteString aPrompt;
ByteString aIn, aOut;
rtl::OString aPrompt;
rtl::OString aIn;
rtl::OString aOut;
short nChan;
SbError nError;
void ReadCon( ByteString& );
void WriteCon( const ByteString& );
void ReadCon(rtl::OString&);
void WriteCon(const rtl::OString&);
public:
SbiIoSystem();
~SbiIoSystem();
SbError GetError();
void Shutdown();
void SetPrompt( const ByteString& r ) { aPrompt = r; }
void SetPrompt(const rtl::OString& r) { aPrompt = r; }
void SetChannel( short n ) { nChan = n; }
short GetChannel() const { return nChan;}
void ResetChannel() { nChan = 0; }
void Open( short, const ByteString&, short, short, short );
void Open( short, const rtl::OString&, short, short, short );
void Close();
void Read( ByteString&, short = 0 );
void Read(rtl::OString&, short = 0);
char Read();
void Write( const ByteString&, short = 0 );
void Write(const rtl::OString&, short = 0);
short NextChannel();
// 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
SbiStream* GetStream( short nChannel ) const;

View file

@ -562,7 +562,7 @@ void UCBStream::SetSize( sal_uIntPtr nSize )
SbError SbiStream::Open
( short nCh, const ByteString& rName, short nStrmMode, short nFlags, short nL )
( short nCh, const rtl::OString& rName, short nStrmMode, short nFlags, short nL )
{
nMode = nFlags;
nLen = nL;
@ -571,7 +571,7 @@ SbError SbiStream::Open
nExpandOnWriteTo = 0;
if( ( nStrmMode & ( STREAM_READ|STREAM_WRITE ) ) == STREAM_READ )
nStrmMode |= STREAM_NOCREATE;
String aStr( rName, osl_getThreadTextEncoding() );
String aStr(rtl::OStringToOUString(rName, osl_getThreadTextEncoding()));
String aNameStr = getFullPath( aStr );
if( hasUno() )
@ -642,14 +642,12 @@ SbError SbiStream::Close()
return nError;
}
SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerByte )
SbError SbiStream::Read(rtl::OString& rBuf, sal_uInt16 n, bool bForceReadingPerByte)
{
nExpandOnWriteTo = 0;
if( !bForceReadingPerByte && IsText() )
{
rtl::OString aBuffer;
pStrm->ReadLine(aBuffer);
rBuf = aBuffer;
pStrm->ReadLine(rBuf);
nLine++;
}
else
@ -673,13 +671,13 @@ SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerBy
SbError SbiStream::Read( char& ch )
{
nExpandOnWriteTo = 0;
if( !aLine.Len() )
if (aLine.isEmpty())
{
Read( aLine, 0 );
aLine += '\n';
aLine = aLine + rtl::OString('\n');
}
ch = aLine.GetBuffer()[0];
aLine.Erase( 0, 1 );
ch = aLine[0];
aLine = aLine.copy(1);
return nError;
}
@ -705,7 +703,7 @@ void SbiStream::ExpandFile()
namespace
{
void WriteLines(SvStream &rStream, const ByteString& rStr)
void WriteLines(SvStream &rStream, const rtl::OString& rStr)
{
ByteString aStr( rStr );
aStr.ConvertLineEnd( rStream.GetLineDelimiter() );
@ -714,7 +712,7 @@ namespace
}
}
SbError SbiStream::Write( const ByteString& rBuf, sal_uInt16 n )
SbError SbiStream::Write( const rtl::OString& rBuf, sal_uInt16 n )
{
ExpandFile();
if( IsAppend() )
@ -722,25 +720,26 @@ SbError SbiStream::Write( const ByteString& rBuf, sal_uInt16 n )
if( IsText() )
{
aLine += rBuf;
aLine = aLine + rBuf;
// Get it out, if the end is an LF, but strip CRLF before,
// because the SvStrm adds a CRLF!
sal_uInt16 nLineLen = aLine.Len();
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0A )
sal_Int32 nLineLen = aLine.getLength();
if (nLineLen && aLine[--nLineLen] == 0x0A)
{
aLine.Erase( nLineLen );
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0D )
aLine.Erase( nLineLen );
aLine = aLine.copy(0, nLineLen);
if (nLineLen && aLine[--nLineLen] == 0x0D)
aLine = aLine.copy(0, nLineLen);
WriteLines(*pStrm, aLine);
aLine.Erase();
aLine = rtl::OString();
}
}
else
{
if( !n ) n = nLen;
if( !n )
n = nLen;
if( !n )
return nError = SbERR_BAD_RECORD_LENGTH;
pStrm->Write( rBuf.GetBuffer(), n );
pStrm->Write(rBuf.getStr(), n);
MapError();
}
return nError;
@ -774,8 +773,7 @@ SbError SbiIoSystem::GetError()
return n;
}
void SbiIoSystem::Open
( short nCh, const ByteString& rName, short nMode, short nFlags, short nLen )
void SbiIoSystem::Open(short nCh, const rtl::OString& rName, short nMode, short nFlags, short nLen)
{
nError = 0;
if( nCh >= CHANNELS || !nCh )
@ -824,9 +822,9 @@ void SbiIoSystem::Shutdown()
}
nChan = 0;
// anything left to PRINT?
if( aOut.Len() )
if( !aOut.isEmpty() )
{
String aOutStr( aOut, osl_getThreadTextEncoding() );
rtl::OUString aOutStr(rtl::OStringToOUString(aOut, osl_getThreadTextEncoding()));
#if defined GCC
Window* pParent = Application::GetDefDialogParent();
MessBox( pParent, WinBits( WB_OK ), String(), aOutStr ).Execute();
@ -834,11 +832,11 @@ void SbiIoSystem::Shutdown()
MessBox( GetpApp()->GetDefDialogParent(), WinBits( WB_OK ), String(), aOutStr ).Execute();
#endif
}
aOut.Erase();
aOut = rtl::OString();
}
void SbiIoSystem::Read( ByteString& rBuf, short n )
void SbiIoSystem::Read(rtl::OString& rBuf, short n)
{
if( !nChan )
ReadCon( rBuf );
@ -853,13 +851,13 @@ char SbiIoSystem::Read()
char ch = ' ';
if( !nChan )
{
if( !aIn.Len() )
if( aIn.isEmpty() )
{
ReadCon( aIn );
aIn += '\n';
aIn = aIn + rtl::OString('\n');
}
ch = aIn.GetBuffer()[0];
aIn.Erase( 0, 1 );
ch = aIn[0];
aIn = aIn.copy(1);
}
else if( !pChan[ nChan ] )
nError = SbERR_BAD_CHANNEL;
@ -868,7 +866,7 @@ char SbiIoSystem::Read()
return ch;
}
void SbiIoSystem::Write( const ByteString& rBuf, short n )
void SbiIoSystem::Write(const rtl::OString& rBuf, short n)
{
if( !nChan )
WriteCon( rBuf );
@ -921,7 +919,7 @@ void SbiIoSystem::CloseAll(void)
***************************************************************************/
void SbiIoSystem::ReadCon( ByteString& rIn )
void SbiIoSystem::ReadCon(rtl::OString& rIn)
{
String aPromptStr( aPrompt, osl_getThreadTextEncoding() );
SbiInputDialog aDlg( NULL, aPromptStr );
@ -929,27 +927,29 @@ void SbiIoSystem::ReadCon( ByteString& rIn )
rIn = rtl::OUStringToOString(aDlg.GetInput(), osl_getThreadTextEncoding());
else
nError = SbERR_USER_ABORT;
aPrompt.Erase();
aPrompt = rtl::OString();
}
// output of a MessageBox, if theres a CR in the console-buffer
void SbiIoSystem::WriteCon( const ByteString& rText )
void SbiIoSystem::WriteCon(const rtl::OString& rText)
{
aOut += rText;
sal_uInt16 n1 = aOut.Search( '\n' );
sal_uInt16 n2 = aOut.Search( '\r' );
if( n1 != STRING_NOTFOUND || n2 != STRING_NOTFOUND )
sal_Int32 n1 = aOut.indexOf('\n');
sal_Int32 n2 = aOut.indexOf('\r');
if( n1 != -1 || n2 != -1 )
{
if( n1 == STRING_NOTFOUND ) n1 = n2;
else
if( n2 == STRING_NOTFOUND ) n2 = n1;
if( n1 > n2 ) n1 = n2;
ByteString s( aOut.Copy( 0, n1 ) );
aOut.Erase( 0, n1 );
while( aOut.GetBuffer()[0] == '\n' || aOut.GetBuffer()[0] == '\r' )
aOut.Erase( 0, 1 );
String aStr( s, osl_getThreadTextEncoding() );
if( n1 == -1 )
n1 = n2;
else if( n2 == -1 )
n2 = n1;
if( n1 > n2 )
n1 = n2;
rtl::OString s(aOut.copy(0, n1));
aOut = aOut.copy(n1);
while (aOut[0] == '\n' || aOut[0] == '\r')
aOut = aOut.copy(1);
String aStr(rtl::OStringToOUString(s, osl_getThreadTextEncoding()));
{
SolarMutexGuard aSolarGuard;
if( !MessBox( GetpApp()->GetDefDialogParent(),

View file

@ -3209,7 +3209,7 @@ RTLFUNC(Input)
return;
}
ByteString aByteBuffer;
rtl::OString aByteBuffer;
SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true );
if( !err )
err = pIosys->GetError();
@ -3219,7 +3219,7 @@ RTLFUNC(Input)
StarBASIC::Error( err );
return;
}
rPar.Get(0)->PutString( String( aByteBuffer, osl_getThreadTextEncoding() ) );
rPar.Get(0)->PutString(rtl::OStringToOUString(aByteBuffer, osl_getThreadTextEncoding()));
}
RTLFUNC(Me)

View file

@ -1175,11 +1175,11 @@ void SbiRuntime::StepINPUT()
void SbiRuntime::StepLINPUT()
{
ByteString aInput;
rtl::OString aInput;
pIosys->Read( aInput );
Error( pIosys->GetError() );
SbxVariableRef p = PopVar();
p->PutString( String( aInput, osl_getThreadTextEncoding() ) );
p->PutString(rtl::OStringToOUString(aInput, osl_getThreadTextEncoding()));
}
// end of program