Permalink
Browse files

handle strings as UChar*

  • Loading branch information...
1 parent 6681326 commit 31611fca161aa03e7603752751507867ba164abb @astro committed Aug 5, 2010
Showing with 15 additions and 13 deletions.
  1. +5 −4 leakcheck.js
  2. +10 −9 node-stringprep.cc
View
@@ -2,15 +2,16 @@ var SP = require('./build/default/node-stringprep');
function run() {
var p = new SP.StringPrep('nameprep');
- if (p.prepare('FooBar') !== 'foobar')
- throw p.prepare('FooBar');
+ var r = p.prepare('A\u0308ffin');
+ if (r !== 'äffin')
+ throw r;
- nextTick(run);
+ process.nextTick(run);
}
try {
run();
} catch (e) {
- console.log(e);
+ console.log(JSON.stringify(e));
}
View
@@ -1,9 +1,8 @@
#include <node.h>
#include <node_object_wrap.h>
-extern "C" {
+#include <unicode/unistr.h>
#include <unicode/usprep.h>
-#include <string.h>
-}
+#include <cstring>
#include <exception>
using namespace v8;
@@ -110,23 +109,23 @@ class StringPrep : public ObjectWrap {
if (args.Length() == 1 && args[0]->IsString())
{
StringPrep *self = ObjectWrap::Unwrap<StringPrep>(args.This());
- String::Utf8Value arg0(args[0]->ToString());
+ String::Value arg0(args[0]->ToString());
return scope.Close(self->prepare(arg0));
}
else
return throwTypeError("Bad argument.");
}
- Handle<Value> prepare(String::Utf8Value &str)
+ Handle<Value> prepare(String::Value &str)
{
size_t destLen = str.length();
- char *dest = NULL;
+ UChar *dest = NULL;
while(!dest)
{
- dest = new char[destLen];
+ dest = new UChar[destLen];
size_t w = usprep_prepare(profile,
- reinterpret_cast<UChar *>(*str), str.length(),
- reinterpret_cast<UChar *>(dest), destLen,
+ *str, str.length(),
+ dest, destLen,
USPREP_DEFAULT, NULL, &error);
if (error == U_BUFFER_OVERFLOW_ERROR)
@@ -142,6 +141,8 @@ class StringPrep : public ObjectWrap {
delete[] dest;
return ThrowException(makeException());
}
+ else
+ destLen = w;
}
Local<String> result = String::New(dest, destLen);

0 comments on commit 31611fc

Please sign in to comment.