Public Member Functions | Protected Attributes | Private Member Functions | List of all members
QStringBuffer Class Reference
Inheritance diagram for QStringBuffer:
QIODevice

Public Member Functions

 QStringBuffer (QString *str)
 
 ~QStringBuffer ()
 
bool open (int m)
 
void close ()
 
void flush ()
 
uint size () const
 
int at () const
 
bool at (int pos)
 
int readBlock (char *p, uint len)
 
int writeBlock (const char *p, uint len)
 
int getch ()
 
int putch (int ch)
 
int ungetch (int ch)
 
- Public Member Functions inherited from QIODevice
 QIODevice ()
 
virtual ~QIODevice ()
 
int flags () const
 
int mode () const
 
int state () const
 
bool isDirectAccess () const
 
bool isSequentialAccess () const
 
bool isCombinedAccess () const
 
bool isBuffered () const
 
bool isRaw () const
 
bool isSynchronous () const
 
bool isAsynchronous () const
 
bool isTranslated () const
 
bool isReadable () const
 
bool isWritable () const
 
bool isReadWrite () const
 
bool isInactive () const
 
bool isOpen () const
 
int status () const
 
void resetStatus ()
 
virtual bool atEnd () const
 
bool reset ()
 
virtual int readLine (char *data, uint maxlen)
 
int writeBlock (const QByteArray &data)
 
QByteArray readAll ()
 

Protected Attributes

QStrings
 
- Protected Attributes inherited from QIODevice
int ioIndex
 

Private Member Functions

 QStringBuffer (const QStringBuffer &)
 
QStringBufferoperator= (const QStringBuffer &)
 

Additional Inherited Members

- Protected Member Functions inherited from QIODevice
void setFlags (int f)
 
void setType (int)
 
void setMode (int)
 
void setState (int)
 
void setStatus (int)
 

Detailed Description

Definition at line 258 of file qtextstream.cpp.

Constructor & Destructor Documentation

QStringBuffer::QStringBuffer ( QString str)

Definition at line 282 of file qtextstream.cpp.

283 {
284  s = str;
285 }
static QCString str
QStringBuffer::~QStringBuffer ( )

Definition at line 287 of file qtextstream.cpp.

288 {
289 }
QStringBuffer::QStringBuffer ( const QStringBuffer )
private

Member Function Documentation

int QStringBuffer::at ( ) const
virtual

Virtual function that returns the current I/O device index.

This index is the data read/write head of the I/O device.

See also
size()

Reimplemented from QIODevice.

Definition at line 337 of file qtextstream.cpp.

338 {
339  return ioIndex;
340 }
int ioIndex
Definition: qiodevice.h:141
bool QStringBuffer::at ( int  pos)
virtual

Virtual function that sets the I/O device index to pos.

See also
size()

Reimplemented from QIODevice.

Definition at line 342 of file qtextstream.cpp.

343 {
344 #if defined(CHECK_STATE)
345  if ( !isOpen() ) {
346  qWarning( "QStringBuffer::at: Buffer is not open" );
347  return FALSE;
348  }
349 #endif
350  if ( (uint)pos >= s->length()*2 ) {
351 #if defined(CHECK_RANGE)
352  qWarning( "QStringBuffer::at: Index %d out of range", pos );
353 #endif
354  return FALSE;
355  }
356  ioIndex = pos;
357  return TRUE;
358 }
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
uint length() const
Definition: qstring.h:679
bool isOpen() const
Definition: qiodevice.h:110
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
int ioIndex
Definition: qiodevice.h:141
void QStringBuffer::close ( )
virtual

Closes the I/O device.

This virtual function must be reimplemented by all subclasses.

See also
open()

Implements QIODevice.

Definition at line 320 of file qtextstream.cpp.

321 {
322  if ( isOpen() ) {
323  setFlags( IO_Direct );
324  ioIndex = 0;
325  }
326 }
void setFlags(int f)
Definition: qiodevice.h:136
#define IO_Direct
Definition: qiodevice.h:49
bool isOpen() const
Definition: qiodevice.h:110
int ioIndex
Definition: qiodevice.h:141
void QStringBuffer::flush ( )
virtual

Flushes an open I/O device.

This virtual function must be reimplemented by all subclasses.

Implements QIODevice.

Definition at line 328 of file qtextstream.cpp.

329 {
330 }
int QStringBuffer::getch ( )
virtual

Reads a single byte/character from the I/O device.

Returns the byte/character read, or -1 if the end of the I/O device has been reached.

This virtual function must be reimplemented by all subclasses.

See also
putch(), ungetch()

Implements QIODevice.

Definition at line 417 of file qtextstream.cpp.

418 {
419 #if defined(CHECK_STATE)
420  if ( !isOpen() ) { // buffer not open
421  qWarning( "QStringBuffer::getch: Buffer not open" );
422  return -1;
423  }
424  if ( !isReadable() ) { // reading not permitted
425  qWarning( "QStringBuffer::getch: Read operation not permitted" );
426  return -1;
427  }
428 #endif
429  if ( (uint)ioIndex >= s->length()*2 ) { // overflow
431  return -1;
432  }
433  return *((char*)s->unicode() + ioIndex++);
434 }
const QChar * unicode() const
Definition: qstring.h:508
#define IO_ReadError
Definition: qiodevice.h:78
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
void setStatus(int)
Definition: qiodevice.cpp:408
bool isReadable() const
Definition: qiodevice.h:106
uint length() const
Definition: qstring.h:679
bool isOpen() const
Definition: qiodevice.h:110
unsigned uint
Definition: qglobal.h:351
int ioIndex
Definition: qiodevice.h:141
bool QStringBuffer::open ( int  mode)
virtual

Opens the I/O device using the specified mode. Returns TRUE if successful, or FALSE if the device could not be opened.

The mode parameter m must be a combination of the following flags.

  • IO_Raw specified raw (unbuffered) file access.
  • IO_ReadOnly opens a file in read-only mode.
  • IO_WriteOnly opens a file in write-only mode.
  • IO_ReadWrite opens a file in read/write mode.
  • IO_Append sets the file index to the end of the file.
  • IO_Truncate truncates the file.
  • IO_Translate enables carriage returns and linefeed translation for text files under MS-DOS, Window, OS/2 and Macintosh. On Unix systems this flag has no effect. Use with caution as it will also transform every linefeed written to the file into a CRLF pair. This is likely to corrupt your file when writing binary data to it. Cannot be combined with IO_Raw.

This virtual function must be reimplemented by all subclasses.

See also
close()

Implements QIODevice.

Definition at line 292 of file qtextstream.cpp.

293 {
294  if ( !s ) {
295 #if defined(CHECK_STATE)
296  qWarning( "QStringBuffer::open: No string" );
297 #endif
298  return FALSE;
299  }
300  if ( isOpen() ) { // buffer already open
301 #if defined(CHECK_STATE)
302  qWarning( "QStringBuffer::open: Buffer already open" );
303 #endif
304  return FALSE;
305  }
306  setMode( m );
307  if ( m & IO_Truncate ) { // truncate buffer
308  s->truncate( 0 );
309  }
310  if ( m & IO_Append ) { // append to end of buffer
311  ioIndex = s->length()*(int)sizeof(QChar);
312  } else {
313  ioIndex = 0;
314  }
315  setState( IO_Open );
316  setStatus( 0 );
317  return TRUE;
318 }
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
void setMode(int)
Definition: qiodevice.cpp:378
void setStatus(int)
Definition: qiodevice.cpp:408
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
#define IO_Truncate
Definition: qiodevice.h:65
#define IO_Append
Definition: qiodevice.h:64
void setState(int)
Definition: qiodevice.cpp:393
void truncate(uint pos)
Definition: qstring.cpp:12490
bool isOpen() const
Definition: qiodevice.h:110
#define IO_Open
Definition: qiodevice.h:71
const bool TRUE
Definition: qglobal.h:371
int ioIndex
Definition: qiodevice.h:141
QStringBuffer& QStringBuffer::operator= ( const QStringBuffer )
private
int QStringBuffer::putch ( int  ch)
virtual

Writes the character ch to the I/O device.

Returns ch, or -1 if some error occurred.

This virtual function must be reimplemented by all subclasses.

See also
getch(), ungetch()

Implements QIODevice.

Definition at line 436 of file qtextstream.cpp.

437 {
438  char c = ch;
439  if ( writeBlock(&c,1) < 0 )
440  return -1;
441  else
442  return ch;
443 }
int writeBlock(const char *p, uint len)
int QStringBuffer::readBlock ( char *  data,
uint  maxlen 
)
virtual

Reads at most maxlen bytes from the I/O device into data and returns the number of bytes actually read.

This virtual function must be reimplemented by all subclasses.

See also
writeBlock()

Implements QIODevice.

Definition at line 361 of file qtextstream.cpp.

362 {
363 #if defined(CHECK_STATE)
364  CHECK_PTR( p );
365  if ( !isOpen() ) { // buffer not open
366  qWarning( "QStringBuffer::readBlock: Buffer not open" );
367  return -1;
368  }
369  if ( !isReadable() ) { // reading not permitted
370  qWarning( "QStringBuffer::readBlock: Read operation not permitted" );
371  return -1;
372  }
373 #endif
374  if ( (uint)ioIndex + len > s->length()*sizeof(QChar) ) {
375  // overflow
376  if ( (uint)ioIndex >= s->length()*sizeof(QChar) ) {
378  return -1;
379  } else {
380  len = s->length()*2 - (uint)ioIndex;
381  }
382  }
383  memcpy( p, ((const char*)(s->unicode()))+ioIndex, len );
384  ioIndex += len;
385  return len;
386 }
const QChar * unicode() const
Definition: qstring.h:508
#define IO_ReadError
Definition: qiodevice.h:78
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
void setStatus(int)
Definition: qiodevice.cpp:408
bool isReadable() const
Definition: qiodevice.h:106
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
#define CHECK_PTR(p)
Definition: qglobal.h:601
bool isOpen() const
Definition: qiodevice.h:110
unsigned uint
Definition: qglobal.h:351
int ioIndex
Definition: qiodevice.h:141
uint QStringBuffer::size ( ) const
virtual

Virtual function that returns the size of the I/O device.

See also
at()

Implements QIODevice.

Definition at line 332 of file qtextstream.cpp.

333 {
334  return s ? s->length()*(int)sizeof(QChar) : 0;
335 }
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uint length() const
Definition: qstring.h:679
int QStringBuffer::ungetch ( int  ch)
virtual

Puts the character ch back into the I/O device and decrements the index if it is not zero.

This function is normally called to "undo" a getch() operation.

Returns ch, or -1 if some error occurred.

This virtual function must be reimplemented by all subclasses.

See also
getch(), putch()

Implements QIODevice.

Definition at line 445 of file qtextstream.cpp.

446 {
447 #if defined(CHECK_STATE)
448  if ( !isOpen() ) { // buffer not open
449  qWarning( "QStringBuffer::ungetch: Buffer not open" );
450  return -1;
451  }
452  if ( !isReadable() ) { // reading not permitted
453  qWarning( "QStringBuffer::ungetch: Read operation not permitted" );
454  return -1;
455  }
456 #endif
457  if ( ch != -1 ) { // something to do with eof
458  if ( ioIndex )
459  ioIndex--;
460  else
461  ch = -1;
462  }
463  return ch;
464 }
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
bool isReadable() const
Definition: qiodevice.h:106
bool isOpen() const
Definition: qiodevice.h:110
int ioIndex
Definition: qiodevice.h:141
int QStringBuffer::writeBlock ( const char *  data,
uint  len 
)
virtual

Writes len bytes from p to the I/O device and returns the number of bytes actually written.

This virtual function must be reimplemented by all subclasses.

See also
readBlock()

Implements QIODevice.

Definition at line 388 of file qtextstream.cpp.

389 {
390 #if defined(CHECK_NULL)
391  if ( p == 0 && len != 0 )
392  qWarning( "QStringBuffer::writeBlock: Null pointer error" );
393 #endif
394 #if defined(CHECK_STATE)
395  if ( !isOpen() ) { // buffer not open
396  qWarning( "QStringBuffer::writeBlock: Buffer not open" );
397  return -1;
398  }
399  if ( !isWritable() ) { // writing not permitted
400  qWarning( "QStringBuffer::writeBlock: Write operation not permitted" );
401  return -1;
402  }
403  if ( ioIndex&1 ) {
404  qWarning( "QStringBuffer::writeBlock: non-even index - non Unicode" );
405  return -1;
406  }
407  if ( len&1 ) {
408  qWarning( "QStringBuffer::writeBlock: non-even length - non Unicode" );
409  return -1;
410  }
411 #endif
412  s->replace(ioIndex/2, len/2, (QChar*)p, len/2);
413  ioIndex += len;
414  return len;
415 }
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
bool isWritable() const
Definition: qiodevice.h:107
p
Definition: test.py:223
QString & replace(uint index, uint len, const QString &)
Definition: qstring.cpp:13665
bool isOpen() const
Definition: qiodevice.h:110
int ioIndex
Definition: qiodevice.h:141

Member Data Documentation

QString* QStringBuffer::s
protected

Definition at line 274 of file qtextstream.cpp.


The documentation for this class was generated from the following file: