From 3b9581e84e19723087b31b79674801b6c06ae533 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Wed, 18 Aug 2010 09:23:15 +0200 Subject: Imported Upstream version 1.6.1 --- bson/util/builder.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'bson/util/builder.h') diff --git a/bson/util/builder.h b/bson/util/builder.h index 75a1ad8..9d9eda2 100644 --- a/bson/util/builder.h +++ b/bson/util/builder.h @@ -164,6 +164,7 @@ namespace mongo { #define SBNUM(val,maxSize,macro) \ int prev = _buf.l; \ int z = sprintf( _buf.grow(maxSize) , macro , (val) ); \ + assert( z >= 0 ); \ _buf.l = prev + z; \ return *this; @@ -197,6 +198,17 @@ namespace mongo { } #undef SBNUM + void appendDoubleNice( double x ){ + int prev = _buf.l; + char * start = _buf.grow( 32 ); + int z = sprintf( start , "%.16g" , x ); + assert( z >= 0 ); + _buf.l = prev + z; + if( strchr(start, '.') == 0 && strchr(start, 'E') == 0 && strchr(start, 'N') == 0 ){ + write( ".0" , 2 ); + } + } + void write( const char* buf, int len){ memcpy( _buf.grow( len ) , buf , len ); } -- cgit v1.2.3