0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00

Have connection.setEncoding use node::ParseEncoding

This commit is contained in:
Ryan 2009-05-26 18:14:32 +02:00
parent 24ebd0360a
commit c4e53c7ceb

View File

@ -15,6 +15,7 @@ using namespace node;
#define UTF8_SYMBOL String::NewSymbol("utf8")
#define RAW_SYMBOL String::NewSymbol("raw")
#define ASCII_SYMBOL String::NewSymbol("ascii")
#define ON_RECEIVE_SYMBOL String::NewSymbol("onReceive")
#define ON_DISCONNECT_SYMBOL String::NewSymbol("onDisconnect")
@ -206,18 +207,20 @@ Connection::SetEncoding (const Arguments& args)
connection->encoding_ = RAW;
return scope.Close(RAW_SYMBOL);
}
Local<String> encoding = args[0]->ToString();
char buf[5]; // need enough room for "utf8" or "raw"
encoding->WriteAscii(buf, 0, 4);
buf[4] = '\0';
switch (ParseEncoding(args[0])) {
case ASCII:
connection->encoding_ = ASCII;
return scope.Close(ASCII_SYMBOL);
if(strcasecmp(buf, "utf8") == 0) {
connection->encoding_ = UTF8;
return scope.Close(UTF8_SYMBOL);
} else {
connection->encoding_ = RAW;
return scope.Close(RAW_SYMBOL);
case UTF8:
connection->encoding_ = UTF8;
return scope.Close(UTF8_SYMBOL);
case RAW:
default:
connection->encoding_ = RAW;
return scope.Close(RAW_SYMBOL);
}
}