From c4e53c7cebd68b4f6ba0214bae22dd63814b172c Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 26 May 2009 18:14:32 +0200 Subject: [PATCH] Have connection.setEncoding use node::ParseEncoding --- src/net.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/net.cc b/src/net.cc index 8a216a8d32f..e936e38f4ce 100644 --- a/src/net.cc +++ b/src/net.cc @@ -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 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); } }