From db45c881d98f2288aa26960e5eae6070f792b82a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 31 Mar 2010 14:23:55 +0000 Subject: Removed the bool cast operator from FBasicString. It turns out it was causing way, way, way more problems than it solved. A number of libbu++ tests were inacurate because of it, there were problems in several other programs, and there may be more that have problems we haven't found yet because of this. This will most likely cause complitaion errors, especially in places we didn't expect, where strings were being stored into or passed as integers and the like. In cases where you were just testing a string, just call the "isSet()" function, which is functionally equivellent to the old bool cast operator. --- src/csvreader.cpp | 3 +++ src/fbasicstring.h | 5 +++-- src/formatter.cpp | 2 +- src/formatter.h | 4 ++-- src/optparser.cpp | 14 +++++++------- src/tafwriter.cpp | 2 +- src/tests/fstrstd.cpp | 2 +- src/tools/myriad.cpp | 4 ++-- src/unit/fstring.unit | 2 +- src/unit/hash.unit | 8 ++++---- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/csvreader.cpp b/src/csvreader.cpp index b045773..c63fe06 100644 --- a/src/csvreader.cpp +++ b/src/csvreader.cpp @@ -71,6 +71,9 @@ Bu::FString Bu::CsvReader::decodeExcel( Bu::FString::iterator &i ) for(; i && (*i == ' ' || *i == '\t'); i++ ) { } + if( !i ) + return sRet; + if( *i == '\"' ) { for( i++ ; i; i++ ) diff --git a/src/fbasicstring.h b/src/fbasicstring.h index 4907d61..e965de8 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -335,7 +335,7 @@ namespace Bu if( !pChunk ) return false; return pChunk->pData[iPos] != c; } - + operator bool() const { return pChunk != NULL; @@ -1598,11 +1598,12 @@ namespace Bu return pFirst->pData; } */ - + /* operator bool() const { return (core->pFirst != NULL); } + */ bool isSet() const { diff --git a/src/formatter.cpp b/src/formatter.cpp index 7ebe256..3e0f41e 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -459,7 +459,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(); - if( !sStr ) + if( !sStr.isSet() ) return f; char c = *sStr.begin(); if( c == 'y' || c == 'Y' || c == 't' || c == 'T' ) diff --git a/src/formatter.h b/src/formatter.h index ec84be5..47592ad 100644 --- a/src/formatter.h +++ b/src/formatter.h @@ -204,7 +204,7 @@ namespace Bu template void iparse( type &i, const Bu::FString &sBuf ) { - if( !sBuf ) + if( !sBuf.isSet() ) return; if( sBuf[0] != '+' && sBuf[0] != '-' && (sBuf[0] < '0' && sBuf[0] > '9') ) @@ -230,7 +230,7 @@ namespace Bu template void uparse( type &i, const Bu::FString &sBuf ) { - if( !sBuf ) + if( !sBuf.isSet() ) return; if( sBuf[0] != '+' && (sBuf[0] < '0' && sBuf[0] > '9') ) diff --git a/src/optparser.cpp b/src/optparser.cpp index bbac9d5..53efe92 100644 --- a/src/optparser.cpp +++ b/src/optparser.cpp @@ -53,7 +53,7 @@ void Bu::OptParser::parse( int argc, char **argv ) { Bu::StrArray aParams( iCount ); aParams.append( sOpt ); - if( sExtraParam ) + if( sExtraParam.isSet() ) { aParams.append( argv[j]+iEPos+1 ); } @@ -65,11 +65,11 @@ void Bu::OptParser::parse( int argc, char **argv ) } else if( pOpt->pProxy ) { - if( pOpt->sOverride ) + if( pOpt->sOverride.isSet() ) { pOpt->pProxy->setValue( pOpt->sOverride ); } - else if( sExtraParam ) + else if( sExtraParam.isSet() ) { pOpt->pProxy->setValue( sExtraParam ); } @@ -117,7 +117,7 @@ void Bu::OptParser::parse( int argc, char **argv ) } else if( pOpt->pProxy ) { - if( pOpt->sOverride ) + if( pOpt->sOverride.isSet() ) { pOpt->pProxy->setValue( pOpt->sOverride ); } @@ -172,7 +172,7 @@ void Bu::OptParser::addOption( const Option &opt ) lOption.append( opt ); if( opt.cOpt != '\0' ) hsOption.insert( opt.cOpt, &lOption.last() ); - if( opt.sOpt ) + if( opt.sOpt.isSet() ) hlOption.insert( opt.sOpt, &lOption.last() ); } @@ -226,7 +226,7 @@ int Bu::OptParser::optHelp( StrArray /*aParams*/ ) if( (*i).cOpt != '\0' ) bHasShort = true; int lOptSize = (*i).sOpt.getSize() + (*i).sHelpDefault.getSize(); - if( (*i).sOpt && iMaxWidth < lOptSize ) + if( (*i).sOpt.isSet() && iMaxWidth < lOptSize ) iMaxWidth = lOptSize; } int iIndent = 4; @@ -260,7 +260,7 @@ int Bu::OptParser::optHelp( StrArray /*aParams*/ ) } if( iMaxWidth > 0 ) { - if( (*i).sOpt ) + if( (*i).sOpt.isSet() ) { sio << "--" << Fmt(iMaxWidth, Fmt::Left) << (*i).sOpt + (*i).sHelpDefault; diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index 7564e74..215cb68 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -28,7 +28,7 @@ void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) { ident(); sOut.write("{", 1 ); - if( pRoot->getName() ) + if( pRoot->getName().isSet() ) writeString( pRoot->getName() ); sOut.write(":\n", 2 ); iDepth++; diff --git a/src/tests/fstrstd.cpp b/src/tests/fstrstd.cpp index 5999ecd..86d7c5c 100644 --- a/src/tests/fstrstd.cpp +++ b/src/tests/fstrstd.cpp @@ -12,5 +12,5 @@ int main() { Bu::FString s("Hey there, dude.\n"); - std::cout << s << 5; +// std::cout << s << 5; } diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 4147579..b3067d2 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp @@ -75,7 +75,7 @@ int main( int argc, char *argv[] ) switch( opts.eMode ) { case modeCreate: - if( !opts.sOutput ) + if( !opts.sOutput.isSet() ) { sio << "Please specify an output file to create a stream for." << sio.nl; @@ -90,7 +90,7 @@ int main( int argc, char *argv[] ) break; case modeInfo: - if( !opts.sInput ) + if( !opts.sInput.isSet() ) { sio << "Please specify an input file to display info about." << sio.nl; diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index fe41ae9..8aaae93 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit @@ -74,7 +74,7 @@ unitTest( a == "ab" ); a += "cdefghijklmnop"; a.remove( 5, 1 ); - unitTest( a = "abcdeghijklmnop" ); + unitTest( a == "abcdeghijklmnop" ); } {%add1} diff --git a/src/unit/hash.unit b/src/unit/hash.unit index 9edc61e..c0a10e3 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit @@ -45,13 +45,13 @@ typedef Bu::Hash IntStrHash; unitTest( h["Hi"].getValue() == "Yo" ); StrStrHash h2(h); - unitTest( h2["Hi"].getValue() = "Yo" ); - unitTest( h2["Bye"].getValue() = "Later" ); + unitTest( h2["Hi"].getValue() == "Yo" ); + unitTest( h2["Bye"].getValue() == "Later" ); StrStrHash h3; h3 = h; - unitTest( h3["Hi"].getValue() = "Yo" ); - unitTest( h3["Bye"].getValue() = "Later" ); + unitTest( h3["Hi"].getValue() == "Yo" ); + unitTest( h3["Bye"].getValue() == "Later" ); } {%insert3} -- cgit v1.2.3