Skip to content

Commit

Permalink
SERVER-3168: Fixed hexadecimal output, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agirbal committed Jun 22, 2011
1 parent 8c8f522 commit 403b7aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 14 additions & 0 deletions jstests/binData.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions scripting/sm_db.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -757,10 +757,12 @@ zzz
assert( holder ); assert( holder );
const char *data = ( ( BinDataHolder* )( holder ) )->c_; const char *data = ( ( BinDataHolder* )( holder ) )->c_;
stringstream ss; stringstream ss;
ss << hex; ss.setf (ios_base::hex , ios_base::basefield);
ss.fill ('0');
ss.setf (ios_base::right , ios_base::adjustfield);
for( int i = 0; i < len; i++ ) { for( int i = 0; i < len; i++ ) {
unsigned v = (unsigned char) data[i]; unsigned v = (unsigned char) data[i];
ss << v; ss << setw(2) << v;
} }
string ret = ss.str(); string ret = ss.str();
return *rval = c.toval( ret.c_str() ); return *rval = c.toval( ret.c_str() );
Expand Down
6 changes: 4 additions & 2 deletions scripting/v8_db.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -775,10 +775,12 @@ namespace mongo {
Local<External> c = External::Cast( *(it->GetInternalField( 0 )) ); Local<External> c = External::Cast( *(it->GetInternalField( 0 )) );
char* data = (char*)(c->Value()); char* data = (char*)(c->Value());
stringstream ss; stringstream ss;
ss << hex; ss.setf (ios_base::hex , ios_base::basefield);
ss.fill ('0');
ss.setf (ios_base::right , ios_base::adjustfield);
for( int i = 0; i < len; i++ ) { for( int i = 0; i < len; i++ ) {
unsigned v = (unsigned char) data[i]; unsigned v = (unsigned char) data[i];
ss << v; ss << setw(2) << v;
} }
return v8::String::New(ss.str().c_str()); return v8::String::New(ss.str().c_str());
} }
Expand Down

0 comments on commit 403b7aa

Please sign in to comment.