From 10c557562e1d67c55314c212371ea9cb7f802863 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 19 Jan 2011 23:02:44 +0000 Subject: Started work adding more functions to stream, and changing to a new size type. --- src/client.h | 1 + src/config.h | 2 ++ src/extratypes.h | 17 +++++++++++++++++ src/membuf.cpp | 18 +++++++++--------- src/membuf.h | 17 +++++++++-------- src/stdstream.cpp | 14 +++++++------- src/stdstream.h | 14 +++++++------- src/stream.cpp | 2 +- src/stream.h | 42 +++++++++++++++++++++++++++++++++--------- src/tcpsocket.cpp | 40 ++++++++++++++++++++++++++++------------ src/tcpsocket.h | 23 ++++++++++++++--------- 11 files changed, 128 insertions(+), 62 deletions(-) create mode 100644 src/extratypes.h (limited to 'src') diff --git a/src/client.h b/src/client.h index 096df2f..98b31f7 100644 --- a/src/client.h +++ b/src/client.h @@ -10,6 +10,7 @@ #include +#include "bu/config.h" #include "bu/fstring.h" #include "bu/queuebuf.h" diff --git a/src/config.h b/src/config.h index ad4991e..3a19a1f 100644 --- a/src/config.h +++ b/src/config.h @@ -15,4 +15,6 @@ #include "bu/compat/osx.h" #include "bu/compat/linux.h" +#include "bu/extratypes.h" + #endif diff --git a/src/extratypes.h b/src/extratypes.h new file mode 100644 index 0000000..bc32dcd --- /dev/null +++ b/src/extratypes.h @@ -0,0 +1,17 @@ +#ifndef EXTRA_TYPES_H +#define EXTRA_TYPES_H + +#include "bu/config.h" + +namespace Bu +{ +#ifdef USE_64BIT_IO + typedef int64_t size; + typedef uint64_t usize; +#else + typedef int32_t size; + typedef uint32_t usize; +#endif +}; + +#endif diff --git a/src/membuf.cpp b/src/membuf.cpp index b822641..1a6bf9a 100644 --- a/src/membuf.cpp +++ b/src/membuf.cpp @@ -28,9 +28,9 @@ void Bu::MemBuf::close() { } -size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) +size Bu::MemBuf::read( void *pBuf, size nBytes ) { - if( (size_t)sBuf.getSize()-(size_t)nPos < nBytes ) + if( (size)sBuf.getSize()-(size)nPos < nBytes ) nBytes = sBuf.getSize()-nPos; memcpy( pBuf, sBuf.getStr()+nPos, nBytes ); @@ -39,7 +39,7 @@ size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) return nBytes; } -size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) +size Bu::MemBuf::write( const void *pBuf, size nBytes ) { if( nPos == sBuf.getSize() ) { @@ -52,7 +52,7 @@ size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) { // Trickier, we must do this in two parts, overwrite, then append // Frist, overwrite. - size_t iOver = sBuf.getSize() - nPos; + size iOver = sBuf.getSize() - nPos; if( iOver > nBytes ) iOver = nBytes; memcpy( sBuf.getStr()+nPos, pBuf, iOver ); @@ -66,26 +66,26 @@ size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) } } -long Bu::MemBuf::tell() +size Bu::MemBuf::tell() { return nPos; } -void Bu::MemBuf::seek( long offset ) +void Bu::MemBuf::seek( size offset ) { nPos += offset; if( nPos < 0 ) nPos = 0; else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); } -void Bu::MemBuf::setPos( long pos ) +void Bu::MemBuf::setPos( size pos ) { nPos = pos; if( nPos < 0 ) nPos = 0; else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); } -void Bu::MemBuf::setPosEnd( long pos ) +void Bu::MemBuf::setPosEnd( size pos ) { nPos = sBuf.getSize()-pos; if( nPos < 0 ) nPos = 0; @@ -140,7 +140,7 @@ void Bu::MemBuf::setBlocking( bool ) { } -void Bu::MemBuf::setSize( long iSize ) +void Bu::MemBuf::setSize( size iSize ) { if( iSize < 0 ) iSize = 0; diff --git a/src/membuf.h b/src/membuf.h index 9e406c1..a75aca1 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -10,6 +10,7 @@ #include +#include "bu/config.h" #include "bu/stream.h" #include "bu/fstring.h" @@ -27,14 +28,14 @@ namespace Bu virtual ~MemBuf(); virtual void close(); - virtual size_t read( void *pBuf, size_t nBytes ); + virtual size read( void *pBuf, size iBytes ); - virtual size_t write( const void *pBuf, size_t nBytes ); + virtual size write( const void *pBuf, size iBytes ); using Stream::write; - virtual long tell(); - virtual void seek( long offset ); - virtual void setPos( long pos ); - virtual void setPosEnd( long pos ); + virtual size tell(); + virtual void seek( size offset ); + virtual void setPos( size pos ); + virtual void setPosEnd( size pos ); virtual bool isEos(); virtual bool isOpen(); virtual void flush(); @@ -45,14 +46,14 @@ namespace Bu virtual bool isSeekable(); virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); - virtual void setSize( long iSize ); + virtual void setSize( size iSize ); Bu::FString &getString(); void setString( const Bu::FString &sNewData ); private: Bu::FString sBuf; - long nPos; + size nPos; }; } diff --git a/src/stdstream.cpp b/src/stdstream.cpp index 32ddec4..64ca1cd 100644 --- a/src/stdstream.cpp +++ b/src/stdstream.cpp @@ -20,30 +20,30 @@ void Bu::StdStream::close() { } -size_t Bu::StdStream::read( void *pBuf, size_t nBytes ) +Bu::size Bu::StdStream::read( void *pBuf, Bu::size nBytes ) { return fread( pBuf, 1, nBytes, stdin ); } -size_t Bu::StdStream::write( const void *pBuf, size_t nBytes ) +Bu::size Bu::StdStream::write( const void *pBuf, Bu::size nBytes ) { return fwrite( pBuf, 1, nBytes, stdout ); } -long Bu::StdStream::tell() +Bu::size Bu::StdStream::tell() { return 0; } -void Bu::StdStream::seek( long ) +void Bu::StdStream::seek( Bu::size ) { } -void Bu::StdStream::setPos( long ) +void Bu::StdStream::setPos( Bu::size ) { } -void Bu::StdStream::setPosEnd( long ) +void Bu::StdStream::setPosEnd( Bu::size ) { } @@ -96,7 +96,7 @@ void Bu::StdStream::setBlocking( bool ) { } -void Bu::StdStream::setSize( long ) +void Bu::StdStream::setSize( Bu::size ) { } diff --git a/src/stdstream.h b/src/stdstream.h index 4efeece..c500dfc 100644 --- a/src/stdstream.h +++ b/src/stdstream.h @@ -23,13 +23,13 @@ namespace Bu virtual ~StdStream(); virtual void close(); - virtual size_t read( void *pBuf, size_t nBytes ); - virtual size_t write( const void *pBuf, size_t nBytes ); + virtual size read( void *pBuf, size nBytes ); + virtual size write( const void *pBuf, size nBytes ); using Stream::write; - virtual long tell(); - virtual void seek( long offset ); - virtual void setPos( long pos ); - virtual void setPosEnd( long pos ); + virtual size tell(); + virtual void seek( size offset ); + virtual void setPos( size pos ); + virtual void setPosEnd( size pos ); virtual bool isEos(); virtual bool isOpen(); virtual void flush(); @@ -40,7 +40,7 @@ namespace Bu virtual bool isSeekable(); virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); - virtual void setSize( long iSize ); + virtual void setSize( size iSize ); }; } diff --git a/src/stream.cpp b/src/stream.cpp index 0e05cad..f13d33a 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -30,7 +30,7 @@ Bu::FString Bu::Stream::readLine() } } -size_t Bu::Stream::write( const Bu::FString &sBuf ) +Bu::size Bu::Stream::write( const Bu::FString &sBuf ) { return write( sBuf.getStr(), sBuf.getSize() ); } diff --git a/src/stream.h b/src/stream.h index 0ea5560..e7db7af 100644 --- a/src/stream.h +++ b/src/stream.h @@ -8,6 +8,8 @@ #ifndef BU_STREAM_H #define BU_STREAM_H +#include "bu/config.h" + #include #include @@ -43,7 +45,7 @@ namespace Bu *@param nBytes (size_t) Max data to read. *@returns (size_t) Amount of data read. */ - virtual size_t read( void *pBuf, size_t nBytes ) = 0; + virtual size read( void *pBuf, size iBytes ) = 0; /** * Attempts to read a complete line from the stream. This will stop @@ -59,33 +61,33 @@ namespace Bu *@param nBytes (size_t) Amount of data to write from pBuf. *@returns (size_t) Amount of data actually written. */ - virtual size_t write( const void *pBuf, size_t nBytes ) = 0; + virtual size write( const void *pBuf, size iBytes ) = 0; - virtual size_t write( const Bu::FString &sBuf ); + virtual size write( const Bu::FString &sBuf ); /** * Get the current position in the stream. *@returns (long) The current position in the stream. */ - virtual long tell() = 0; + virtual size tell() = 0; /** * Seek to a position in the stream relative to the current position. *@param offset (long) Offset from current position to seek to. */ - virtual void seek( long offset ) = 0; + virtual void seek( size offset ) = 0; /** * Set position in the stream relative to the start of the stream. *@param pos (long) The position. */ - virtual void setPos( long pos ) = 0; + virtual void setPos( size pos ) = 0; /** * Set position in the stream relative to the end of the stream. *@param pos (long) The position. */ - virtual void setPosEnd( long pos ) = 0; + virtual void setPosEnd( size pos ) = 0; /** * Are we at the end of the stream? @@ -158,10 +160,32 @@ namespace Bu * removed from the end of the stream, but the content of the added * data is undefined. */ - virtual void setSize( long iSize ) = 0; + virtual void setSize( size iSize ) = 0; + + /** + * Returns the size of the stream if the stream can have a size. For + * streams that do not (sockets, pipes, etc.) this should throw an + * unsupported exception. + */ + virtual size getSize() const = 0; - public: // Filters + /** + * Returns the block-size of the stream, if it has one. This should + * throw an unsupported exception. In some cases the block size + * returned will not represent quite the same thing, for example, + * sockets will return their MTU, while files will return the + * filesystem's block size, and memory buffers will throw an exception. + */ + virtual size getBlockSize() const = 0; + /** + * If possible, this returns a string that can be used to describe how + * to access the open stream. Not all streams support this, such as + * MemBuf, but for files it may give you a path to a file, for a socket + * it may give you an ip address, etc. If it isn't supported, an empty + * string may be returned. + */ + virtual Bu::FString getLocation() const = 0; private: diff --git a/src/tcpsocket.cpp b/src/tcpsocket.cpp index bbd9cf5..22acdf7 100644 --- a/src/tcpsocket.cpp +++ b/src/tcpsocket.cpp @@ -149,7 +149,7 @@ void Bu::TcpSocket::close() bActive = false; } -size_t Bu::TcpSocket::read( void *pBuf, size_t nBytes ) +Bu::size Bu::TcpSocket::read( void *pBuf, Bu::size nBytes ) { fd_set rfds; FD_ZERO(&rfds); @@ -195,11 +195,11 @@ size_t Bu::TcpSocket::read( void *pBuf, size_t nBytes ) return 0; } -size_t Bu::TcpSocket::read( void *pBuf, size_t nBytes, +Bu::size Bu::TcpSocket::read( void *pBuf, Bu::size nBytes, uint32_t nSec, uint32_t nUSec ) { struct timeval tv; - size_t nRead = 0; + Bu::size nRead = 0; fd_set rfds; FD_ZERO(&rfds); @@ -239,7 +239,7 @@ size_t Bu::TcpSocket::read( void *pBuf, size_t nBytes, return nRead; } -size_t Bu::TcpSocket::write( const void *pBuf, size_t nBytes ) +Bu::size Bu::TcpSocket::write( const void *pBuf, Bu::size nBytes ) { //#ifdef WIN32 int nWrote = TEMP_FAILURE_RETRY( @@ -261,10 +261,10 @@ size_t Bu::TcpSocket::write( const void *pBuf, size_t nBytes ) return nWrote; } -size_t Bu::TcpSocket::write( const void *pBuf, size_t nBytes, uint32_t nSec, uint32_t nUSec ) +Bu::size Bu::TcpSocket::write( const void *pBuf, Bu::size nBytes, uint32_t nSec, uint32_t nUSec ) { struct timeval tv; - size_t nWrote = 0; + Bu::size nWrote = 0; fd_set wfds; FD_ZERO(&wfds); @@ -304,22 +304,22 @@ size_t Bu::TcpSocket::write( const void *pBuf, size_t nBytes, uint32_t nSec, uin return nWrote; } -long Bu::TcpSocket::tell() +Bu::size Bu::TcpSocket::tell() { throw UnsupportedException(); } -void Bu::TcpSocket::seek( long ) +void Bu::TcpSocket::seek( Bu::size ) { throw UnsupportedException(); } -void Bu::TcpSocket::setPos( long ) +void Bu::TcpSocket::setPos( Bu::size ) { throw UnsupportedException(); } -void Bu::TcpSocket::setPosEnd( long ) +void Bu::TcpSocket::setPosEnd( Bu::size ) { throw UnsupportedException(); } @@ -401,7 +401,7 @@ void Bu::TcpSocket::setBlocking( bool bBlocking ) fcntl( nTcpSocket, F_SETFL, fcntl( nTcpSocket, F_GETFL, 0 ) | O_NONBLOCK ); } #else - u_long iMode; + u_Bu::size iMode; if( bBlocking ) iMode = 0; else @@ -416,7 +416,7 @@ void Bu::TcpSocket::setBlocking( bool bBlocking ) #endif } -void Bu::TcpSocket::setSize( long ) +void Bu::TcpSocket::setSize( Bu::size ) { } @@ -436,6 +436,8 @@ void Bu::TcpSocket::setAddress() addr.sin_family = AF_INET; bu_getpeername( nTcpSocket, (sockaddr *)(&addr), &len ); sAddress = bu_inet_ntoa( addr.sin_addr ); + + printf("%d\n", IP_MTU ); } Bu::FString Bu::TcpSocket::getAddress() const @@ -448,3 +450,17 @@ Bu::TcpSocket::operator int() const return nTcpSocket; } +Bu::size Bu::TcpSocket::getSize() const +{ + throw UnsupportedException(); +} + +Bu::size Bu::TcpSocket::getBlockSize() const +{ + +} + +Bu::FString Bu::TcpSocket::getLocation() const +{ +} + diff --git a/src/tcpsocket.h b/src/tcpsocket.h index 3361e84..8543ad0 100644 --- a/src/tcpsocket.h +++ b/src/tcpsocket.h @@ -10,6 +10,7 @@ #include +#include "bu/config.h" #include "bu/stream.h" #include "bu/fstring.h" #include "bu/exceptionbase.h" @@ -66,18 +67,18 @@ namespace Bu virtual void close(); //virtual void read(); - virtual size_t read( void *pBuf, size_t nBytes ); - virtual size_t read( void *pBuf, size_t nBytes, + virtual size read( void *pBuf, size nBytes ); + virtual size read( void *pBuf, size nBytes, uint32_t nSec, uint32_t nUSec=0 ); - virtual size_t write( const void *pBuf, size_t nBytes ); - virtual size_t write( const void *pBuf, size_t nBytes, + virtual size write( const void *pBuf, size nBytes ); + virtual size write( const void *pBuf, size nBytes, uint32_t nSec, uint32_t nUSec=0 ); using Stream::write; - virtual long tell(); - virtual void seek( long offset ); - virtual void setPos( long pos ); - virtual void setPosEnd( long pos ); + virtual size tell(); + virtual void seek( size offset ); + virtual void setPos( size pos ); + virtual void setPosEnd( size pos ); virtual bool isEos(); virtual bool isOpen(); @@ -93,11 +94,15 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); - virtual void setSize( long iSize ); + virtual void setSize( size iSize ); Bu::FString getAddress() const; operator int() const; + virtual size getSize() const; + virtual size getBlockSize() const; + virtual Bu::FString getLocation() const; + private: void setAddress(); -- cgit v1.2.3 From f5aca1a1b402bd7ebc944dc6e6fe65828d863365 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Jan 2011 02:14:08 +0000 Subject: Bu::FString is now String, and there's a shell script to fix any other programs that were using fstring, I hope. --- src/archive.h | 6 +- src/bitstring.cpp | 4 +- src/bitstring.h | 4 +- src/cachestorefiles.h | 8 +- src/cachestoremyriad.h | 2 +- src/client.cpp | 8 +- src/client.h | 10 +- src/clientlink.h | 4 +- src/compat/win32.h | 2 +- src/conduit.h | 2 +- src/crypt.cpp | 8 +- src/crypt.h | 6 +- src/cryptohash.cpp | 8 +- src/cryptohash.h | 10 +- src/csvreader.cpp | 10 +- src/csvreader.h | 10 +- src/csvwriter.cpp | 14 +- src/csvwriter.h | 10 +- src/fastcgi.cpp | 8 +- src/fastcgi.h | 10 +- src/fbasicstring.cpp | 9 - src/fbasicstring.h | 2101 -------------------------------------------- src/fifo.cpp | 2 +- src/fifo.h | 4 +- src/file.cpp | 4 +- src/file.h | 8 +- src/formatter.cpp | 14 +- src/formatter.h | 18 +- src/formula.h | 10 +- src/fstring.cpp | 128 --- src/fstring.h | 53 -- src/hash.h | 2 +- src/httpget.cpp | 2 +- src/httpget.h | 8 +- src/itoserver.cpp | 8 +- src/itoserver.h | 8 +- src/lexer.cpp | 2 +- src/lexer.h | 2 +- src/logger.cpp | 8 +- src/logger.h | 6 +- src/md5.cpp | 6 +- src/md5.h | 4 +- src/membuf.cpp | 6 +- src/membuf.h | 10 +- src/minicron.cpp | 22 +- src/minicron.h | 24 +- src/minimacro.cpp | 34 +- src/minimacro.h | 42 +- src/multiserver.cpp | 2 +- src/multiserver.h | 2 +- src/nullstream.cpp | 4 +- src/nullstream.h | 2 +- src/optparser.cpp | 28 +- src/optparser.h | 56 +- src/parser.cpp | 22 +- src/parser.h | 26 +- src/plugger.h | 14 +- src/process.h | 2 +- src/protocol.cpp | 2 +- src/protocol.h | 4 +- src/protocolhttp.cpp | 10 +- src/protocolhttp.h | 24 +- src/protocoltelnet.cpp | 2 +- src/protocoltelnet.h | 16 +- src/regex.cpp | 12 +- src/regex.h | 16 +- src/server.cpp | 4 +- src/server.h | 6 +- src/sha1.cpp | 6 +- src/sha1.h | 4 +- src/stream.cpp | 6 +- src/stream.h | 8 +- src/streamstack.cpp | 2 +- src/streamstack.h | 2 +- src/string.cpp | 128 +++ src/string.h | 2129 +++++++++++++++++++++++++++++++++++++++++++++ src/tafcomment.cpp | 4 +- src/tafcomment.h | 6 +- src/tafgroup.cpp | 32 +- src/tafgroup.h | 44 +- src/tafnode.h | 2 +- src/tafproperty.cpp | 6 +- src/tafproperty.h | 10 +- src/tafreader.cpp | 14 +- src/tafreader.h | 4 +- src/tafwriter.cpp | 4 +- src/tafwriter.h | 4 +- src/tcpserversocket.cpp | 2 +- src/tcpserversocket.h | 4 +- src/tcpsocket.cpp | 6 +- src/tcpsocket.h | 12 +- src/tests/archive.cpp | 4 +- src/tests/cache.cpp | 18 +- src/tests/fastcgi.cpp | 8 +- src/tests/fstratsptr.cpp | 8 +- src/tests/fstrformat.cpp | 4 +- src/tests/fstring.cpp | 28 +- src/tests/fstrstd.cpp | 4 +- src/tests/hash2.cpp | 4 +- src/tests/heap.cpp | 14 +- src/tests/listsort.cpp | 6 +- src/tests/mmparse.cpp | 2 +- src/tests/optparser.cpp | 2 +- src/tests/sha1.cpp | 4 +- src/tests/signals.cpp | 24 +- src/tests/size.cpp | 6 +- src/tests/speed.cpp | 6 +- src/tests/streamstack.cpp | 4 +- src/tests/telnetsrv.cpp | 2 +- src/tools/bnfcompile.cpp | 26 +- src/tools/mkunit.cpp | 34 +- src/tools/myriad.cpp | 6 +- src/tools/parser.cpp | 2 +- src/tools/viewcsv.cpp | 10 +- src/unit/archive.unit | 14 +- src/unit/array.unit | 2 +- src/unit/buffer.unit | 4 +- src/unit/fstring.unit | 134 +-- src/unit/hash.unit | 10 +- src/unit/list.unit | 2 +- src/unit/myriad.unit | 20 +- src/unit/queuebuf.unit | 12 +- src/unit/taf.unit | 6 +- src/unit/xml.unit | 4 +- src/unitsuite.cpp | 8 +- src/unitsuite.h | 24 +- src/url.cpp | 66 +- src/url.h | 66 +- src/utfstring.cpp | 27 - src/utfstring.h | 21 +- src/uuid.cpp | 6 +- src/uuid.h | 6 +- src/variant.cpp | 12 +- src/variant.h | 12 +- src/xmlreader.h | 6 +- support/fixstrings.sh | 17 + 136 files changed, 3015 insertions(+), 3072 deletions(-) delete mode 100644 src/fbasicstring.cpp delete mode 100644 src/fbasicstring.h delete mode 100644 src/fstring.cpp delete mode 100644 src/fstring.h create mode 100644 src/string.cpp create mode 100644 src/string.h create mode 100755 support/fixstrings.sh (limited to 'src') diff --git a/src/archive.h b/src/archive.h index 9d2aee2..5294c15 100644 --- a/src/archive.h +++ b/src/archive.h @@ -111,7 +111,7 @@ namespace Bu void readID( const void *ptr, uint32_t id ); template - void setProp( const Bu::FString &sId, const t &val ) + void setProp( const Bu::String &sId, const t &val ) { if( !hProps.has( sId ) ) { @@ -121,7 +121,7 @@ namespace Bu } template - t getProp( const Bu::FString &sId ) + t getProp( const Bu::String &sId ) { return hProps.get( sId ); } @@ -131,7 +131,7 @@ namespace Bu uint32_t nNextID; Hash hPtrID; Hash > hPtrDest; - Hash hProps; + Hash hProps; }; } diff --git a/src/bitstring.cpp b/src/bitstring.cpp index 207a036..39c2e63 100644 --- a/src/bitstring.cpp +++ b/src/bitstring.cpp @@ -444,9 +444,9 @@ long Bu::BitString::getHighestOrderBitPos() return -1; } -Bu::FString Bu::BitString::toString() +Bu::String Bu::BitString::toString() { - Bu::FString sRet; + Bu::String sRet; for( int j = iBits-1; j >= 0; j-- ) sRet.append( getBit( j )?'1':'0' ); return sRet; diff --git a/src/bitstring.h b/src/bitstring.h index 4d0437a..a8aec57 100644 --- a/src/bitstring.h +++ b/src/bitstring.h @@ -9,7 +9,7 @@ #define BU_BITSTRING_H #include "bu/util.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -203,7 +203,7 @@ namespace Bu */ long toLong( long iStart = 0, long iSize = 32 ); - Bu::FString toString(); + Bu::String toString(); //operators BitString &operator=( const BitString &xSrc ); diff --git a/src/cachestorefiles.h b/src/cachestorefiles.h index c2cf091..5a9478d 100644 --- a/src/cachestorefiles.h +++ b/src/cachestorefiles.h @@ -8,7 +8,7 @@ #ifndef BU_CACHE_STORE_FILES_H #define BU_CACHE_STORE_FILES_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/file.h" #include "bu/cachestore.h" #include "bu/archive.h" @@ -53,7 +53,7 @@ namespace Bu class CacheStoreFiles : public CacheStore { public: - CacheStoreFiles( const Bu::FString &sPrefix ) : + CacheStoreFiles( const Bu::String &sPrefix ) : sPrefix( sPrefix ) { if( access( sPrefix.getStr(), W_OK|R_OK|X_OK ) ) @@ -138,7 +138,7 @@ namespace Bu Bu::MemBuf mb; Bu::Formatter f( mb ); f << sPrefix << "/"; - Bu::FString sBase = mb.getString(); + Bu::String sBase = mb.getString(); f << key; if( sBase == mb.getString() ) @@ -199,7 +199,7 @@ namespace Bu } private: - Bu::FString sPrefix; + Bu::String sPrefix; }; }; diff --git a/src/cachestoremyriad.h b/src/cachestoremyriad.h index 21c84e6..1928840 100644 --- a/src/cachestoremyriad.h +++ b/src/cachestoremyriad.h @@ -8,7 +8,7 @@ #ifndef BU_CACHE_STORE_MYRIAD_H #define BU_CACHE_STORE_MYRIAD_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/stream.h" #include "bu/myriad.h" #include "bu/cachestore.h" diff --git a/src/client.cpp b/src/client.cpp index b635c8b..c8d5dd4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -109,12 +109,12 @@ void Bu::Client::clearProtocol() pProto = NULL; } /* -Bu::FString &Bu::Client::getInput() +Bu::String &Bu::Client::getInput() { return sReadBuf; } -Bu::FString &Bu::Client::getOutput() +Bu::String &Bu::Client::getOutput() { return sWriteBuf; } @@ -126,7 +126,7 @@ bool Bu::Client::isOpen() return pTopStream->isOpen(); } -size_t Bu::Client::write( const Bu::FString &sData ) +size_t Bu::Client::write( const Bu::String &sData ) { return qbWrite.write( sData.getStr(), sData.getSize() ); } @@ -221,7 +221,7 @@ Bu::ClientLink *Bu::Client::getLink() return pfLink->createLink( this ); } -void Bu::Client::onMessage( const Bu::FString &sMsg ) +void Bu::Client::onMessage( const Bu::String &sMsg ) { if( pProto ) pProto->onMessage( this, sMsg ); diff --git a/src/client.h b/src/client.h index 98b31f7..871acad 100644 --- a/src/client.h +++ b/src/client.h @@ -11,7 +11,7 @@ #include #include "bu/config.h" -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/queuebuf.h" namespace Bu @@ -33,9 +33,9 @@ namespace Bu void processInput(); void processOutput(); - //Bu::FString &getInput(); - //Bu::FString &getOutput(); - size_t write( const Bu::FString &sData ); + //Bu::String &getInput(); + //Bu::String &getOutput(); + size_t write( const Bu::String &sData ); size_t write( const void *pData, size_t nBytes ); size_t write( int8_t nData ); size_t write( int16_t nData ); @@ -66,7 +66,7 @@ namespace Bu class ClientLink *getLink(); - void onMessage( const Bu::FString &sMsg ); + void onMessage( const Bu::String &sMsg ); bool hasOutput() { return qbWrite.getSize() > 0; } bool hasInput() { return qbRead.getSize() > 0; } diff --git a/src/clientlink.h b/src/clientlink.h index aa6d362..28910bb 100644 --- a/src/clientlink.h +++ b/src/clientlink.h @@ -8,7 +8,7 @@ #ifndef BU_CLIENT_LINK_H #define BU_CLIENT_LINK_H -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -18,7 +18,7 @@ namespace Bu ClientLink(); virtual ~ClientLink(); - virtual void sendMessage( const Bu::FString &sMsg )=0; + virtual void sendMessage( const Bu::String &sMsg )=0; }; }; diff --git a/src/compat/win32.h b/src/compat/win32.h index 6304d4c..82ab4d6 100644 --- a/src/compat/win32.h +++ b/src/compat/win32.h @@ -18,7 +18,7 @@ extern "C" } #endif -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/singleton.h" #ifndef TEMP_FAILURE_RETRY diff --git a/src/conduit.h b/src/conduit.h index 7125fc5..f8ad4fa 100644 --- a/src/conduit.h +++ b/src/conduit.h @@ -9,7 +9,7 @@ #define BU_CONDUIT_H #include "bu/stream.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { diff --git a/src/crypt.cpp b/src/crypt.cpp index ae04353..97260c9 100644 --- a/src/crypt.cpp +++ b/src/crypt.cpp @@ -11,14 +11,14 @@ #include "bu/membuf.h" #include "bu/file.h" -Bu::FString Bu::cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt ) +Bu::String Bu::cryptPass( const Bu::String &sPass, const Bu::String &sSalt ) { Bu::Md5 md5; Bu::MemBuf mbOut; Bu::Base64 b64Out( mbOut ); - Bu::FString::const_iterator i = sSalt.find('$'); - Bu::FString sSaltSml = sSalt.getSubStr( sSalt.begin(), i ); + Bu::String::const_iterator i = sSalt.find('$'); + Bu::String sSaltSml = sSalt.getSubStr( sSalt.begin(), i ); md5.addData( sPass ); md5.addData( sSaltSml ); @@ -29,7 +29,7 @@ Bu::FString Bu::cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt ) return sSaltSml + "$" + mbOut.getString(); } -Bu::FString Bu::cryptPass( const Bu::FString &sPass ) +Bu::String Bu::cryptPass( const Bu::String &sPass ) { Bu::MemBuf mbSalt; Bu::Base64 b64Salt( mbSalt ); diff --git a/src/crypt.h b/src/crypt.h index cf7fb97..d6bfe4b 100644 --- a/src/crypt.h +++ b/src/crypt.h @@ -8,12 +8,12 @@ #ifndef BU_CRYPT_H #define BU_CRYPT_H -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { - FString cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt ); - FString cryptPass( const Bu::FString &sPass ); + String cryptPass( const Bu::String &sPass, const Bu::String &sSalt ); + String cryptPass( const Bu::String &sPass ); }; #endif diff --git a/src/cryptohash.cpp b/src/cryptohash.cpp index 8aee415..bb07a4b 100644 --- a/src/cryptohash.cpp +++ b/src/cryptohash.cpp @@ -15,15 +15,15 @@ Bu::CryptoHash::~CryptoHash() { } -void Bu::CryptoHash::addData( const Bu::FString &sData ) +void Bu::CryptoHash::addData( const Bu::String &sData ) { addData( sData.getStr(), sData.getSize() ); } -Bu::FString Bu::CryptoHash::getHexResult() +Bu::String Bu::CryptoHash::getHexResult() { - Bu::FString sResult = getResult(); - Bu::FString sRet( 2*sResult.getSize() ); + Bu::String sResult = getResult(); + Bu::String sRet( 2*sResult.getSize() ); static const char hex_tab[] = {"0123456789abcdef"}; int k = 0; diff --git a/src/cryptohash.h b/src/cryptohash.h index 5d83895..56dc356 100644 --- a/src/cryptohash.h +++ b/src/cryptohash.h @@ -8,7 +8,7 @@ #ifndef BU_CRYPTO_HASH_H #define BU_CRYPTO_HASH_H -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -21,12 +21,12 @@ namespace Bu virtual ~CryptoHash(); virtual void reset() = 0; - virtual void setSalt( const Bu::FString &sSalt ) = 0; + virtual void setSalt( const Bu::String &sSalt ) = 0; virtual void addData( const void *sData, int iSize ) = 0; - virtual void addData( const Bu::FString &sData ); - virtual FString getResult() = 0; + virtual void addData( const Bu::String &sData ); + virtual String getResult() = 0; virtual void writeResult( Stream &sOut ) = 0; - virtual Bu::FString getHexResult(); + virtual Bu::String getHexResult(); }; }; diff --git a/src/csvreader.cpp b/src/csvreader.cpp index f3133c2..22b0608 100644 --- a/src/csvreader.cpp +++ b/src/csvreader.cpp @@ -41,12 +41,12 @@ Bu::StrArray Bu::CsvReader::readLine() { Bu::StrArray aVals; - Bu::FString sLine = sIn.readLine(); + Bu::String sLine = sIn.readLine(); if( !sLine.isSet() ) return Bu::StrArray(); - Bu::FString::iterator i = sLine.begin(); + Bu::String::iterator i = sLine.begin(); aVals.append( sDecode( i ) ); @@ -73,9 +73,9 @@ Bu::StrArray Bu::CsvReader::readLine() return aVals; } -Bu::FString Bu::CsvReader::decodeExcel( Bu::FString::iterator &i ) +Bu::String Bu::CsvReader::decodeExcel( Bu::String::iterator &i ) { - Bu::FString sRet; + Bu::String sRet; for(; i && (*i == ' ' || *i == '\t'); i++ ) { } @@ -123,7 +123,7 @@ Bu::FString Bu::CsvReader::decodeExcel( Bu::FString::iterator &i ) return sRet; } -Bu::FString Bu::CsvReader::decodeC( Bu::FString::iterator & ) +Bu::String Bu::CsvReader::decodeC( Bu::String::iterator & ) { return ""; } diff --git a/src/csvreader.h b/src/csvreader.h index 9ad65fd..1c3525c 100644 --- a/src/csvreader.h +++ b/src/csvreader.h @@ -8,19 +8,19 @@ #ifndef BU_CSV_READER_H #define BU_CSV_READER_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/array.h" #include "bu/signals.h" namespace Bu { class Stream; - typedef Bu::Array StrArray; + typedef Bu::Array StrArray; class CsvReader { public: - typedef Bu::Signal1 DecodeSignal; + typedef Bu::Signal1 DecodeSignal; enum Style { styleExcel, ///< Excel style quotes around things that need em @@ -37,8 +37,8 @@ namespace Bu Stream &sIn; DecodeSignal sDecode; - static Bu::FString decodeExcel( Bu::FString::iterator &i ); - static Bu::FString decodeC( Bu::FString::iterator &i ); + static Bu::String decodeExcel( Bu::String::iterator &i ); + static Bu::String decodeC( Bu::String::iterator &i ); }; }; diff --git a/src/csvwriter.cpp b/src/csvwriter.cpp index 3e2816b..6b50ed0 100644 --- a/src/csvwriter.cpp +++ b/src/csvwriter.cpp @@ -36,7 +36,7 @@ Bu::CsvWriter::~CsvWriter() void Bu::CsvWriter::writeLine( const StrArray &aStrs ) { - Bu::FString sBuf; + Bu::String sBuf; for( StrArray::const_iterator i = aStrs.begin(); i; i++ ) { if( i != aStrs.begin() ) @@ -48,12 +48,12 @@ void Bu::CsvWriter::writeLine( const StrArray &aStrs ) sOut.write( sBuf ); } -Bu::FString Bu::CsvWriter::encodeExcel( const Bu::FString &sIn ) +Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn ) { if( sIn.find('\"') ) { - Bu::FString sOut = "\""; - for( Bu::FString::const_iterator i = sIn.begin(); i; i++ ) + Bu::String sOut = "\""; + for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) { if( *i == '\"' ) sOut += "\"\""; @@ -65,10 +65,10 @@ Bu::FString Bu::CsvWriter::encodeExcel( const Bu::FString &sIn ) return sIn; } -Bu::FString Bu::CsvWriter::encodeC( const Bu::FString &sIn ) +Bu::String Bu::CsvWriter::encodeC( const Bu::String &sIn ) { - Bu::FString sOut = ""; - for( Bu::FString::const_iterator i = sIn.begin(); i; i++ ) + Bu::String sOut = ""; + for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) { if( *i == ',' ) sOut += "\\,"; diff --git a/src/csvwriter.h b/src/csvwriter.h index 289d25c..8da5eee 100644 --- a/src/csvwriter.h +++ b/src/csvwriter.h @@ -8,19 +8,19 @@ #ifndef BU_CSV_WRITER_H #define BU_CSV_WRITER_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/array.h" #include "bu/signals.h" namespace Bu { class Stream; - typedef Bu::Array StrArray; + typedef Bu::Array StrArray; class CsvWriter { public: - typedef Bu::Signal1 EncodeSignal; + typedef Bu::Signal1 EncodeSignal; enum Style { styleExcel, ///< Excel style quotes around things that need em @@ -37,8 +37,8 @@ namespace Bu Stream &sOut; EncodeSignal sEncode; - static Bu::FString encodeExcel( const Bu::FString &sIn ); - static Bu::FString encodeC( const Bu::FString &sIn ); + static Bu::String encodeExcel( const Bu::String &sIn ); + static Bu::String encodeC( const Bu::String &sIn ); }; }; diff --git a/src/fastcgi.cpp b/src/fastcgi.cpp index ca3010e..1b012e8 100644 --- a/src/fastcgi.cpp +++ b/src/fastcgi.cpp @@ -114,14 +114,14 @@ void Bu::FastCgi::readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uRead uRead += uName + uValue; unsigned char *sName = new unsigned char[uName]; s.read( sName, uName ); - Bu::FString fsName( (char *)sName, uName ); + Bu::String fsName( (char *)sName, uName ); delete[] sName; if( uValue > 0 ) { unsigned char *sValue = new unsigned char[uValue]; s.read( sValue, uValue ); - Bu::FString fsValue( (char *)sValue, uValue ); + Bu::String fsValue( (char *)sValue, uValue ); hParams.insert( fsName, fsValue ); delete[] sValue; } @@ -305,8 +305,8 @@ void Bu::FastCgi::run() mStdOut, mStdErr ); - Bu::FString &sStdOut = mStdOut.getString(); - Bu::FString &sStdErr = mStdErr.getString(); + Bu::String &sStdOut = mStdOut.getString(); + Bu::String &sStdErr = mStdErr.getString(); Record rOut; memset( &rOut, 0, sizeof(rOut) ); diff --git a/src/fastcgi.h b/src/fastcgi.h index 7c1c04c..4463bee 100644 --- a/src/fastcgi.h +++ b/src/fastcgi.h @@ -8,7 +8,7 @@ #ifndef BU_FAST_CGI_H #define BU_FAST_CGI_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/hash.h" #include "bu/array.h" #include "bu/tcpsocket.h" @@ -27,7 +27,7 @@ namespace Bu static bool isEmbedded(); - typedef Bu::Hash StrHash; + typedef Bu::Hash StrHash; enum RequestType { typeBeginRequest = 1, @@ -86,8 +86,8 @@ namespace Bu typedef struct Channel { Channel() : uFlags( 0 ) { } StrHash hParams; - Bu::FString sStdIn; - Bu::FString sData; + Bu::String sStdIn; + Bu::String sData; uint8_t uFlags; } Channel; @@ -104,7 +104,7 @@ namespace Bu virtual void onInit() { }; virtual int onRequest( const StrHash &hParams, - const Bu::FString &sStdIn, Bu::Stream &sStdOut, + const Bu::String &sStdIn, Bu::Stream &sStdOut, Bu::Stream &sStdErr )=0; virtual void onUninit() { }; diff --git a/src/fbasicstring.cpp b/src/fbasicstring.cpp deleted file mode 100644 index 4834301..0000000 --- a/src/fbasicstring.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2007-2010 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/fbasicstring.h" - diff --git a/src/fbasicstring.h b/src/fbasicstring.h deleted file mode 100644 index 064ff16..0000000 --- a/src/fbasicstring.h +++ /dev/null @@ -1,2101 +0,0 @@ -/* - * Copyright (C) 2007-2010 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_F_BASIC_STRING_H -#define BU_F_BASIC_STRING_H - -#include -#include - -#ifndef WIN32 -#include -#endif - -#include "bu/util.h" -#include "bu/sharedcore.h" -#include "bu/exceptionbase.h" -#include "bu/archivebase.h" -#include "bu/list.h" - -#include - -namespace Bu -{ - /** @cond DEVEL */ - template< typename chr > - struct FStringChunk - { - long nLength; - chr *pData; - FStringChunk *pNext; - }; - -#define cpy( dest, src, size ) Bu::memcpy( dest, src, size*sizeof(chr) ) - - template< typename chr, int nMinSize, typename chralloc, - typename chunkalloc> class FBasicString; - - template - size_t strlen( const chr *pData ) - { - for( size_t tLen = 0;; ++tLen ) - { - if( pData[tLen] == (chr)0 ) - return tLen; - } - return -1; - } - - template - size_t strlen( const char *pData ) - { - return ::strlen( pData ); - } - - template - int strncmp( const chr *a, const chr *b, size_t iLen ) - { - for( size_t iPos = 0; iPos < iLen; iPos++ ) - { - if( a[iPos] != b[iPos] ) - { - return a[iPos]-b[iPos]; - } - } - return 0; - } - - template - int strncmp( const char *a, const char *b, size_t iLen ) - { - return ::strncmp( a, b, iLen ); - } - - template - struct FStringCore - { - friend class FBasicString; - friend class SharedCore< - FBasicString, - FStringCore - >; - private: - typedef struct FStringCore MyType; - typedef struct FStringChunk Chunk; - FStringCore() : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - } - - FStringCore( const MyType &rSrc ) : - nLength( rSrc.nLength ), - pFirst( NULL ), - pLast( NULL ), - aChr( rSrc.aChr ), - aChunk( rSrc.aChunk ) - { - if( rSrc.pFirst == NULL || rSrc.nLength == 0 ) - { - pFirst = pLast = NULL; - } - else - { - pFirst = pLast = newChunk( nLength ); - Chunk *pLink = rSrc.pFirst; - int iPos = 0; - while( pLink != NULL ) - { - cpy( pFirst->pData+iPos, pLink->pData, pLink->nLength ); - iPos += pLink->nLength; - pLink = pLink->pNext; - } - } - } - - virtual ~FStringCore() - { - clear(); - } - - mutable long nLength; - mutable Chunk *pFirst; - mutable Chunk *pLast; - - mutable chralloc aChr; - mutable chunkalloc aChunk; - - void clear() const - { - if( pFirst == NULL ) - return; - - Chunk *i = pFirst; - for(;;) - { - Chunk *n = i->pNext; - aChr.deallocate( i->pData, i->nLength+1 ); - aChunk.deallocate( i, 1 ); - if( n == NULL ) - break; - i = n; - } - pFirst = pLast = NULL; - nLength = 0; - } - - Chunk *newChunk() const - { - Chunk *pNew = aChunk.allocate( 1 ); - pNew->pNext = NULL; - return pNew; - } - - Chunk *newChunk( long nLen ) const - { - Chunk *pNew = aChunk.allocate( 1 ); - pNew->pNext = NULL; - pNew->nLength = nLen; - pNew->pData = aChr.allocate( (nLenpData[nLen] = (chr)0; - return pNew; - } - - Chunk *copyChunk( Chunk *pSrc ) const - { - Chunk *pNew = aChunk.allocate( 1 ); - pNew->pNext = pSrc->pNext; - pNew->nLength = pSrc->nLength; - pNew->pData = aChr.allocate( pSrc->nLength+1 ); - cpy( pNew->pData, pSrc->pData, pSrc->nLength ); - pNew->pData[pNew->nLength] = (chr)0; - return pNew; - } - - void appendChunk( Chunk *pNewChunk ) - { - if( pFirst == NULL ) - pLast = pFirst = pNewChunk; - else - { - pLast->pNext = pNewChunk; - pLast = pNewChunk; - } - - nLength += pNewChunk->nLength; - } - - void prependChunk( Chunk *pNewChunk ) - { - if( pFirst == NULL ) - pLast = pFirst = pNewChunk; - else - { - pNewChunk->pNext = pFirst; - pFirst = pNewChunk; - } - - nLength += pNewChunk->nLength; - } - }; - /** @endcond */ - - /** - * Flexible String class. This class was designed with string passing and - * generation in mind. Like the standard string class you can specify what - * datatype to use for each character. Unlike the standard string class, - * collection of appended and prepended terms is done lazily, making long - * operations that involve many appends very inexpensive. In addition - * internal ref-counting means that if you pass strings around between - * functions there's almost no overhead in time or memory since a reference - * is created and no data is actually copied. This also means that you - * never need to put any FBasicString into a ref-counting container class. - * - *@param chr (typename) Type of character (i.e. char) - *@param nMinSize (int) Chunk size (default: 256) - *@param chralloc (typename) Memory Allocator for chr - *@param chunkalloc (typename) Memory Allocator for chr chunks - */ - template< typename chr, int nMinSize=256, - typename chralloc=std::allocator, - typename chunkalloc=std::allocator > > - class FBasicString : public SharedCore< - FBasicString, - FStringCore > - { - protected: - typedef struct FStringChunk Chunk; - typedef struct FBasicString MyType; - typedef struct FStringCore Core; - - using SharedCore::core; - using SharedCore::_hardCopy; - - public: // Iterators - struct iterator; - typedef struct const_iterator - { - friend class FBasicString; - friend struct iterator; - private: - const_iterator( Chunk *pChunk, int iPos ) : - pChunk( pChunk ), - iPos( iPos ) - { - } - - Chunk *pChunk; - int iPos; - - public: - const_iterator( const const_iterator &i ) : - pChunk( i.pChunk ), - iPos( i.iPos ) - { - } - - const_iterator( const struct iterator &i ) : - pChunk( i.pChunk ), - iPos( i.iPos ) - { - } - - const_iterator() : - pChunk( NULL ), - iPos( 0 ) - { - } - - bool operator==( const const_iterator &i ) const - { - return pChunk == i.pChunk && iPos == i.iPos; - } - - bool operator!=( const const_iterator &i ) const - { - return !(*this == i); - } - - const_iterator &operator=( const const_iterator &i ) - { - pChunk = i.pChunk; - iPos = i.iPos; - return *this; - } - - const_iterator &operator++() - { - if( !pChunk ) return *this; - iPos++; - if( iPos >= pChunk->nLength ) - { - iPos = 0; - pChunk = pChunk->pNext; - } - return *this; - } - - const_iterator &operator++( int ) - { - if( !pChunk ) return *this; - iPos++; - if( iPos >= pChunk->nLength ) - { - iPos = 0; - pChunk = pChunk->pNext; - } - return *this; - } - - const_iterator &operator+=( int iAmnt ) - { - if( !pChunk ) return *this; - iPos += iAmnt; - while( iPos >= pChunk->nLength ) - { - iPos -= pChunk->nLength; - pChunk = pChunk->pNext; - if( pChunk == NULL ) - break; - } - return *this; - } - - const_iterator operator+( int iAmnt ) const - { - if( !pChunk ) return *this; - const_iterator ret( *this ); - ret += iAmnt; - return ret; - } - - const chr &operator *() const - { - if( !pChunk ) throw Bu::ExceptionBase("Not a valid const_iterator."); - return pChunk->pData[iPos]; - } - - bool operator==( const chr &c ) const - { - if( !pChunk ) return false; - return pChunk->pData[iPos] == c; - } - - bool operator!=( const chr &c ) const - { - if( !pChunk ) return false; - return pChunk->pData[iPos] != c; - } - - operator bool() const - { - return pChunk != NULL; - } - - bool isValid() const - { - return pChunk != NULL; - } - - bool compare( const const_iterator &c ) const - { - const_iterator a = *this; - const_iterator b = c; - if( a == b ) - return true; - for(; a && b; a++, b++ ) - { - if( *a != *b ) - return false; - } - return true; - } - - bool compare( const const_iterator &c, int nLen ) const - { - const_iterator a = *this; - const_iterator b = c; - if( a == b ) - return true; - for(int j = 0; a && b && j < nLen; a++, b++, j++ ) - { - if( *a != *b ) - return false; - } - return true; - } - - bool compare( const chr *c ) const - { - if( !pChunk ) return false; - const_iterator a = *this; - for(; a && *c; a++, c++ ) - { - if( *a != *c ) - return false; - } - if( a.isValid() != (*c!=(chr)0) ) - return false; - return true; - } - - bool compare( const chr *c, int nLen ) const - { - if( !pChunk ) return false; - const_iterator a = *this; - int j = 0; - for(; a && j < nLen; a++, c++, j++ ) - { - if( *a != *c ) - return false; - } - if( j < nLen ) - return false; - return true; - } - - bool compare( const MyType &s ) const - { - if( !pChunk ) return false; - return compare( s.begin() ); - } - - bool compare( const MyType &s, int nLen ) const - { - if( !pChunk ) return false; - return compare( s.begin(), nLen ); - } - - const_iterator find( const chr c ) const - { - for( const_iterator i = *this; i; i++ ) - { - if( *i == c ) - return i; - } - return const_iterator( NULL, 0 ); - } - - const_iterator find( const chr *pStr, int nLen ) const - { - for( const_iterator i = *this; i; i++ ) - { - if( i.compare( pStr, nLen ) ) - return i; - } - return const_iterator( NULL, 0 ); - } - - const_iterator find( const MyType &s ) const - { - for( const_iterator i = *this; i; i++ ) - { - if( i.compare( s ) ) - return i; - } - return const_iterator( NULL, 0 ); - } - - const_iterator find( const MyType &s, int nLen ) const - { - for( const_iterator i = *this; i; i++ ) - { - if( i.compare( s, nLen ) ) - return i; - } - return const_iterator( NULL, 0 ); - } - } const_iterator; - - typedef struct iterator - { - friend class FBasicString; - friend struct const_iterator; - private: - iterator( Chunk *pChunk, int iPos ) : - pChunk( pChunk ), - iPos( iPos ) - { - } - - Chunk *pChunk; - int iPos; - - public: - iterator( const iterator &i ) : - pChunk( i.pChunk ), - iPos( i.iPos ) - { - } - - iterator() : - pChunk( NULL ), - iPos( 0 ) - { - } - - operator const_iterator() const - { - return const_iterator( pChunk, iPos ); - } - - bool operator==( const iterator &i ) const - { - return pChunk == i.pChunk && iPos == i.iPos; - } - - bool operator!=( const iterator &i ) const - { - return !(*this == i); - } - - iterator &operator=( const iterator &i ) - { - pChunk = i.pChunk; - iPos = i.iPos; - return *this; - } - - iterator &operator++() - { - if( !pChunk ) return *this; - iPos++; - if( iPos >= pChunk->nLength ) - { - iPos = 0; - pChunk = pChunk->pNext; - } - return *this; - } - - iterator &operator++( int ) - { - if( !pChunk ) return *this; - iPos++; - if( iPos >= pChunk->nLength ) - { - iPos = 0; - pChunk = pChunk->pNext; - } - return *this; - } - - iterator &operator+=( int iAmnt ) - { - if( !pChunk ) return *this; - iPos += iAmnt; - while( iPos >= pChunk->nLength ) - { - iPos -= pChunk->nLength; - pChunk = pChunk->pNext; - if( pChunk == NULL ) - break; - } - return *this; - } - - iterator operator+( int iAmnt ) const - { - if( !pChunk ) return *this; - iterator ret( *this ); - ret += iAmnt; - return ret; - } - - chr &operator*() - { - if( !pChunk ) throw Bu::ExceptionBase("Not a valid iterator."); - return pChunk->pData[iPos]; - } - - const chr &operator*() const - { - if( !pChunk ) throw Bu::ExceptionBase("Not a valid iterator."); - return pChunk->pData[iPos]; - } - - bool operator==( const chr &c ) const - { - if( !pChunk ) return false; - return pChunk->pData[iPos] == c; - } - - bool operator!=( const chr &c ) const - { - if( !pChunk ) return false; - return pChunk->pData[iPos] != c; - } - - iterator &operator=( const chr &c ) - { - if( !pChunk ) throw Bu::ExceptionBase("Not a valid iterator."); - pChunk->pData[iPos] = c; - return *this; - } - - operator bool() const - { - return pChunk != NULL; - } - - bool isValid() const - { - return pChunk != NULL; - } - - bool compare( const iterator &c ) const - { - iterator a = *this; - iterator b = c; - if( a == b ) - return true; - for(; a && b; a++, b++ ) - { - if( *a != *b ) - return false; - } - return true; - } - - bool compare( const iterator &c, int nLen ) const - { - iterator a = *this; - iterator b = c; - if( a == b ) - return true; - for(int j = 0; a && b && j < nLen; a++, b++, j++ ) - { - if( *a != *b ) - return false; - } - return true; - } - - bool compare( const chr *c ) const - { - if( !pChunk ) return false; - iterator a = *this; - for(; a && *c; a++, c++ ) - { - if( *a != *c ) - return false; - } - if( a.isValid() != (*c!=(chr)0) ) - return false; - return true; - } - - bool compare( const chr *c, int nLen ) const - { - if( !pChunk ) return false; - iterator a = *this; - int j = 0; - for(; a && j < nLen; a++, c++, j++ ) - { - if( *a != *c ) - return false; - } - if( j < nLen ) - return false; - return true; - } - - bool compare( const MyType &s ) const - { - if( !pChunk ) return false; - return compare( s.begin() ); - } - - bool compare( const MyType &s, int nLen ) const - { - if( !pChunk ) return false; - return compare( s.begin(), nLen ); - } - - iterator find( const chr c ) const - { - for( iterator i = *this; i; i++ ) - { - if( *i == c ) - return i; - } - return iterator( NULL, 0 ); - } - - iterator find( const chr *pStr, int nLen ) const - { - for( iterator i = *this; i; i++ ) - { - if( i.compare( pStr, nLen ) ) - return i; - } - return iterator( NULL, 0 ); - } - - iterator find( const MyType &s ) const - { - for( iterator i = *this; i; i++ ) - { - if( i.compare( s ) ) - return i; - } - return iterator( NULL, 0 ); - } - - iterator find( const MyType &s, int nLen ) const - { - for( iterator i = *this; i; i++ ) - { - if( i.compare( s, nLen ) ) - return i; - } - return iterator( NULL, 0 ); - } - } iterator; - - public: - FBasicString() - { - } - - FBasicString( const chr *pData ) - { - append( pData ); - } - - FBasicString( const chr *pData, long nLength ) - { - append( pData, nLength ); - } - - FBasicString( const MyType &rSrc ) : - SharedCore( rSrc ) - { - } - - FBasicString( const MyType &rSrc, long nLength ) - { - append( rSrc, nLength ); - } - - FBasicString( const MyType &rSrc, long nStart, long nLength ) - { - append( rSrc, nStart, nLength ); - } - - FBasicString( long nSize ) - { - core->pFirst = core->pLast = core->newChunk( nSize ); - core->nLength = nSize; - } - - FBasicString( const const_iterator &s ) - { - append( s ); - } - - FBasicString( const const_iterator &s, const const_iterator &e ) - { - append( s, e ); - } - - virtual ~FBasicString() - { - } - - /** - * Append data to your string. - *@param pData (const chr *) The data to append. - */ - void append( const chr *pData ) - { - if( !pData ) return; - long nLen; - for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } - - append( pData, 0, nLen ); - } - - /** - * Append data to your string. - *@param pData (const chr *) The data to append. - *@param nLen (long) The length of the data to append. - */ - void append( const chr *pData, long nLen ) - { - append( pData, 0, nLen ); - } - - /** - * Append data to your string. - *@param pData (const chr *) The data to append. - *@param nStart (long) The start position to copy from. - *@param nLen (long) The length of the data to append. - */ - void append( const chr *pData, long nStart, long nLen ) - { - if( !pData ) return; - if( nLen <= 0 ) - return; - - pData += nStart; - - _hardCopy(); - - if( core->pLast && core->pLast->nLength < nMinSize ) - { - int nAmnt = nMinSize - core->pLast->nLength; - if( nAmnt > nLen ) - nAmnt = nLen; - cpy( - core->pLast->pData+core->pLast->nLength, - pData, - nAmnt - ); - pData += nAmnt; - core->pLast->nLength += nAmnt; - nLen -= nAmnt; - core->nLength += nAmnt; - } - - if( nLen > 0 ) - { - Chunk *pNew = core->newChunk( nLen ); - cpy( pNew->pData, pData, nLen ); - core->appendChunk( pNew ); -// core->nLength += nLen; - } - } - - /** - * Append a single chr to your string. - *@param cData (const chr &) The character to append. - */ - void append( const chr &cData ) - { - if( core->pLast && core->pLast->nLength < nMinSize ) - { - _hardCopy(); - core->pLast->pData[core->pLast->nLength] = cData; - ++core->pLast->nLength; ++core->nLength; - // pLast->pData[pLast->nLength] = (chr)0; - } - else - { - append( &cData, 1 ); - } - } - - /** - * Append another FString to this one. - *@param sData (MyType &) The FString to append. - *@todo This function can be made much faster by not using getStr() - */ - void append( const MyType & sData ) - { - append( sData.getStr(), 0, sData.getSize() ); - } - - /** - * Append another FString to this one. - *@param sData (MyType &) The FString to append. - *@param nLen How much data to append. - *@todo This function can be made much faster by not using getStr() - */ - void append( const MyType & sData, long nLen ) - { - append( sData.getStr(), 0, nLen ); - } - - /** - * Append another FString to this one. - *@param sData (MyType &) The FString to append. - *@param nStart Start position in sData to start copying from. - *@param nLen How much data to append. - *@todo This function can be made much faster by not using getStr() - */ - void append( const MyType & sData, long nStart, long nLen ) - { - if( nLen < 0 ) - nLen = sData.getSize() - nStart; - append( sData.getStr(), nStart, nLen ); - } - - /** - * Append data to this FString using the passed in iterator as a base. - * The iterator is const, it is not changed. - *@param s Iterator from any compatible FBasicString to copy data from. - */ - void append( const const_iterator &s ) - { - if( !s.isValid() ) - return; - Chunk *pSrc = s.pChunk; - - Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); - cpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); - - _hardCopy(); - core->appendChunk( pNew ); - - while( (pSrc = pSrc->pNext) ) - { - core->appendChunk( core->copyChunk( pSrc ) ); - } - } - - /** - * Append data to this FString using the passed in iterator as a base. - * The iterator is const, it is not changed. - *@param s Iterator from any compatible FBasicString to copy data from. - */ - void append( const iterator &s ) // I get complaints without this one - { - append( const_iterator( s ) ); - } - - /** - * Append data to this FString using the passed in iterator as a base, - * and copy data until the ending iterator is reached. The character - * at the ending iterator is not copied. - * The iterators are const, they are not changed. - *@param s Iterator from any compatible FBasicString to copy data from. - *@param e Iterator to stop copying at. - */ - void append( const const_iterator &s, const const_iterator &e ) - { - if( !s.isValid() ) - return; - if( !e.isValid() ) - { - append( s ); - return; - } - _hardCopy(); - if( s.pChunk == e.pChunk ) - { - // Simple case, they're the same chunk - Chunk *pNew = core->newChunk( e.iPos-s.iPos ); - cpy( pNew->pData, s.pChunk->pData+s.iPos, e.iPos-s.iPos ); - core->appendChunk( pNew ); - } - else - { - // A little trickier, scan the blocks... - Chunk *pSrc = s.pChunk; - Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); - cpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); - core->appendChunk( pNew ); - - while( (pSrc = pSrc->pNext) != e.pChunk ) - { - core->appendChunk( core->copyChunk( pSrc ) ); - } - - pNew = core->newChunk( e.iPos ); - cpy( pNew->pData, pSrc->pData, e.iPos ); - core->appendChunk( pNew ); - } - } - - /** - * Prepend another FString to this one. - *@param sData (MyType &) The FString to prepend. - *@todo This function can be made much faster by not using getStr() - */ - void prepend( const MyType & sData ) - { - prepend( sData.getStr(), sData.getSize() ); - } - - /** - * Prepend data to your string. - *@param pData (const chr *) The data to prepend. - */ - void prepend( const chr *pData ) - { - if( pData == NULL ) - return; - - _hardCopy(); - long nLen; - for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } - - Chunk *pNew = core->newChunk( nLen ); - cpy( pNew->pData, pData, nLen ); - - core->prependChunk( pNew ); - } - - /** - * Prepend data to your string. - *@param pData (const chr *) The data to prepend. - *@param nLen (long) The length of the data to prepend. - */ - void prepend( const chr *pData, long nLen ) - { - Chunk *pNew = core->newChunk( nLen ); - - cpy( pNew->pData, pData, nLen ); - - _hardCopy(); - core->prependChunk( pNew ); - } - - void prepend( const chr c ) - { - prepend( &c, 1 ); - } - - /** - * Insert pData before byte nPos, that is, the first byte of pData will - * start at nPos. This could probably be made faster by avoiding - * flattening. - */ - void insert( long nPos, const chr *pData, long nLen ) - { - if( nLen <= 0 ) - return; - if( nPos <= 0 ) - { - prepend( pData, nLen ); - } - else if( nPos >= core->nLength ) - { - append( pData, nLen ); - } - else - { - // If we're going to flatten anyway, might as well for everyone - flatten(); - _hardCopy(); - Chunk *p1 = core->newChunk( nPos ); - Chunk *p2 = core->newChunk( nLen ); - Chunk *p3 = core->newChunk( core->nLength-nPos ); - cpy( p1->pData, core->pFirst->pData, nPos ); - cpy( p2->pData, pData, nLen ); - cpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); - core->clear(); - core->appendChunk( p1 ); - core->appendChunk( p2 ); - core->appendChunk( p3 ); - } - } - - void insert( long nPos, const MyType &str ) - { - if( nPos <= 0 ) - { - prepend( str ); - } - else if( nPos >= core->nLength ) - { - append( str ); - } - else - { - flatten(); - _hardCopy(); - Chunk *p1 = core->newChunk( nPos ); - Chunk *p3 = core->newChunk( core->nLength-nPos ); - cpy( p1->pData, core->pFirst->pData, nPos ); - cpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); - core->clear(); - core->appendChunk( p1 ); - for( Chunk *pChnk = str.core->pFirst; pChnk; - pChnk = pChnk->pNext ) - { - core->appendChunk( core->copyChunk( pChnk ) ); - } - - core->appendChunk( p3 ); - } - } - - /** - *@todo This function shouldn't use strlen, we should add our own to - * this class, one that can be overridden in a specific implementation. - */ - void insert( long nPos, const chr *pData ) - { - insert( nPos, pData, Bu::strlen( pData ) ); - } - - void remove( long nPos, long nLen ) - { - if( nLen <= 0 || nPos < 0 || nPos >= core->nLength ) - return; - if( nLen > core->nLength-nPos ) - nLen = core->nLength-nPos; - flatten(); - _hardCopy(); - memmove( core->pFirst->pData+nPos, core->pFirst->pData+nPos+nLen, core->nLength-nPos-nLen+1 ); - core->nLength -= nLen; - core->pFirst->nLength -= nLen; - } - - /** - * Clear all data from the string. - */ - void clear() - { - _hardCopy(); - core->clear(); - } - - MyType replace( const MyType &fnd, const MyType &rep ) const - { - MyType out; - const_iterator o = begin(); - while( true ) - { - const_iterator i = o.find( fnd ); - if( !i ) - { - out.append( o ); - return out; - } - else - { - out.append( o, i ); - out.append( rep ); - o = i; - o += fnd.getSize(); - } - } - } - - /** - * Force the string to resize - *@param nNewSize (long) The new size of the string. - */ - void resize( long nNewSize ) - { - if( core->nLength == nNewSize ) - return; - if( nNewSize < 0 ) - nNewSize = 0; - - flatten(); - _hardCopy(); - - Chunk *pNew = core->newChunk( nNewSize ); - long nNewLen = (nNewSizenLength)?(nNewSize):(core->nLength); - if( core->nLength > 0 ) - { - cpy( pNew->pData, core->pFirst->pData, nNewLen ); - core->aChr.deallocate( core->pFirst->pData, core->pFirst->nLength+1 ); - core->aChunk.deallocate( core->pFirst, 1 ); - } - pNew->pData[nNewLen] = (chr)0; - core->pFirst = core->pLast = pNew; - core->nLength = nNewSize; - } - - /** - * Get the current size of the string. - *@returns (long) The current size of the string. - */ - long getSize() const - { - return core->nLength; - } - - /** - * Get a pointer to the string array. - *@returns (chr *) The string data. - */ - chr *getStr() - { - if( core->pFirst == NULL || core->nLength == 0 ) - return (chr *)""; - - flatten(); - _hardCopy(); - core->pFirst->pData[core->nLength] = (chr)0; - return core->pFirst->pData; - } - - /** - * Get a const pointer to the string array. - *@returns (const chr *) The string data. - */ - const chr *getStr() const - { - if( core->pFirst == NULL || core->nLength == 0 ) - return (chr *)""; - - flatten(); - core->pFirst->pData[core->nLength] = (chr)0; - return core->pFirst->pData; - } - - /** - * A convinience function, this one won't cause as much work as the - * non-const getStr, so if you're not changing the data, consider it. - */ - const chr *getConstStr() const - { - return getStr(); - } - - MyType getSubStrIdx( long iStart, long iSize=-1 ) const - { - if( iStart < 0 ) - iStart = 0; - if( iStart >= core->nLength ) - return (const chr[]){(chr)0}; - if( iSize < 0 ) - iSize = core->nLength; - if( iStart+iSize > core->nLength ) - iSize = core->nLength-iStart; - if( iSize == 0 ) - return (const chr[]){(chr)0}; - - flatten(); - MyType ret( core->pFirst->pData+iStart, iSize ); - return ret; - } - - MyType getSubStr( const_iterator iBegin, - const_iterator iEnd=typename MyType::const_iterator() ) const - { - if( !iBegin.isValid() ) - return MyType(); - if( iBegin.pChunk == iEnd.pChunk ) - { - return MyType( iBegin.pChunk->pData+iBegin.iPos, - iEnd.iPos-iBegin.iPos ); - } - else if( !iEnd.isValid() ) - { - MyType ret; - ret.append( - iBegin.pChunk->pData+iBegin.iPos, - iBegin.pChunk->nLength-iBegin.iPos - ); - for( Chunk *pCur = iBegin.pChunk->pNext; - pCur; pCur = pCur->pNext ) - { - ret.append( pCur->pData, pCur->nLength ); - } - return ret; - } - else - { - MyType ret; - ret.append( - iBegin.pChunk->pData+iBegin.iPos, - iBegin.pChunk->nLength-iBegin.iPos - ); - for( Chunk *pCur = iBegin.pChunk->pNext; - pCur != iEnd.pChunk; pCur = pCur->pNext ) - { - ret.append( pCur->pData, pCur->nLength ); - } - ret.append( - iEnd.pChunk->pData, - iEnd.iPos - ); - return ret; - } - } - - Bu::List split( const chr c ) const - { - Bu::List ret; - const_iterator l, r; - l = begin(); - for(r=l; l;) - { - for( r = l; r && r != c; r++ ) { } - ret.append( MyType( l, r ) ); - l = r; - l++; - } - return ret; - } - - /** - * Plus equals operator for FString. - *@param pData (const chr *) The data to append to your FString. - */ - MyType &operator+=( const chr *pData ) - { - append( pData ); - - return (*this); - } - - /** - * Plus equals operator for FString. - *@param rSrc (const MyType &) The FString to append to your FString. - */ - MyType &operator+=( const MyType &rSrc ) - { - append( rSrc ); - - return (*this); - } - - MyType &operator+=( const MyType::const_iterator &i ) - { - append( i, i+1 ); - - return (*this); - } - - /** - * Plus equals operator for FString. - *@param cData (const chr) The character to append to your FString. - */ - MyType &operator+=( const chr cData ) - { - if( core->pLast && core->pLast->nLength < nMinSize ) - { - _hardCopy(); - core->pLast->pData[core->pLast->nLength] = cData; - ++core->pLast->nLength; ++core->nLength; - // pLast->pData[pLast->nLength] = (chr)0; - } - else - { - append( &cData, 1 ); - } - //append( pData ); - - return (*this); - } - - /** - * Assignment operator. - *@param pData (const chr *) The character array to append to your - * FString. - */ - MyType &operator=( const chr *pData ) - { - set( pData ); - - return (*this); - } - - MyType operator+( const MyType &rRight ) const - { - MyType ret( *this ); - ret.append( rRight ); - return ret; - } - - MyType operator+( const chr *pRight ) const - { - MyType ret( *this ); - ret.append( pRight ); - return ret; - } - - MyType operator+( chr *pRight ) const - { - MyType ret( *this ); - ret.append( pRight ); - return ret; - } - - /** - * Reset your FString to this character array. - *@param pData (const chr *) The character array to set your FString to. - */ - void set( const chr *pData ) - { - clear(); - append( pData ); - } - - /** - * Reset your FString to this character array. - *@param pData (const chr *) The character array to set your FString to. - *@param nSize (long) The length of the inputted character array. - */ - void set( const chr *pData, long nSize ) - { - clear(); - append( pData, nSize ); - } - - void set( const chr *pData, long nStart, long nSize ) - { - clear(); - append( pData, nStart, nSize ); - } - - void set( const MyType &rData ) - { - clear(); - append( rData ); - } - - void set( const MyType &rData, long nSize ) - { - clear(); - append( rData, nSize ); - } - - void set( const MyType &rData, long nStart, long nSize ) - { - clear(); - append( rData, nStart, nSize ); - } - - void set( const_iterator s ) - { - clear(); - append( s ); - } - - void set( const_iterator s, const_iterator e ) - { - clear(); - append( s, e ); - } - - /** - * Resize the string, possibly to make room for a copy. At the moment - * this operation *is* destructive. What was in the string will in no - * way be preserved. This is, however, very fast. If you want to - * keep your data check out resize. - *@param iSize the new size in bytes. The string is guranteed to have - * at least this much contiguous space available when done. - */ - void setSize( long iSize ) - { - _hardCopy(); - core->clear(); - core->appendChunk( core->newChunk( iSize ) ); - } - - void expand() - { -#ifndef WIN32 - flatten(); - _hardCopy(); - - wordexp_t result; - - /* Expand the string for the program to run. */ - switch (wordexp ((char *)core->pFirst->pData, &result, 0)) - { - case 0: /* Successful. */ - { - set( (chr *)result.we_wordv[0] ); - wordfree( &result ); - return; - } - break; - case WRDE_NOSPACE: - /* If the error was `WRDE_NOSPACE', - then perhaps part of the result was allocated. */ - wordfree (&result); - default: /* Some other error. */ - return; - } -#endif - } - - /** - * Assignment operator. - *@param rSrc (const MyType &) The FString to set your FString to. - */ - /* MyType &operator=( const MyType &rSrc ) - { - set( rSrc ); - - return (*this); - } */ - - /** - * Equals comparison operator. - *@param pData (const chr *) The character array to compare your FString - * to. - */ - bool operator==( const chr *pData ) const - { - if( core->pFirst == NULL || core->nLength == 0 ) { - if( pData == NULL ) - return true; - if( pData[0] == (chr)0 ) - return true; - return false; - } - - flatten(); - core->pFirst->pData[core->nLength] = (chr)0; - const chr *a = pData; - chr *b = core->pFirst->pData; - for( long j = 0; *a!=(chr)0 || *b!=(chr)0; j++, a++, b++ ) - { - if( *a != *b ) - return false; - if( *a == (chr)0 && j < core->nLength ) - return false; - } - - return true; - } - - /** - * Equals comparison operator. - *@param pData (const MyType &) The FString to compare your FString to. - */ - bool operator==( const MyType &pData ) const - { - if( core == pData.core ) - return true; - if( core->pFirst == pData.core->pFirst ) - return true; - if( (core->nLength == 0 && pData.core->nLength == 0) ) - return true; - if( core->nLength != pData.core->nLength ) - return false; - if( pData.core->pFirst == NULL || core->pFirst == NULL ) - return false; - - flatten(); - pData.flatten(); - const chr *a = pData.core->pFirst->pData; - chr *b = core->pFirst->pData; - for( long j = 0; j < core->nLength; j++, a++, b++ ) - { - if( *a != *b ) - return false; - } - - return true; - } - - /** - * Not equals comparison operator. - *@param pData (const chr *) The character array to compare your FString - * to. - */ - bool operator!=(const chr *pData ) const - { - return !(*this == pData); - } - - /** - * Not equals comparison operator. - *@param pData (const MyType &) The FString to compare your FString to. - */ - bool operator!=(const MyType &pData ) const - { - return !(*this == pData); - } - - bool operator<(const MyType &pData ) const - { - flatten(); - pData.flatten(); - - const chr *a = core->pFirst->pData; - chr *b = pData.core->pFirst->pData; - for( long j = 0; j < core->nLength; j++, a++, b++ ) - { - if( *a != *b ) - return *a < *b; - } - - return false; - } - - bool operator<=(const MyType &pData ) const - { - flatten(); - pData.flatten(); - - const chr *a = core->pFirst->pData; - chr *b = pData.core->pFirst->pData; - for( long j = 0; j < core->nLength; j++, a++, b++ ) - { - if( *a != *b ) - return *a < *b; - } - - return true; - } - - bool operator>(const MyType &pData ) const - { - flatten(); - pData.flatten(); - - const chr *a = core->pFirst->pData; - chr *b = pData.core->pFirst->pData; - for( long j = 0; j < core->nLength; j++, a++, b++ ) - { - if( *a != *b ) - return *a > *b; - } - - return false; - } - - bool operator>=(const MyType &pData ) const - { - flatten(); - pData.flatten(); - - const chr *a = core->pFirst->pData; - chr *b = pData.core->pFirst->pData; - for( long j = 0; j < core->nLength; j++, a++, b++ ) - { - if( *a != *b ) - return *a > *b; - } - - return true; - } - - /** - * Indexing operator - *@param nIndex (long) The index of the character you want. - *@returns (chr &) The character at position (nIndex). - */ - chr &operator[]( long nIndex ) - { - if( nIndex < 0 || nIndex >= core->nLength ) - throw Bu::ExceptionBase("Index out of range."); - flatten(); - _hardCopy(); - - return core->pFirst->pData[nIndex]; - } - - /** - * Const indexing operator - *@param nIndex (long) The index of the character you want. - *@returns (const chr &) The character at position (nIndex). - */ - const chr &operator[]( long nIndex ) const - { - if( nIndex < 0 || nIndex >= core->nLength ) - throw Bu::ExceptionBase("Index out of range."); - flatten(); - - return core->pFirst->pData[nIndex]; - } -/* - operator const chr *() const - { - if( !pFirst ) return NULL; - flatten(); - return pFirst->pData; - } - */ - /* - operator bool() const - { - return (core->pFirst != NULL); - } - */ - - bool isSet() const - { - return (core->pFirst != NULL); - } - - bool compareSub( const chr *pData, long nIndex, long nLen ) const - { - if( core->pFirst == NULL || core->nLength == 0 ) { - if( pData == NULL ) - return true; - if( nLen == 0 ) - return true; - if( pData[0] == (chr)0 ) - return true; - return false; - } - if( nIndex+nLen > core->nLength ) - return false; - - flatten(); - core->pFirst->pData[core->nLength] = (chr)0; - const chr *a = pData; - chr *b = core->pFirst->pData+nIndex; - for( long j = 0; j < nLen; j++, a++, b++ ) - { - if( *a != *b ) - return false; - if( *a == (chr)0 && j < core->nLength ) - return false; - } - - return true; - } - - bool compareSub( const MyType &rData, long nIndex, long nLen ) const - { - if( core->pFirst == NULL || core->nLength == 0 || rData.core->pFirst == NULL || rData.core->nLength == 0 ) - return false; - if( nLen < 0 ) - nLen = rData.core->nLength; - if( nIndex+nLen > core->nLength ) - return false; - - flatten(); - rData.flatten(); - const chr *a = rData.core->pFirst->pData; - chr *b = core->pFirst->pData + nIndex; - for( long j = 0; j < nLen; j++, a++, b++ ) - { - if( *a != *b ) - return false; - } - - return true; - } - - /** - * Is the character at index (nIndex) white space? - *@param nIndex (long) The index of the character you want to check. - *@returns (bool) Is it white space? - */ - bool isWS( long nIndex ) const - { - flatten(); - - return core->pFirst->pData[nIndex]==' ' || core->pFirst->pData[nIndex]=='\t' - || core->pFirst->pData[nIndex]=='\r' || core->pFirst->pData[nIndex]=='\n'; - } - - /** - * Is the character at index (nIndex) a letter? - *@param nIndex (long) The index of the character you want to check. - *@returns (bool) Is it a letter? - */ - bool isAlpha( long nIndex ) const - { - flatten(); - - return (core->pFirst->pData[nIndex] >= 'a' && core->pFirst->pData[nIndex] <= 'z') - || (core->pFirst->pData[nIndex] >= 'A' && core->pFirst->pData[nIndex] <= 'Z'); - } - - /** - * Convert your alpha characters to lower case. - */ - void toLower() - { - flatten(); - _hardCopy(); - - for( long j = 0; j < core->nLength; j++ ) - { - if( core->pFirst->pData[j] >= 'A' && core->pFirst->pData[j] <= 'Z' ) - core->pFirst->pData[j] -= 'A'-'a'; - } - } - - /** - * Convert your alpha characters to upper case. - */ - void toUpper() - { - flatten(); - _hardCopy(); - - for( long j = 0; j < core->nLength; j++ ) - { - if( core->pFirst->pData[j] >= 'a' && core->pFirst->pData[j] <= 'z' ) - core->pFirst->pData[j] += 'A'-'a'; - } - } - -// template -// void to( out &dst ); -/* { - flatten(); - - dst = strtol( pFirst->pData, NULL, 0 ); - } */ - - const_iterator find( const chr cChar, - const_iterator iStart=typename MyType::const_iterator() ) const - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( cChar == *iStart ) - return iStart; - } - return end(); - } - - const_iterator find( const chr *sText, int nLen, - const_iterator iStart=typename MyType::const_iterator() ) const - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( sText, nLen ) ) - return iStart; - } - return end(); - } - - const_iterator find( const MyType &rStr, - const_iterator iStart=typename MyType::const_iterator() ) const - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( rStr ) ) - return iStart; - } - return end(); - } - - const_iterator find( const MyType &rStr, int nLen, - const_iterator iStart=typename MyType::const_iterator() ) const - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( rStr, nLen ) ) - return iStart; - } - return end(); - } - - iterator find( const chr cChar, - const_iterator iStart=typename MyType::const_iterator() ) - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( cChar == *iStart ) - return iterator( iStart.pChunk, iStart.iPos ); - } - return end(); - } - - iterator find( const chr *sText, int nLen, - const_iterator iStart=typename MyType::const_iterator() ) - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( sText, nLen ) ) - return iterator( iStart.pChunk, iStart.iPos ); - } - return end(); - } - - iterator find( const MyType &rStr, - const_iterator iStart=typename MyType::const_iterator() ) - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( rStr ) ) - return iterator( iStart.pChunk, iStart.iPos ); - } - return end(); - } - - iterator find( const MyType &rStr, int nLen, - const_iterator iStart=typename MyType::const_iterator() ) - { - if( !iStart ) iStart = begin(); - for( ; iStart; iStart++ ) - { - if( iStart.compare( rStr, nLen ) ) - return iterator( iStart.pChunk, iStart.iPos ); - } - return end(); - } - - /** - * Find the index of the first occurrance of cChar - *@param cChar The character to search for. - *@param iStart The position in the string to start searching from. - *@returns (long) The index of the first occurrance. -1 for not found. - */ - long findIdx( const chr cChar, long iStart=0 ) const - { - flatten(); - for( long j = iStart; j < core->pFirst->nLength; j++ ) - { - if( core->pFirst->pData[j] == cChar ) - return j; - } - return -1; - } - - /** - * Find the index of the first occurrance of sText - *@param sText The null-terminated string to search for. - *@param iStart The position in the string to start searching from. - *@returns The index of the first occurrance. -1 for not found. - */ - long findIdx( const chr *sText, long iStart=0 ) const - { - long nTLen = strlen( sText ); - flatten(); - for( long j = iStart; j < core->pFirst->nLength-nTLen; j++ ) - { - if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) - return j; - } - return -1; - } - - /** - * Do a reverse search for (sText) - *@param sText (const chr *) The string to search for. - *@returns (long) The index of the last occurrance. -1 for not found. - */ - long rfindIdx( const chr *sText ) const - { - long nTLen = strlen( sText ); - flatten(); - for( long j = core->pFirst->nLength-nTLen-1; j >= 0; j-- ) - { - if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) - return j; - } - return -1; - } - - /** - * Remove nAmnt bytes from the front of the string. This function - * operates in O(n) time and should be used sparingly. - */ - void trimFront( long nAmnt ) - { - long nNewLen = core->nLength - nAmnt; - flatten(); - Chunk *pNew = core->newChunk( nNewLen ); - cpy( pNew->pData, core->pFirst->pData+nAmnt, nNewLen ); - _hardCopy(); - core->clear(); - core->appendChunk( pNew ); - } - - void trimBack( chr c ) - { - if( core->pFirst == NULL || core->nLength == 0 ) - return; - flatten(); - for( ; core->pFirst->nLength > 0 && core->pFirst->pData[core->pFirst->nLength-1] == c; core->pFirst->nLength--, core->nLength-- ) { } - } - - MyType &format( const char *sFrmt, ...) - { - _hardCopy(); - clear(); - - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = core->newChunk( iLen ); - vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); - core->appendChunk( pNew ); - - va_end( ap ); - - return *this; - } - - MyType &formatAppend( const char *sFrmt, ...) - { - _hardCopy(); - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = core->newChunk( iLen ); - vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); - core->appendChunk( pNew ); - - va_end( ap ); - - return *this; - } - - MyType &formatPrepend( const char *sFrmt, ...) - { - _hardCopy(); - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = core->newChunk( iLen ); - vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); - core->prependChunk( pNew ); - - va_end( ap ); - - return *this; - } - - iterator begin() - { - if( core->nLength == 0 ) - return iterator( NULL, 0 ); - return iterator( core->pFirst, 0 ); - } - - const_iterator begin() const - { - if( core->nLength == 0 ) - return const_iterator( NULL, 0 ); - return iterator( core->pFirst, 0 ); - } - - iterator end() - { - return iterator( NULL, 0 ); - } - - const_iterator end() const - { - return const_iterator( NULL, 0 ); - } - - bool isEmpty() const - { - if( core->nLength == 0 ) - return true; - return false; - } - - private: - void flatten() const - { - if( isFlat() ) - return; - - if( core->pFirst == NULL || core->nLength == 0 ) - return; - - Chunk *pNew = core->newChunk( core->nLength ); - chr *pos = pNew->pData; - Chunk *i = core->pFirst; - for(;;) - { - cpy( pos, i->pData, i->nLength ); - pos += i->nLength; - i = i->pNext; - if( i == NULL ) - break; - } - core->clear(); - - core->pLast = core->pFirst = pNew; - core->nLength = pNew->nLength; - } - - bool isFlat() const - { - return (core->pFirst == core->pLast); - } - }; - - template FBasicString operator+( const T *pLeft, const FBasicString &rRight ) - { - Bu::FBasicString ret( pLeft ); - ret.append( rRight ); - return ret; - } - - template - ArchiveBase &operator<<( ArchiveBase &ar, const FBasicString &s ) - { - long n = s.getSize(); - ar << n; - ar.write( s.getConstStr(), n ); - return ar; - } - - template - ArchiveBase &operator>>( ArchiveBase &ar, FBasicString &s ) - { - long n; - ar >> n; - s.setSize( n ); - ar.read( s.getStr(), n ); - return ar; - } -} - -#undef cpy - -#endif diff --git a/src/fifo.cpp b/src/fifo.cpp index d1fa960..d6106cc 100644 --- a/src/fifo.cpp +++ b/src/fifo.cpp @@ -16,7 +16,7 @@ namespace Bu { subExceptionDef( FifoException ) } -Bu::Fifo::Fifo( const Bu::FString &sName, int iFlags, mode_t mAcc ) : +Bu::Fifo::Fifo( const Bu::String &sName, int iFlags, mode_t mAcc ) : iFlags( iFlags ), iIn( -1 ), iOut( -1 ) diff --git a/src/fifo.h b/src/fifo.h index fc70b2c..140e966 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -13,7 +13,7 @@ #include #include "bu/stream.h" -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/exceptionbase.h" namespace Bu @@ -27,7 +27,7 @@ namespace Bu class Fifo : public Bu::Stream { public: - Fifo( const Bu::FString &sName, int iFlags, mode_t mAcc=-1 ); + Fifo( const Bu::String &sName, int iFlags, mode_t mAcc=-1 ); virtual ~Fifo(); virtual void close(); diff --git a/src/file.cpp b/src/file.cpp index 008b88e..6634a62 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -17,7 +17,7 @@ namespace Bu { subExceptionDef( FileException ) } -Bu::File::File( const Bu::FString &sName, int iFlags ) : +Bu::File::File( const Bu::String &sName, int iFlags ) : fd( -1 ), bEos( true ) { @@ -187,7 +187,7 @@ void Bu::File::setBlocking( bool bBlocking ) #endif } -Bu::File Bu::File::tempFile( Bu::FString &sName ) +Bu::File Bu::File::tempFile( Bu::String &sName ) { uint32_t iX; iX = time( NULL ) + getpid(); diff --git a/src/file.h b/src/file.h index b2cd2a4..81c1592 100644 --- a/src/file.h +++ b/src/file.h @@ -12,7 +12,7 @@ #include #include "bu/stream.h" -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/exceptionbase.h" namespace Bu @@ -26,7 +26,7 @@ namespace Bu class File : public Bu::Stream { public: - File( const Bu::FString &sName, int iFlags ); + File( const Bu::String &sName, int iFlags ); File( int fd ); virtual ~File(); @@ -75,12 +75,12 @@ namespace Bu /** * Create a temp file and return its handle. The file is opened * Read/Write. - *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" + *@param sName (Bu::String) Give in the form: "/tmp/tmpfileXXXXXXXX" * It will alter your (sName) setting the 'X's to random * characters. *@returns (Bu::File) A file object representing your temp file. */ - static Bu::File tempFile( Bu::FString &sName ); + static Bu::File tempFile( Bu::String &sName ); #ifndef WIN32 /** diff --git a/src/formatter.cpp b/src/formatter.cpp index 7eaa1e2..9288e91 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -21,7 +21,7 @@ Bu::Formatter::~Formatter() { } -void Bu::Formatter::write( const Bu::FString &sStr ) +void Bu::Formatter::write( const Bu::String &sStr ) { rStream.write( sStr ); } @@ -31,7 +31,7 @@ void Bu::Formatter::write( const void *sStr, int iLen ) rStream.write( sStr, iLen ); } -void Bu::Formatter::writeAligned( const Bu::FString &sStr ) +void Bu::Formatter::writeAligned( const Bu::String &sStr ) { int iLen = sStr.getSize(); if( iLen > fLast.uMinWidth ) @@ -117,9 +117,9 @@ void Bu::Formatter::read( void *sStr, int iLen ) rStream.read( sStr, iLen ); } -Bu::FString Bu::Formatter::readToken() +Bu::String Bu::Formatter::readToken() { - Bu::FString sRet; + Bu::String sRet; if( fLast.bTokenize ) { for(;;) @@ -292,7 +292,7 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &f, char *sStr ) return f; } -Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::FString &sStr ) +Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::String &sStr ) { f.writeAligned( sStr ); return f; @@ -388,7 +388,7 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &f, bool b ) return f; } -Bu::Formatter &Bu::operator>>( Bu::Formatter &f, Bu::FString &sStr ) +Bu::Formatter &Bu::operator>>( Bu::Formatter &f, Bu::String &sStr ) { sStr = f.readToken(); return f; @@ -480,7 +480,7 @@ Bu::Formatter &Bu::operator>>( Bu::Formatter &f, long double &flt ) Bu::Formatter &Bu::operator>>( Bu::Formatter &f, bool &b ) { - Bu::FString sStr = f.readToken(); + Bu::String sStr = f.readToken(); if( !sStr.isSet() ) return f; char c = *sStr.begin(); diff --git a/src/formatter.h b/src/formatter.h index 7e0c54b..fb51c81 100644 --- a/src/formatter.h +++ b/src/formatter.h @@ -103,13 +103,13 @@ namespace Bu unsigned short bTokenize : 1; } Fmt; - void write( const Bu::FString &sStr ); + void write( const Bu::String &sStr ); void write( const void *sStr, int iLen ); - void writeAligned( const Bu::FString &sStr ); + void writeAligned( const Bu::String &sStr ); void writeAligned( const char *sStr, int iLen ); void read( void *sStr, int iLen ); - Bu::FString readToken(); + Bu::String readToken(); void incIndent(); void decIndent(); @@ -199,7 +199,7 @@ namespace Bu template void ffmt( type f ) { - Bu::FString fTmp; + Bu::String fTmp; fTmp.format("%f", f ); // writeAligned("**make floats work**"); writeAligned( fTmp ); @@ -207,7 +207,7 @@ namespace Bu } template - void iparse( type &i, const Bu::FString &sBuf ) + void iparse( type &i, const Bu::String &sBuf ) { if( !sBuf.isSet() ) return; @@ -233,7 +233,7 @@ namespace Bu } template - void uparse( type &i, const Bu::FString &sBuf ) + void uparse( type &i, const Bu::String &sBuf ) { if( !sBuf.isSet() ) return; @@ -257,7 +257,7 @@ namespace Bu } template - void fparse( type &f, const Bu::FString &sBuf ) + void fparse( type &f, const Bu::String &sBuf ) { sscanf( sBuf.getStr(), "%f", &f ); usedFormat(); @@ -288,7 +288,7 @@ namespace Bu Formatter &operator<<( Formatter &f, Formatter::Special s ); Formatter &operator<<( Formatter &f, const char *sStr ); Formatter &operator<<( Formatter &f, char *sStr ); - Formatter &operator<<( Formatter &f, const Bu::FString &sStr ); + Formatter &operator<<( Formatter &f, const Bu::String &sStr ); Formatter &operator<<( Formatter &f, signed char c ); Formatter &operator<<( Formatter &f, char c ); Formatter &operator<<( Formatter &f, unsigned char c ); @@ -305,7 +305,7 @@ namespace Bu Formatter &operator<<( Formatter &f, long double flt ); Formatter &operator<<( Formatter &f, bool b ); - Formatter &operator>>( Formatter &f, Bu::FString &sStr ); + Formatter &operator>>( Formatter &f, Bu::String &sStr ); Formatter &operator>>( Formatter &f, signed char &c ); Formatter &operator>>( Formatter &f, char &c ); Formatter &operator>>( Formatter &f, unsigned char &c ); diff --git a/src/formula.h b/src/formula.h index d93e27b..757884f 100644 --- a/src/formula.h +++ b/src/formula.h @@ -17,7 +17,7 @@ #include "bu/stack.h" #include "bu/exceptionbase.h" #include "bu/hash.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -41,8 +41,8 @@ namespace Bu virtual prec operator()( prec )=0; }; - typedef Hash varHash; - typedef Hash funcHash; + typedef Hash varHash; + typedef Hash funcHash; Formula() { @@ -57,7 +57,7 @@ namespace Bu } } - prec run( const Bu::FString &sFormulaSrc ) + prec run( const Bu::String &sFormulaSrc ) { if( sFormulaSrc.isEmpty() ) throw FormulaException("Empty formula, nothing to do."); @@ -158,7 +158,7 @@ namespace Bu Bu::Stack sOper; Bu::Stack sValue; - Bu::Stack sFunc; + Bu::Stack sFunc; private: symType getPrec( symType nOper ) diff --git a/src/fstring.cpp b/src/fstring.cpp deleted file mode 100644 index a3e0cb1..0000000 --- a/src/fstring.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2007-2010 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#define BU_TRACE -#include "bu/trace.h" - -#include "bu/fstring.h" -#include "bu/hash.h" - -template class Bu::FBasicString; - -template<> uint32_t Bu::__calcHashCode( const Bu::FString &k ) -{ - long j, sz = k.getSize(); - const char *s = k.getStr(); - - long nPos = 0; - for( j = 0; j < sz; j++, s++ ) - { - nPos = *s + (nPos << 6) + (nPos << 16) - nPos; - } - - return nPos; -} - -template<> bool Bu::__cmpHashKeys( - const Bu::FString &a, const Bu::FString &b ) -{ - return a == b; -} - -template<> void Bu::__tracer_format( const Bu::FString &v ) -{ - printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); -} - -bool &Bu::operator<<( bool &dst, const Bu::FString &sIn ) -{ - if( sIn == "true" || sIn == "yes" || sIn == "t" ) - dst = true; - else - dst = false; - - return dst; -} - -uint8_t &Bu::operator<<( uint8_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%hhu", &dst ); - return dst; -} - -int8_t &Bu::operator<<( int8_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%hhd", &dst ); - return dst; -} - -char &Bu::operator<<( char &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%hhd", &dst ); - return dst; -} - -uint16_t &Bu::operator<<( uint16_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%hu", &dst ); - return dst; -} - -int16_t &Bu::operator<<( int16_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%hd", &dst ); - return dst; -} - -uint32_t &Bu::operator<<( uint32_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%u", &dst ); - return dst; -} - -int32_t &Bu::operator<<( int32_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%d", &dst ); - return dst; -} - -uint64_t &Bu::operator<<( uint64_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%llu", &dst ); - return dst; -} - -int64_t &Bu::operator<<( int64_t &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%lld", &dst ); - return dst; -} - -float &Bu::operator<<( float &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%f", &dst ); - return dst; -} - -double &Bu::operator<<( double &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%lf", &dst ); - return dst; -} - -long double &Bu::operator<<( long double &dst, const Bu::FString &sIn ) -{ - sscanf( sIn.getStr(), "%Lf", &dst ); - return dst; -} - -Bu::FString &Bu::operator<<( Bu::FString &dst, const Bu::FString &sIn ) -{ - dst = sIn; - return dst; -} - diff --git a/src/fstring.h b/src/fstring.h deleted file mode 100644 index 0f9d81a..0000000 --- a/src/fstring.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2007-2010 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_F_STRING_H -#define BU_F_STRING_H - -#include "bu/fbasicstring.h" - -namespace Bu -{ - typedef FBasicString FString; - - template - uint32_t __calcHashCode( const T &k ); - - template - bool __cmpHashKeys( const T &a, const T &b ); - - template<> uint32_t __calcHashCode( const FString &k ); - template<> bool __cmpHashKeys( - const FString &a, const FString &b ); - - template void __tracer_format( const t &v ); - template<> void __tracer_format( const FString &v ); - - bool &operator<<( bool &dst, const FString &sIn ); - uint8_t &operator<<( uint8_t &dst, const FString &sIn ); - int8_t &operator<<( int8_t &dst, const FString &sIn ); - char &operator<<( char &dst, const FString &sIn ); - uint16_t &operator<<( uint16_t &dst, const FString &sIn ); - int16_t &operator<<( int16_t &dst, const FString &sIn ); - uint32_t &operator<<( uint32_t &dst, const FString &sIn ); - int32_t &operator<<( int32_t &dst, const FString &sIn ); - uint64_t &operator<<( uint64_t &dst, const FString &sIn ); - int64_t &operator<<( int64_t &dst, const FString &sIn ); - float &operator<<( float &dst, const FString &sIn ); - double &operator<<( double &dst, const FString &sIn ); - long double &operator<<( long double &dst, const FString &sIn ); - Bu::FString &operator<<( Bu::FString &dst, const FString &sIn ); - -} - -/***** I dunno about this block, I don't really want to have it... ***** -#include -std::basic_ostream& operator<< (std::basic_ostream &os, - const Bu::FString &val ); -*/ - -#endif diff --git a/src/hash.h b/src/hash.h index 354569e..04c3e76 100644 --- a/src/hash.h +++ b/src/hash.h @@ -411,7 +411,7 @@ namespace Bu * In order to use it, I recommend the following for all basic usage: *@code // Define a Hash typedef with strings as keys and ints as values. - typedef Bu::Hash StrIntHash; + typedef Bu::Hash StrIntHash; // Create one StrIntHash hInts; diff --git a/src/httpget.cpp b/src/httpget.cpp index 2347167..673cdd6 100644 --- a/src/httpget.cpp +++ b/src/httpget.cpp @@ -7,7 +7,7 @@ #include "bu/httpget.h" -Bu::HttpGet::HttpGet( const Bu::Url &uSrc, const Bu::FString &sMethod ) : +Bu::HttpGet::HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod ) : uSrc( uSrc ), sMethod( sMethod ), sSrv( uSrc.getHost(), uSrc.getPort() ) diff --git a/src/httpget.h b/src/httpget.h index 783f880..58982c0 100644 --- a/src/httpget.h +++ b/src/httpget.h @@ -9,7 +9,7 @@ #define BU_HTTP_GET_H #include "bu/stream.h" -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/url.h" #include "bu/tcpsocket.h" #include "bu/hash.h" @@ -19,7 +19,7 @@ namespace Bu class HttpGet : public Bu::Stream { public: - HttpGet( const Bu::Url &uSrc, const Bu::FString &sMethod="GET" ); + HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod="GET" ); virtual ~HttpGet(); void get(); @@ -51,9 +51,9 @@ namespace Bu private: Bu::Url uSrc; - Bu::FString sMethod; + Bu::String sMethod; Bu::TcpSocket sSrv; - typedef Bu::Hash MimeHash; + typedef Bu::Hash MimeHash; MimeHash hMimeIn; MimeHash hMimeOut; }; diff --git a/src/itoserver.cpp b/src/itoserver.cpp index ea737bf..80e5bfb 100644 --- a/src/itoserver.cpp +++ b/src/itoserver.cpp @@ -47,7 +47,7 @@ void Bu::ItoServer::addPort( int nPort, int nPoolSize ) hServers.insert( nSocket, s ); } -void Bu::ItoServer::addPort( const FString &sAddr, int nPort, int nPoolSize ) +void Bu::ItoServer::addPort( const String &sAddr, int nPort, int nPoolSize ) { TcpServerSocket *s = new TcpServerSocket( sAddr, nPort, nPoolSize ); int nSocket = s->getSocket(); @@ -163,7 +163,7 @@ void Bu::ItoServer::ItoClient::run() while( !qMsg.isEmpty() ) { imProto.lock(); - Bu::FString *pMsg = qMsg.dequeue(); + Bu::String *pMsg = qMsg.dequeue(); pClient->onMessage( *pMsg ); delete pMsg; pClient->processOutput(); @@ -205,7 +205,7 @@ Bu::ItoServer::SrvClientLink::~SrvClientLink() { } -void Bu::ItoServer::SrvClientLink::sendMessage( const Bu::FString &sMsg ) +void Bu::ItoServer::SrvClientLink::sendMessage( const Bu::String &sMsg ) { if( !pClient->imProto.trylock() ) { @@ -215,7 +215,7 @@ void Bu::ItoServer::SrvClientLink::sendMessage( const Bu::FString &sMsg ) } else { - Bu::FString *pMsg = new Bu::FString( sMsg ); + Bu::String *pMsg = new Bu::String( sMsg ); pClient->qMsg.enqueue( pMsg ); } } diff --git a/src/itoserver.h b/src/itoserver.h index 81e42cc..83e7552 100644 --- a/src/itoserver.h +++ b/src/itoserver.h @@ -14,7 +14,7 @@ #include #endif -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/list.h" #include "bu/ito.h" #include "bu/itomutex.h" @@ -59,7 +59,7 @@ namespace Bu virtual ~ItoServer(); void addPort( int nPort, int nPoolSize=40 ); - void addPort( const FString &sAddr, int nPort, int nPoolSize=40 ); + void addPort( const String &sAddr, int nPort, int nPoolSize=40 ); //void scan(); void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); @@ -82,7 +82,7 @@ namespace Bu int nTimeoutSec, int nTimeoutUSec ); virtual ~ItoClient(); - typedef ItoQueue StringQueue; + typedef ItoQueue StringQueue; StringQueue qMsg; protected: @@ -105,7 +105,7 @@ namespace Bu SrvClientLink( ItoClient *pClient ); virtual ~SrvClientLink(); - virtual void sendMessage( const Bu::FString &sMsg ); + virtual void sendMessage( const Bu::String &sMsg ); private: ItoClient *pClient; diff --git a/src/lexer.cpp b/src/lexer.cpp index af9a23f..5db6bbc 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -18,7 +18,7 @@ Bu::Lexer::Token::Token( Bu::Lexer::TokenType iToken ) : { } -Bu::FString Bu::Lexer::tokenToString( const Bu::Lexer::Token &t ) +Bu::String Bu::Lexer::tokenToString( const Bu::Lexer::Token &t ) { Bu::MemBuf mb; Bu::Formatter f( mb ); diff --git a/src/lexer.h b/src/lexer.h index 9840afe..f4e0479 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -44,7 +44,7 @@ namespace Bu virtual Token *nextToken()=0; - virtual Bu::FString tokenToString( const Token &t ); + virtual Bu::String tokenToString( const Token &t ); }; }; diff --git a/src/logger.cpp b/src/logger.cpp index 9f734a9..eb5ac2d 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -69,7 +69,7 @@ void Bu::Logger::log( uint32_t nLevel, const char *sFile, const char *sFunction, #endif } -void Bu::Logger::setFormat( const Bu::FString &str ) +void Bu::Logger::setFormat( const Bu::String &str ) { sLogFormat = ""; @@ -93,7 +93,7 @@ void Bu::Logger::setFormat( const Bu::FString &str ) if( *s == '%' ) { sLogFormat += '%'; - Bu::FString sBuf; + Bu::String sBuf; for(;;) { s++; @@ -166,10 +166,10 @@ void Bu::Logger::hexDump( uint32_t nLevel, const char *sFile, log( nLevel, sFile, sFunction, nLine, "Displaying %ld bytes of %s.", nDataLen, lpName ); const unsigned char *pData = (const unsigned char *)pDataV; int j = 0; - Bu::FString sBorder; + Bu::String sBorder; for( int l = 0; l < 8*3+2*8+2+5; l++ ) sBorder += ((l!=11&&l!=37)?("-"):("+")); log( nLevel, sFile, sFunction, nLine, sBorder.getStr() ); - Bu::FString sLine; + Bu::String sLine; for(;;) { { diff --git a/src/logger.h b/src/logger.h index 6a7a2d5..9a4b030 100644 --- a/src/logger.h +++ b/src/logger.h @@ -9,7 +9,7 @@ #define BU_LOGGER_H #include "bu/singleton.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -78,7 +78,7 @@ namespace Bu public: void log( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const char *sFormat, ...); - void setFormat( const Bu::FString &str ); + void setFormat( const Bu::String &str ); void setMask( uint32_t n ); void setLevel( uint32_t n ); uint32_t getMask(); @@ -86,7 +86,7 @@ namespace Bu void hexDump( uint32_t nLevel, const char *sFile, const char *sFunction, int nLine, const void *pData, long nDataLen, const char *lpName ); private: - Bu::FString sLogFormat; + Bu::String sLogFormat; uint32_t nLevelMask; }; } diff --git a/src/md5.cpp b/src/md5.cpp index abf4bfa..db70ddc 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -60,7 +60,7 @@ void Bu::Md5::reset() iFill = 0; } -void Bu::Md5::setSalt( const Bu::FString & /*sSalt*/ ) +void Bu::Md5::setSalt( const Bu::String & /*sSalt*/ ) { } @@ -84,11 +84,11 @@ void Bu::Md5::addData( const void *sVData, int iSize ) iBytes += iSize; } -Bu::FString Bu::Md5::getResult() +Bu::String Bu::Md5::getResult() { long lsum[4]; compCap( lsum ); - return Bu::FString( (const char *)lsum, 4*4 ); + return Bu::String( (const char *)lsum, 4*4 ); } void Bu::Md5::writeResult( Bu::Stream &sOut ) diff --git a/src/md5.h b/src/md5.h index 79b1d09..d43574d 100644 --- a/src/md5.h +++ b/src/md5.h @@ -26,10 +26,10 @@ namespace Bu virtual ~Md5(); virtual void reset(); - virtual void setSalt( const Bu::FString &sSalt ); + virtual void setSalt( const Bu::String &sSalt ); virtual void addData( const void *sData, int iSize ); using Bu::CryptoHash::addData; - virtual FString getResult(); + virtual String getResult(); virtual void writeResult( Bu::Stream &sOut ); private: diff --git a/src/membuf.cpp b/src/membuf.cpp index 1a6bf9a..2dc266f 100644 --- a/src/membuf.cpp +++ b/src/membuf.cpp @@ -14,7 +14,7 @@ Bu::MemBuf::MemBuf() : { } -Bu::MemBuf::MemBuf( const Bu::FString &str ) : +Bu::MemBuf::MemBuf( const Bu::String &str ) : sBuf( str ), nPos( 0 ) { @@ -149,12 +149,12 @@ void Bu::MemBuf::setSize( size iSize ) nPos = iSize; } -Bu::FString &Bu::MemBuf::getString() +Bu::String &Bu::MemBuf::getString() { return sBuf; } -void Bu::MemBuf::setString( const Bu::FString &sNewData ) +void Bu::MemBuf::setString( const Bu::String &sNewData ) { sBuf = sNewData; nPos = 0; diff --git a/src/membuf.h b/src/membuf.h index a75aca1..7faa956 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -12,7 +12,7 @@ #include "bu/config.h" #include "bu/stream.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { @@ -24,7 +24,7 @@ namespace Bu { public: MemBuf(); - MemBuf( const Bu::FString &str ); + MemBuf( const Bu::String &str ); virtual ~MemBuf(); virtual void close(); @@ -48,11 +48,11 @@ namespace Bu virtual void setBlocking( bool bBlocking=true ); virtual void setSize( size iSize ); - Bu::FString &getString(); - void setString( const Bu::FString &sNewData ); + Bu::String &getString(); + void setString( const Bu::String &sNewData ); private: - Bu::FString sBuf; + Bu::String sBuf; size nPos; }; } diff --git a/src/minicron.cpp b/src/minicron.cpp index 491d143..307880e 100644 --- a/src/minicron.cpp +++ b/src/minicron.cpp @@ -73,7 +73,7 @@ void Bu::MiniCron::poll() } } -Bu::MiniCron::JobId Bu::MiniCron::addJob( const Bu::FString &sName, +Bu::MiniCron::JobId Bu::MiniCron::addJob( const Bu::String &sName, Bu::MiniCron::CronSignal sigJob, const Bu::MiniCron::Timer &t ) { JobId jid = jidNext++; @@ -86,7 +86,7 @@ Bu::MiniCron::JobId Bu::MiniCron::addJob( const Bu::FString &sName, return jid; } -Bu::MiniCron::JobId Bu::MiniCron::addJobOnce( const Bu::FString &sName, +Bu::MiniCron::JobId Bu::MiniCron::addJobOnce( const Bu::String &sName, Bu::MiniCron::CronSignal sigJob, const Bu::MiniCron::Timer &t ) { JobId jid = jidNext++; @@ -132,7 +132,7 @@ Bu::MiniCron::JobInfoList Bu::MiniCron::getJobInfo() return lRet; } -Bu::MiniCron::Job::Job( const Bu::FString &sName, JobId jid, bool bRepeat ) : +Bu::MiniCron::Job::Job( const Bu::String &sName, JobId jid, bool bRepeat ) : sName( sName ), pTimer( NULL ), bContinue( bRepeat ), @@ -202,12 +202,12 @@ time_t Bu::MiniCron::Job::getNextRunTime() const return tNextRun; } -Bu::FString Bu::MiniCron::Job::getName() const +Bu::String Bu::MiniCron::Job::getName() const { return sName; } -Bu::MiniCron::JobInfo::JobInfo( const Bu::FString &sName, JobId jid, +Bu::MiniCron::JobInfo::JobInfo( const Bu::String &sName, JobId jid, time_t tNext ) : sName( sName ), jid( jid ), @@ -249,7 +249,7 @@ time_t Bu::MiniCron::TimerInterval::nextTime() return tRet; } -Bu::MiniCron::TimerBasic::TimerBasic( const Bu::FString &s ) : +Bu::MiniCron::TimerBasic::TimerBasic( const Bu::String &s ) : tLast( -1 ), sSpec( s ) { @@ -264,7 +264,7 @@ time_t Bu::MiniCron::TimerBasic::nextTime() if( tLast == -1 ) tLast = time( NULL ); - Bu::FString::const_iterator i = sSpec.begin(); + Bu::String::const_iterator i = sSpec.begin(); switch( lex( i ) ) { case tokDaily: @@ -343,19 +343,19 @@ time_t Bu::MiniCron::TimerBasic::nextTime() } Bu::MiniCron::TimerBasic::Token Bu::MiniCron::TimerBasic::lex( - Bu::FString::const_iterator &i ) + Bu::String::const_iterator &i ) { if( !i ) { return tokEos; } - Bu::FString::const_iterator b = i; + Bu::String::const_iterator b = i; for(; b && (*b == ' ' || *b == '\t'); b++ ) { i = b+1; } for(; b && *b != ' ' && *b != '\t'; b++ ) { } - Bu::FString sTok( i, b ); + Bu::String sTok( i, b ); i = b; if( sTok == "daily" ) @@ -412,7 +412,7 @@ Bu::MiniCron::TimerBasic::Token Bu::MiniCron::TimerBasic::lex( return tokErr; } -int Bu::MiniCron::TimerBasic::lexInt( Bu::FString::const_iterator &i ) +int Bu::MiniCron::TimerBasic::lexInt( Bu::String::const_iterator &i ) { Token t = lex( i ); if( t == tokEos ) diff --git a/src/minicron.h b/src/minicron.h index b045e79..42369f5 100644 --- a/src/minicron.h +++ b/src/minicron.h @@ -10,7 +10,7 @@ #include "bu/signals.h" #include "bu/heap.h" -#include "bu/fstring.h" +#include "bu/string.h" #include @@ -89,7 +89,7 @@ namespace Bu * JobId which can be used at a later time to control the execution of * the job. */ - virtual JobId addJob( const Bu::FString &sName, CronSignal sigJob, + virtual JobId addJob( const Bu::String &sName, CronSignal sigJob, const Timer &t ); /** @@ -98,7 +98,7 @@ namespace Bu * function returns a JobId which can be used at a later time to control * the execution of the job. */ - virtual JobId addJobOnce( const Bu::FString &sName, CronSignal sigJob, + virtual JobId addJobOnce( const Bu::String &sName, CronSignal sigJob, const Timer &t ); /** @@ -113,12 +113,12 @@ namespace Bu class JobInfo { public: - JobInfo( const Bu::FString &sName, JobId jid, time_t tNext ); + JobInfo( const Bu::String &sName, JobId jid, time_t tNext ); virtual ~JobInfo(); bool operator<( const JobInfo &rhs ) const; - Bu::FString sName; + Bu::String sName; JobId jid; time_t tNext; }; @@ -189,7 +189,7 @@ namespace Bu class TimerBasic : public Timer { public: - TimerBasic( const Bu::FString &s ); + TimerBasic( const Bu::String &s ); virtual ~TimerBasic(); virtual time_t nextTime(); @@ -208,11 +208,11 @@ namespace Bu tokErr, tokEos }; - Token lex( Bu::FString::const_iterator &i ); - int lexInt( Bu::FString::const_iterator &i ); + Token lex( Bu::String::const_iterator &i ); + int lexInt( Bu::String::const_iterator &i ); int iVal; //< A temp variable for parsing. time_t tLast; - Bu::FString sSpec; + Bu::String sSpec; }; /** @@ -225,7 +225,7 @@ namespace Bu { friend class Bu::MiniCron; private: - Job( const Bu::FString &sName, JobId jid, bool bRepeat=true ); + Job( const Bu::String &sName, JobId jid, bool bRepeat=true ); virtual ~Job(); public: @@ -290,10 +290,10 @@ namespace Bu /** * Gets the name that was set when the job was created. */ - Bu::FString getName() const; + Bu::String getName() const; private: - Bu::FString sName; + Bu::String sName; CronSignal sigJob; time_t tNextRun; Timer *pTimer; diff --git a/src/minimacro.cpp b/src/minimacro.cpp index df1a5c9..6c5a7c9 100644 --- a/src/minimacro.cpp +++ b/src/minimacro.cpp @@ -25,10 +25,10 @@ Bu::MiniMacro::~MiniMacro() { } -Bu::FString Bu::MiniMacro::parse( const Bu::FString &sIn ) +Bu::String Bu::MiniMacro::parse( const Bu::String &sIn ) { bContinue = true; - Bu::FString sOut; + Bu::String sOut; for( sCur = sIn.getStr(); *sCur && bContinue; sCur++ ) { if( *sCur == '{' ) @@ -66,16 +66,16 @@ Bu::FString Bu::MiniMacro::parse( const Bu::FString &sIn ) return sOut; } -Bu::FString Bu::MiniMacro::parseRepl() +Bu::String Bu::MiniMacro::parseRepl() { - Bu::FString sOut; + Bu::String sOut; bool bIsFirst = true; for( const char *sNext = sCur;;) { for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { } if( *sNext == '\0' ) break; - Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); + Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); if( bIsFirst ) { sOut = hVars[sName]; @@ -101,21 +101,21 @@ Bu::FString Bu::MiniMacro::parseRepl() return sOut; } -Bu::FString Bu::MiniMacro::parseCond() +Bu::String Bu::MiniMacro::parseCond() { - Bu::FString sOut; + Bu::String sOut; //printf("%20s\n", sCur ); return sOut; } -Bu::FString Bu::MiniMacro::parseCmd() +Bu::String Bu::MiniMacro::parseCmd() { - Bu::FString sOut; + Bu::String sOut; const char *sNext = sCur; for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { } if( *sNext != '\0' ) { - Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); + Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); if( sName == "end" ) { sCur = sNext; @@ -138,20 +138,20 @@ Bu::FString Bu::MiniMacro::parseCmd() return sOut; } -Bu::FString Bu::MiniMacro::callFunc( - const Bu::FString &sIn, const Bu::FString &sFunc ) +Bu::String Bu::MiniMacro::callFunc( + const Bu::String &sIn, const Bu::String &sFunc ) { int i = sFunc.findIdx('('); if( i < 0 ) throw Bu::ExceptionBase("That doesn't look like a function call"); - Bu::FString sName( sFunc.getStr(), i ); + Bu::String sName( sFunc.getStr(), i ); StrList lsParams; for( const char *s = sFunc.getStr()+i+1; *s && *s != ')'; s++ ) { for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ ) { } const char *sNext; for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ ) { } - Bu::FString p( s, (ptrdiff_t)sNext-(ptrdiff_t)s ); + Bu::String p( s, (ptrdiff_t)sNext-(ptrdiff_t)s ); lsParams.append( p ); sNext++; s = sNext; @@ -160,17 +160,17 @@ Bu::FString Bu::MiniMacro::callFunc( } void Bu::MiniMacro::addVar( - const Bu::FString &sName, const Bu::FString &sValue ) + const Bu::String &sName, const Bu::String &sValue ) { hVars.insert( sName, sValue ); } -bool Bu::MiniMacro::hasVar( const Bu::FString &sName ) +bool Bu::MiniMacro::hasVar( const Bu::String &sName ) { return hVars.has( sName ); } -const Bu::FString &Bu::MiniMacro::getVar( const Bu::FString &sName ) +const Bu::String &Bu::MiniMacro::getVar( const Bu::String &sName ) { return hVars.get( sName ); } diff --git a/src/minimacro.h b/src/minimacro.h index 2a1fe23..0483190 100644 --- a/src/minimacro.h +++ b/src/minimacro.h @@ -9,11 +9,11 @@ #define BU_MINI_MACRO_H #include "bu/hash.h" -#include "bu/fstring.h" +#include "bu/string.h" namespace Bu { - typedef Bu::Hash StrHash; + typedef Bu::Hash StrHash; /** * A processor for Libbu++ brand Mini Macros. These are really simple, but * still fairly flexible. It's mainly text replacement, but with a few @@ -67,34 +67,34 @@ namespace Bu MiniMacro( const StrHash &sVarSrc ); virtual ~MiniMacro(); - Bu::FString parse( const Bu::FString &sIn ); - void addVar( const Bu::FString &sName, const Bu::FString &sValue ); - bool hasVar( const Bu::FString &sName ); - const Bu::FString &getVar( const Bu::FString &sName ); + Bu::String parse( const Bu::String &sIn ); + void addVar( const Bu::String &sName, const Bu::String &sValue ); + bool hasVar( const Bu::String &sName ); + const Bu::String &getVar( const Bu::String &sName ); const StrHash &getVars(); int getPosition(); private: const char *sCur; - Bu::FString parseRepl(); - Bu::FString parseCond(); - Bu::FString parseCmd(); - Bu::FString callFunc( - const Bu::FString &sIn, const Bu::FString &sFunc ); + Bu::String parseRepl(); + Bu::String parseCond(); + Bu::String parseCmd(); + Bu::String callFunc( + const Bu::String &sIn, const Bu::String &sFunc ); StrHash hVars; bool bContinue; int iLastPos; public: - typedef Bu::List StrList; + typedef Bu::List StrList; class Func { public: Func(){} virtual ~Func(){} - virtual Bu::FString call( - const Bu::FString &sIn, StrList &lsParam )=0; + virtual Bu::String call( + const Bu::String &sIn, StrList &lsParam )=0; }; class FuncToUpper : public Func @@ -102,10 +102,10 @@ namespace Bu public: FuncToUpper(){} virtual ~FuncToUpper(){} - virtual Bu::FString call( - const Bu::FString &sIn, StrList & ) + virtual Bu::String call( + const Bu::String &sIn, StrList & ) { - Bu::FString sOut( sIn ); + Bu::String sOut( sIn ); sOut.toUpper(); return sOut; } @@ -116,17 +116,17 @@ namespace Bu public: FuncToLower(){} virtual ~FuncToLower(){} - virtual Bu::FString call( - const Bu::FString &sIn, StrList & ) + virtual Bu::String call( + const Bu::String &sIn, StrList & ) { - Bu::FString sOut( sIn ); + Bu::String sOut( sIn ); sOut.toLower(); return sOut; } }; private: - typedef Bu::Hash FuncHash; + typedef Bu::Hash FuncHash; FuncHash hFuncs; }; }; diff --git a/src/multiserver.cpp b/src/multiserver.cpp index a6cee36..58f2a7c 100644 --- a/src/multiserver.cpp +++ b/src/multiserver.cpp @@ -26,7 +26,7 @@ void Bu::MultiServer::addProtocol( Bu::Protocol *(*proc)(), int iPort, addPort( iPort, nPoolSize ); } -void Bu::MultiServer::addProtocol( Protocol *(*proc)(), const FString &sAddr, +void Bu::MultiServer::addProtocol( Protocol *(*proc)(), const String &sAddr, int iPort, int nPoolSize ) { hProtos[iPort] = proc; diff --git a/src/multiserver.h b/src/multiserver.h index 6b98c1d..d529d0c 100644 --- a/src/multiserver.h +++ b/src/multiserver.h @@ -29,7 +29,7 @@ namespace Bu virtual ~MultiServer(); void addProtocol( Protocol *(*proc)(), int iPort, int nPoolSize=40 ); - void addProtocol( Protocol *(*proc)(), const FString &sAddr, int iPort, + void addProtocol( Protocol *(*proc)(), const String &sAddr, int iPort, int nPoolSize=40 ); void scan() diff --git a/src/nullstream.cpp b/src/nullstream.cpp index 40c636c..6f792e3 100644 --- a/src/nullstream.cpp +++ b/src/nullstream.cpp @@ -22,10 +22,10 @@ size_t Bu::NullStream::read( void *pBuf, size_t nBytes ) return nBytes; } -Bu::FString Bu::NullStream::readLine() +Bu::String Bu::NullStream::readLine() { sRead++; - return Bu::FString("\0", 1 ); + return Bu::String("\0", 1 ); } size_t Bu::NullStream::write( const void *, size_t nBytes ) diff --git a/src/nullstream.h b/src/nullstream.h index 1537ffb..8c1f744 100644 --- a/src/nullstream.h +++ b/src/nullstream.h @@ -25,7 +25,7 @@ namespace Bu virtual void close(); virtual size_t read( void *pBuf, size_t nBytes ); - virtual Bu::FString readLine(); + virtual Bu::String readLine(); virtual size_t write( const void *pBuf, size_t nBytes ); using Bu::Stream::write; virtual long tell(); diff --git a/src/optparser.cpp b/src/optparser.cpp index b81691d..7b4e0d0 100644 --- a/src/optparser.cpp +++ b/src/optparser.cpp @@ -32,9 +32,9 @@ void Bu::OptParser::parse( int argc, char **argv ) for( iEPos = 2; argv[j][iEPos] != '\0' && argv[j][iEPos] != '='; iEPos++ ) { } - Bu::FString sOpt; + Bu::String sOpt; int iCount = argc-j; - Bu::FString sExtraParam; + Bu::String sExtraParam; if( argv[j][iEPos] == '=' ) { sOpt.set( argv[j]+2, iEPos-2 ); @@ -92,7 +92,7 @@ void Bu::OptParser::parse( int argc, char **argv ) { if( !hsOption.has( argv[j][iCPos] ) ) { - Bu::FString sOpt("-"); + Bu::String sOpt("-"); sOpt += argv[j][iCPos]; optionError( sOpt ); } @@ -181,17 +181,17 @@ void Bu::OptParser::setOverride( char cOpt, const Bu::Variant &sOverride ) hsOption.get( cOpt )->sOverride = sOverride; } -void Bu::OptParser::setOverride( const Bu::FString &sOpt, const Bu::Variant &sOverride ) +void Bu::OptParser::setOverride( const Bu::String &sOpt, const Bu::Variant &sOverride ) { hlOption.get( sOpt )->sOverride = sOverride; } -void Bu::OptParser::setHelpDefault( const Bu::FString &sOpt, const Bu::FString &sTxt ) +void Bu::OptParser::setHelpDefault( const Bu::String &sOpt, const Bu::String &sTxt ) { hlOption.get( sOpt )->sHelpDefault = sTxt; } -void Bu::OptParser::addHelpOption( char c, const Bu::FString &s, const Bu::FString &sHelp ) +void Bu::OptParser::addHelpOption( char c, const Bu::String &s, const Bu::String &sHelp ) { Option o; o.sUsed = slot( this, &OptParser::optHelp ); @@ -201,7 +201,7 @@ void Bu::OptParser::addHelpOption( char c, const Bu::FString &s, const Bu::FStri addOption( o ); } -void Bu::OptParser::addHelpBanner( const Bu::FString &sText, bool bFormatted ) +void Bu::OptParser::addHelpBanner( const Bu::String &sText, bool bFormatted ) { Banner b; b.sText = sText; @@ -290,7 +290,7 @@ int Bu::OptParser::optHelp( StrArray /*aParams*/ ) return 0; } -void Bu::OptParser::optionError( const Bu::FString &sOption ) +void Bu::OptParser::optionError( const Bu::String &sOption ) { sio << "Unregcognized option discovered: " << sOption << sio.nl << sio.nl; exit( 1 ); @@ -301,11 +301,11 @@ void Bu::OptParser::setNonOption( OptionSignal sSignal ) sNonOption = sSignal; } -Bu::FString Bu::OptParser::format( const Bu::FString &sIn, int iWidth, +Bu::String Bu::OptParser::format( const Bu::String &sIn, int iWidth, int iIndent ) { - Bu::FString sOut; - Bu::FString sIndent; + Bu::String sOut; + Bu::String sIndent; for( int j = 0; j < iIndent; j++ ) sIndent.append(" ", 1); bool bFirst = true; @@ -314,8 +314,8 @@ Bu::FString Bu::OptParser::format( const Bu::FString &sIn, int iWidth, int iPrevLineLen; int iLineLen = 0; char c; - Bu::FString::const_iterator iLastSpace, iStart; - for( Bu::FString::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) + Bu::String::const_iterator iLastSpace, iStart; + for( Bu::String::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) { c = *i; if( *i == ' ' ) @@ -346,7 +346,7 @@ Bu::FString Bu::OptParser::format( const Bu::FString &sIn, int iWidth, float fFill = 0.0; int iSubSpaceCount = 0; float fAdd = ((float)iExtraSpaces/(float)iSpaceCount); - for( Bu::FString::const_iterator k = iStart; k != iLastSpace; k++ ) + for( Bu::String::const_iterator k = iStart; k != iLastSpace; k++ ) { sOut += *k; if( *k == ' ' ) diff --git a/src/optparser.h b/src/optparser.h index 7ec69e5..9781542 100644 --- a/src/optparser.h +++ b/src/optparser.h @@ -8,7 +8,7 @@ #ifndef BU_OPT_PARSER_H #define BU_OPT_PARSER_H -#include "bu/fstring.h" +#include "bu/string.h" #include "bu/list.h" #include "bu/hash.h" #include "bu/signals.h" @@ -19,7 +19,7 @@ namespace Bu { - typedef Bu::Array StrArray; + typedef Bu::Array StrArray; /** * POSIX/Gnu style command line parser. Handles long and short options in @@ -41,7 +41,7 @@ namespace Bu _ValueProxy(); virtual ~_ValueProxy(); - virtual void setValueFromStr( const Bu::FString & )=0; + virtual void setValueFromStr( const Bu::String & )=0; virtual void setValue( const Bu::Variant &vVar )=0; virtual _ValueProxy *clone()=0; }; @@ -59,7 +59,7 @@ namespace Bu { } - virtual void setValueFromStr( const Bu::FString &sVal ) + virtual void setValueFromStr( const Bu::String &sVal ) { Bu::MemBuf mb( sVal ); Bu::Formatter f( mb ); @@ -72,9 +72,9 @@ namespace Bu { v = vVar.get(); } - else if( vVar.getType() == typeid(Bu::FString) ) + else if( vVar.getType() == typeid(Bu::String) ) { - setValueFromStr( vVar.get() ); + setValueFromStr( vVar.get() ); } else { @@ -101,23 +101,23 @@ namespace Bu virtual ~Option(); char cOpt; - Bu::FString sOpt; - Bu::FString sHelp; + Bu::String sOpt; + Bu::String sHelp; OptionSignal sUsed; _ValueProxy *pProxy; Bu::Variant sOverride; - Bu::FString sHelpDefault; + Bu::String sHelpDefault; }; private: typedef Bu::List