diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index ad6627e27b..b9dc4adf37 100755 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -49,6 +49,7 @@ #include "VocBase/general-cursor.h" #include "VocBase/document-collection.h" #include "VocBase/voc-shaper.h" +#include "Basics/Utf8Helper.h" using namespace std; using namespace triagens::basics; @@ -1625,6 +1626,30 @@ static v8::Handle JS_normalize_string (v8::Arguments const& argv) { return scope.Close(v8::String::New(*x, x.length())); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief compare two UTF 16 strings +//////////////////////////////////////////////////////////////////////////////// + +static v8::Handle JS_compare_string (v8::Arguments const& argv) { + v8::HandleScope scope; + + if (argv.Length() != 2) { + return scope.Close(v8::ThrowException( + TRI_CreateErrorObject(TRI_ERROR_ILLEGAL_OPTION, + "usage: COMPARE_STRING(, )"))); + } + + // TODO: get collation language + Utf8Helper u8(""); + + v8::String::Value left(argv[0]); + v8::String::Value right(argv[1]); + + int result = u8.compareUtf16(*left, left.length(), *right, right.length()); + + return scope.Close(v8::Integer::New(result)); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief generates a general cursor from a list //////////////////////////////////////////////////////////////////////////////// @@ -5664,6 +5689,10 @@ TRI_v8_global_t* TRI_InitV8VocBridge (v8::Handle context, TRI_vocba v8::FunctionTemplate::New(JS_normalize_string)->GetFunction(), v8::ReadOnly); + context->Global()->Set(v8::String::New("COMPARE_STRING"), + v8::FunctionTemplate::New(JS_compare_string)->GetFunction(), + v8::ReadOnly); + // ............................................................................. // create the global variables // ............................................................................. diff --git a/js/server/ahuacatl.js b/js/server/ahuacatl.js index e416ee36a3..932dddb878 100755 --- a/js/server/ahuacatl.js +++ b/js/server/ahuacatl.js @@ -671,6 +671,10 @@ function AHUACATL_RELATIONAL_EQUAL (lhs, rhs) { rhs = null; } + if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) { + return COMPARE_STRING(lhs, rhs) == 0; + } + return (lhs === rhs); } diff --git a/js/server/js-ahuacatl.h b/js/server/js-ahuacatl.h index c26fb78bcf..7b3507f260 100644 --- a/js/server/js-ahuacatl.h +++ b/js/server/js-ahuacatl.h @@ -672,6 +672,10 @@ static string JS_server_ahuacatl = " rhs = null;\n" " }\n" "\n" + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + " return COMPARE_STRING(lhs, rhs) == 0;\n" + " }\n" + "\n" " return (lhs === rhs);\n" "}\n" "\n"