summaryrefslogtreecommitdiff
path: root/src/mongo/util/text.cpp
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2012-03-22 13:05:45 -0400
committerTad Marshall <tad@10gen.com>2012-03-22 14:47:16 -0400
commit3363b199e72a7b41c965fea9483d7825fd353d70 (patch)
treeec61bfd575de9839d2078eb947473f1dd02c9415 /src/mongo/util/text.cpp
parentc7c3b36e36c6ba621c10b246415b07189d67cea0 (diff)
downloadmongo-3363b199e72a7b41c965fea9483d7825fd353d70.tar.gz
SERVER-2939 Supporting code for UTF-8 in the shell
This commit lets the shell read UTF-8 from the command line and fixes a display problem with lines that start with a UTF-8 character. It does not include the actual UTF-8 enabling in linenoise, but prepares for it.
Diffstat (limited to 'src/mongo/util/text.cpp')
-rw-r--r--src/mongo/util/text.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/mongo/util/text.cpp b/src/mongo/util/text.cpp
index 69ea16158ce..a4091d684bb 100644
--- a/src/mongo/util/text.cpp
+++ b/src/mongo/util/text.cpp
@@ -105,7 +105,30 @@ namespace mongo {
}
#endif
-#endif
+ WindowsCommandLine::WindowsCommandLine( int argc, wchar_t* argvW[] ) {
+ vector < string > utf8args;
+ vector < size_t > utf8argLength;
+ size_t blockSize = argc * sizeof( char * );
+ size_t blockPtr = blockSize;
+ for ( int i = 0; i < argc; ++i ) {
+ utf8args.push_back( toUtf8String( argvW[ i ] ) );
+ size_t argLength = utf8args[ i ].length() + 1;
+ utf8argLength.push_back( argLength );
+ blockSize += argLength;
+ }
+ _argv = reinterpret_cast< char** >( malloc( blockSize ) );
+ for ( int i = 0; i < argc; ++i ) {
+ _argv[ i ] = reinterpret_cast< char * >( _argv ) + blockPtr;
+ strcpy_s( _argv[ i ], utf8argLength[ i ], utf8args[ i ].c_str() );
+ blockPtr += utf8argLength[ i ];
+ }
+ }
+
+ WindowsCommandLine::~WindowsCommandLine() {
+ free( _argv );
+ }
+
+#endif // #if defined(_WIN32)
struct TextUnitTest : public UnitTest {
void run() {