Skip to content

Commit

Permalink
ByteString->rtl::OString
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolán McNamara committed Jan 30, 2012
1 parent 74ded8e commit 89dc836
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 66 deletions.
31 changes: 17 additions & 14 deletions basic/source/inc/iosys.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand All @@ -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;
Expand Down
96 changes: 48 additions & 48 deletions basic/source/runtime/iosys.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() )
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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() );
Expand All @@ -714,33 +712,34 @@ namespace
}
}

SbError SbiStream::Write( const ByteString& rBuf, sal_uInt16 n )
SbError SbiStream::Write( const rtl::OString& rBuf, sal_uInt16 n )
{
ExpandFile();
if( IsAppend() )
pStrm->Seek( STREAM_SEEK_TO_END );

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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -824,21 +822,21 @@ 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();
#else
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 );
Expand All @@ -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;
Expand All @@ -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 );
Expand Down Expand Up @@ -921,35 +919,37 @@ void SbiIoSystem::CloseAll(void)
***************************************************************************/


void SbiIoSystem::ReadCon( ByteString& rIn )
void SbiIoSystem::ReadCon(rtl::OString& rIn)
{
String aPromptStr( aPrompt, osl_getThreadTextEncoding() );
SbiInputDialog aDlg( NULL, aPromptStr );
if( aDlg.Execute() )
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 )
{
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() );
sal_Int32 n1 = aOut.indexOf('\n');
sal_Int32 n2 = aOut.indexOf('\r');
if( n1 != -1 || n2 != -1 )
{
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(),
Expand Down
4 changes: 2 additions & 2 deletions basic/source/runtime/methods1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,7 @@ RTLFUNC(Input)
return;
}

ByteString aByteBuffer;
rtl::OString aByteBuffer;
SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true );
if( !err )
err = pIosys->GetError();
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions basic/source/runtime/step0.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89dc836

Please sign in to comment.