mirror of https://gitee.com/bigwinds/arangodb
implemented LENGTH in C++
This commit is contained in:
parent
cc00bb8897
commit
4564f13bc8
|
@ -137,7 +137,7 @@ std::unordered_map<std::string, Function const> const Executor::FunctionNames{
|
|||
{ "MINUS", Function("MINUS", "AQL_MINUS", "l,l|+", true, false, true) },
|
||||
{ "INTERSECTION", Function("INTERSECTION", "AQL_INTERSECTION", "l,l|+", true, false, true) },
|
||||
{ "FLATTEN", Function("FLATTEN", "AQL_FLATTEN", "l|n", true, false, true) },
|
||||
{ "LENGTH", Function("LENGTH", "AQL_LENGTH", "las", true, false, true) },
|
||||
{ "LENGTH", Function("LENGTH", "AQL_LENGTH", "las", true, false, true, &Functions::Length) },
|
||||
{ "MIN", Function("MIN", "AQL_MIN", "l", true, false, true) },
|
||||
{ "MAX", Function("MAX", "AQL_MAX", "l", true, false, true) },
|
||||
{ "SUM", Function("SUM", "AQL_SUM", "l", true, false, true) },
|
||||
|
|
|
@ -100,6 +100,51 @@ AqlValue Functions::IsDocument (triagens::arango::AqlTransaction* trx,
|
|||
return AqlValue(new Json(j.isArray()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief function LENGTH
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
AqlValue Functions::Length (triagens::arango::AqlTransaction* trx,
|
||||
TRI_document_collection_t const* collection,
|
||||
AqlValue const parameters) {
|
||||
Json j(parameters.extractListMember(trx, collection, 0, false));
|
||||
|
||||
TRI_json_t const* json = j.json();
|
||||
size_t length = 0;
|
||||
|
||||
if (json != nullptr) {
|
||||
switch (json->_type) {
|
||||
case TRI_JSON_UNUSED:
|
||||
case TRI_JSON_NULL:
|
||||
length = strlen("null");
|
||||
break;
|
||||
|
||||
case TRI_JSON_BOOLEAN:
|
||||
length = (json->_value._boolean ? strlen("true") : strlen("false"));
|
||||
break;
|
||||
|
||||
case TRI_JSON_NUMBER:
|
||||
case TRI_JSON_STRING:
|
||||
case TRI_JSON_STRING_REFERENCE:
|
||||
// return number of characters (not byteS) in string
|
||||
length = TRI_CharLengthUtf8String(json->_value._string.data);
|
||||
break;
|
||||
|
||||
case TRI_JSON_ARRAY:
|
||||
// return number of attributes
|
||||
length = json->_value._objects._length / 2;
|
||||
break;
|
||||
|
||||
case TRI_JSON_LIST:
|
||||
// return list length
|
||||
length = TRI_LengthListJson(json);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return AqlValue(new Json(static_cast<double>(length)));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "Basics/Common.h"
|
||||
#include "Aql/AqlValue.h"
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Utils/AqlTransaction.h"
|
||||
|
||||
#include <functional>
|
||||
|
@ -55,6 +56,7 @@ namespace triagens {
|
|||
static AqlValue IsString (triagens::arango::AqlTransaction*, TRI_document_collection_t const*, AqlValue const);
|
||||
static AqlValue IsList (triagens::arango::AqlTransaction*, TRI_document_collection_t const*, AqlValue const);
|
||||
static AqlValue IsDocument (triagens::arango::AqlTransaction*, TRI_document_collection_t const*, AqlValue const);
|
||||
static AqlValue Length (triagens::arango::AqlTransaction*, TRI_document_collection_t const*, AqlValue const);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -342,9 +342,6 @@ size_t TRI_CharLengthUtf8String (const char*);
|
|||
|
||||
char* TRI_PrefixUtf8String (const char*, const uint32_t);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue