Kaydet (Commit) 89dc8369 authored tarafından Caolán McNamara's avatar Caolán McNamara

ByteString->rtl::OString

üst 74ded8e6
...@@ -45,10 +45,11 @@ class SvStream; ...@@ -45,10 +45,11 @@ class SvStream;
#define SBSTRM_APPEND 0x0008 #define SBSTRM_APPEND 0x0008
#define SBSTRM_BINARY 0x0010 #define SBSTRM_BINARY 0x0010
class SbiStream { class SbiStream
{
SvStream* pStrm; SvStream* pStrm;
sal_uIntPtr nExpandOnWriteTo; // during writing access expand the stream to this size sal_uIntPtr nExpandOnWriteTo; // during writing access expand the stream to this size
ByteString aLine; rtl::OString aLine;
sal_uIntPtr nLine; sal_uIntPtr nLine;
short nLen; // buffer length short nLen; // buffer length
short nMode; short nMode;
...@@ -59,11 +60,11 @@ class SbiStream { ...@@ -59,11 +60,11 @@ class SbiStream {
public: public:
SbiStream(); SbiStream();
~SbiStream(); ~SbiStream();
SbError Open( short, const ByteString&, short, short, short ); SbError Open( short, const rtl::OString&, short, short, short );
SbError Close(); 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 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 IsText() const { return (nMode & SBSTRM_BINARY) == 0; }
bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; } bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; }
...@@ -78,28 +79,30 @@ public: ...@@ -78,28 +79,30 @@ public:
SvStream* GetStrm() { return pStrm; } SvStream* GetStrm() { return pStrm; }
}; };
class SbiIoSystem { class SbiIoSystem
{
SbiStream* pChan[ CHANNELS ]; SbiStream* pChan[ CHANNELS ];
ByteString aPrompt; rtl::OString aPrompt;
ByteString aIn, aOut; rtl::OString aIn;
rtl::OString aOut;
short nChan; short nChan;
SbError nError; SbError nError;
void ReadCon( ByteString& ); void ReadCon(rtl::OString&);
void WriteCon( const ByteString& ); void WriteCon(const rtl::OString&);
public: public:
SbiIoSystem(); SbiIoSystem();
~SbiIoSystem(); ~SbiIoSystem();
SbError GetError(); SbError GetError();
void Shutdown(); void Shutdown();
void SetPrompt( const ByteString& r ) { aPrompt = r; } void SetPrompt(const rtl::OString& r) { aPrompt = r; }
void SetChannel( short n ) { nChan = n; } void SetChannel( short n ) { nChan = n; }
short GetChannel() const { return nChan;} short GetChannel() const { return nChan;}
void ResetChannel() { nChan = 0; } void ResetChannel() { nChan = 0; }
void Open( short, const ByteString&, short, short, short ); void Open( short, const rtl::OString&, short, short, short );
void Close(); void Close();
void Read( ByteString&, short = 0 ); void Read(rtl::OString&, short = 0);
char Read(); char Read();
void Write( const ByteString&, short = 0 ); void Write(const rtl::OString&, short = 0);
short NextChannel(); short NextChannel();
// 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1) // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1)
SbiStream* GetStream( short nChannel ) const; SbiStream* GetStream( short nChannel ) const;
......
...@@ -562,7 +562,7 @@ void UCBStream::SetSize( sal_uIntPtr nSize ) ...@@ -562,7 +562,7 @@ void UCBStream::SetSize( sal_uIntPtr nSize )
SbError SbiStream::Open 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; nMode = nFlags;
nLen = nL; nLen = nL;
...@@ -571,7 +571,7 @@ SbError SbiStream::Open ...@@ -571,7 +571,7 @@ SbError SbiStream::Open
nExpandOnWriteTo = 0; nExpandOnWriteTo = 0;
if( ( nStrmMode & ( STREAM_READ|STREAM_WRITE ) ) == STREAM_READ ) if( ( nStrmMode & ( STREAM_READ|STREAM_WRITE ) ) == STREAM_READ )
nStrmMode |= STREAM_NOCREATE; nStrmMode |= STREAM_NOCREATE;
String aStr( rName, osl_getThreadTextEncoding() ); String aStr(rtl::OStringToOUString(rName, osl_getThreadTextEncoding()));
String aNameStr = getFullPath( aStr ); String aNameStr = getFullPath( aStr );
if( hasUno() ) if( hasUno() )
...@@ -642,14 +642,12 @@ SbError SbiStream::Close() ...@@ -642,14 +642,12 @@ SbError SbiStream::Close()
return nError; 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; nExpandOnWriteTo = 0;
if( !bForceReadingPerByte && IsText() ) if( !bForceReadingPerByte && IsText() )
{ {
rtl::OString aBuffer; pStrm->ReadLine(rBuf);
pStrm->ReadLine(aBuffer);
rBuf = aBuffer;
nLine++; nLine++;
} }
else else
...@@ -673,13 +671,13 @@ SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerBy ...@@ -673,13 +671,13 @@ SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerBy
SbError SbiStream::Read( char& ch ) SbError SbiStream::Read( char& ch )
{ {
nExpandOnWriteTo = 0; nExpandOnWriteTo = 0;
if( !aLine.Len() ) if (aLine.isEmpty())
{ {
Read( aLine, 0 ); Read( aLine, 0 );
aLine += '\n'; aLine = aLine + rtl::OString('\n');
} }
ch = aLine.GetBuffer()[0]; ch = aLine[0];
aLine.Erase( 0, 1 ); aLine = aLine.copy(1);
return nError; return nError;
} }
...@@ -705,7 +703,7 @@ void SbiStream::ExpandFile() ...@@ -705,7 +703,7 @@ void SbiStream::ExpandFile()
namespace namespace
{ {
void WriteLines(SvStream &rStream, const ByteString& rStr) void WriteLines(SvStream &rStream, const rtl::OString& rStr)
{ {
ByteString aStr( rStr ); ByteString aStr( rStr );
aStr.ConvertLineEnd( rStream.GetLineDelimiter() ); aStr.ConvertLineEnd( rStream.GetLineDelimiter() );
...@@ -714,7 +712,7 @@ namespace ...@@ -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(); ExpandFile();
if( IsAppend() ) if( IsAppend() )
...@@ -722,25 +720,26 @@ SbError SbiStream::Write( const ByteString& rBuf, sal_uInt16 n ) ...@@ -722,25 +720,26 @@ SbError SbiStream::Write( const ByteString& rBuf, sal_uInt16 n )
if( IsText() ) if( IsText() )
{ {
aLine += rBuf; aLine = aLine + rBuf;
// Get it out, if the end is an LF, but strip CRLF before, // Get it out, if the end is an LF, but strip CRLF before,
// because the SvStrm adds a CRLF! // because the SvStrm adds a CRLF!
sal_uInt16 nLineLen = aLine.Len(); sal_Int32 nLineLen = aLine.getLength();
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0A ) if (nLineLen && aLine[--nLineLen] == 0x0A)
{ {
aLine.Erase( nLineLen ); aLine = aLine.copy(0, nLineLen);
if( nLineLen && aLine.GetBuffer()[ --nLineLen ] == 0x0D ) if (nLineLen && aLine[--nLineLen] == 0x0D)
aLine.Erase( nLineLen ); aLine = aLine.copy(0, nLineLen);
WriteLines(*pStrm, aLine); WriteLines(*pStrm, aLine);
aLine.Erase(); aLine = rtl::OString();
} }
} }
else else
{ {
if( !n ) n = nLen; if( !n )
n = nLen;
if( !n ) if( !n )
return nError = SbERR_BAD_RECORD_LENGTH; return nError = SbERR_BAD_RECORD_LENGTH;
pStrm->Write( rBuf.GetBuffer(), n ); pStrm->Write(rBuf.getStr(), n);
MapError(); MapError();
} }
return nError; return nError;
...@@ -774,8 +773,7 @@ SbError SbiIoSystem::GetError() ...@@ -774,8 +773,7 @@ SbError SbiIoSystem::GetError()
return n; return n;
} }
void SbiIoSystem::Open void SbiIoSystem::Open(short nCh, const rtl::OString& rName, short nMode, short nFlags, short nLen)
( short nCh, const ByteString& rName, short nMode, short nFlags, short nLen )
{ {
nError = 0; nError = 0;
if( nCh >= CHANNELS || !nCh ) if( nCh >= CHANNELS || !nCh )
...@@ -824,9 +822,9 @@ void SbiIoSystem::Shutdown() ...@@ -824,9 +822,9 @@ void SbiIoSystem::Shutdown()
} }
nChan = 0; nChan = 0;
// anything left to PRINT? // 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 #if defined GCC
Window* pParent = Application::GetDefDialogParent(); Window* pParent = Application::GetDefDialogParent();
MessBox( pParent, WinBits( WB_OK ), String(), aOutStr ).Execute(); MessBox( pParent, WinBits( WB_OK ), String(), aOutStr ).Execute();
...@@ -834,11 +832,11 @@ void SbiIoSystem::Shutdown() ...@@ -834,11 +832,11 @@ void SbiIoSystem::Shutdown()
MessBox( GetpApp()->GetDefDialogParent(), WinBits( WB_OK ), String(), aOutStr ).Execute(); MessBox( GetpApp()->GetDefDialogParent(), WinBits( WB_OK ), String(), aOutStr ).Execute();
#endif #endif
} }
aOut.Erase(); aOut = rtl::OString();
} }
void SbiIoSystem::Read( ByteString& rBuf, short n ) void SbiIoSystem::Read(rtl::OString& rBuf, short n)
{ {
if( !nChan ) if( !nChan )
ReadCon( rBuf ); ReadCon( rBuf );
...@@ -853,13 +851,13 @@ char SbiIoSystem::Read() ...@@ -853,13 +851,13 @@ char SbiIoSystem::Read()
char ch = ' '; char ch = ' ';
if( !nChan ) if( !nChan )
{ {
if( !aIn.Len() ) if( aIn.isEmpty() )
{ {
ReadCon( aIn ); ReadCon( aIn );
aIn += '\n'; aIn = aIn + rtl::OString('\n');
} }
ch = aIn.GetBuffer()[0]; ch = aIn[0];
aIn.Erase( 0, 1 ); aIn = aIn.copy(1);
} }
else if( !pChan[ nChan ] ) else if( !pChan[ nChan ] )
nError = SbERR_BAD_CHANNEL; nError = SbERR_BAD_CHANNEL;
...@@ -868,7 +866,7 @@ char SbiIoSystem::Read() ...@@ -868,7 +866,7 @@ char SbiIoSystem::Read()
return ch; return ch;
} }
void SbiIoSystem::Write( const ByteString& rBuf, short n ) void SbiIoSystem::Write(const rtl::OString& rBuf, short n)
{ {
if( !nChan ) if( !nChan )
WriteCon( rBuf ); WriteCon( rBuf );
...@@ -921,7 +919,7 @@ void SbiIoSystem::CloseAll(void) ...@@ -921,7 +919,7 @@ void SbiIoSystem::CloseAll(void)
***************************************************************************/ ***************************************************************************/
void SbiIoSystem::ReadCon( ByteString& rIn ) void SbiIoSystem::ReadCon(rtl::OString& rIn)
{ {
String aPromptStr( aPrompt, osl_getThreadTextEncoding() ); String aPromptStr( aPrompt, osl_getThreadTextEncoding() );
SbiInputDialog aDlg( NULL, aPromptStr ); SbiInputDialog aDlg( NULL, aPromptStr );
...@@ -929,27 +927,29 @@ void SbiIoSystem::ReadCon( ByteString& rIn ) ...@@ -929,27 +927,29 @@ void SbiIoSystem::ReadCon( ByteString& rIn )
rIn = rtl::OUStringToOString(aDlg.GetInput(), osl_getThreadTextEncoding()); rIn = rtl::OUStringToOString(aDlg.GetInput(), osl_getThreadTextEncoding());
else else
nError = SbERR_USER_ABORT; nError = SbERR_USER_ABORT;
aPrompt.Erase(); aPrompt = rtl::OString();
} }
// output of a MessageBox, if theres a CR in the console-buffer // 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; aOut += rText;
sal_uInt16 n1 = aOut.Search( '\n' ); sal_Int32 n1 = aOut.indexOf('\n');
sal_uInt16 n2 = aOut.Search( '\r' ); sal_Int32 n2 = aOut.indexOf('\r');
if( n1 != STRING_NOTFOUND || n2 != STRING_NOTFOUND ) if( n1 != -1 || n2 != -1 )
{ {
if( n1 == STRING_NOTFOUND ) n1 = n2; if( n1 == -1 )
else n1 = n2;
if( n2 == STRING_NOTFOUND ) n2 = n1; else if( n2 == -1 )
if( n1 > n2 ) n1 = n2; n2 = n1;
ByteString s( aOut.Copy( 0, n1 ) ); if( n1 > n2 )
aOut.Erase( 0, n1 ); n1 = n2;
while( aOut.GetBuffer()[0] == '\n' || aOut.GetBuffer()[0] == '\r' ) rtl::OString s(aOut.copy(0, n1));
aOut.Erase( 0, 1 ); aOut = aOut.copy(n1);
String aStr( s, osl_getThreadTextEncoding() ); while (aOut[0] == '\n' || aOut[0] == '\r')
aOut = aOut.copy(1);
String aStr(rtl::OStringToOUString(s, osl_getThreadTextEncoding()));
{ {
SolarMutexGuard aSolarGuard; SolarMutexGuard aSolarGuard;
if( !MessBox( GetpApp()->GetDefDialogParent(), if( !MessBox( GetpApp()->GetDefDialogParent(),
......
...@@ -3209,7 +3209,7 @@ RTLFUNC(Input) ...@@ -3209,7 +3209,7 @@ RTLFUNC(Input)
return; return;
} }
ByteString aByteBuffer; rtl::OString aByteBuffer;
SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true ); SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true );
if( !err ) if( !err )
err = pIosys->GetError(); err = pIosys->GetError();
...@@ -3219,7 +3219,7 @@ RTLFUNC(Input) ...@@ -3219,7 +3219,7 @@ RTLFUNC(Input)
StarBASIC::Error( err ); StarBASIC::Error( err );
return; return;
} }
rPar.Get(0)->PutString( String( aByteBuffer, osl_getThreadTextEncoding() ) ); rPar.Get(0)->PutString(rtl::OStringToOUString(aByteBuffer, osl_getThreadTextEncoding()));
} }
RTLFUNC(Me) RTLFUNC(Me)
......
...@@ -1175,11 +1175,11 @@ void SbiRuntime::StepINPUT() ...@@ -1175,11 +1175,11 @@ void SbiRuntime::StepINPUT()
void SbiRuntime::StepLINPUT() void SbiRuntime::StepLINPUT()
{ {
ByteString aInput; rtl::OString aInput;
pIosys->Read( aInput ); pIosys->Read( aInput );
Error( pIosys->GetError() ); Error( pIosys->GetError() );
SbxVariableRef p = PopVar(); SbxVariableRef p = PopVar();
p->PutString( String( aInput, osl_getThreadTextEncoding() ) ); p->PutString(rtl::OStringToOUString(aInput, osl_getThreadTextEncoding()));
} }
// end of program // end of program
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment