@@ -212,7 +212,7 @@ static AqlValue ExtractFunctionParameterValue(
212
212
// parameter out of range
213
213
return AqlValue ();
214
214
}
215
- return parameters. at ( position) ;
215
+ return parameters[ position] ;
216
216
}
217
217
218
218
// / @brief extra a collection name from an AqlValue
@@ -1109,6 +1109,8 @@ AqlValue Functions::Contains(arangodb::aql::Query* query,
1109
1109
AqlValue value = ExtractFunctionParameterValue (trx, parameters, 0 );
1110
1110
AqlValue search = ExtractFunctionParameterValue (trx, parameters, 1 );
1111
1111
AqlValue returnIndex = ExtractFunctionParameterValue (trx, parameters, 2 );
1112
+
1113
+ bool const willReturnIndex = returnIndex.toBoolean ();
1112
1114
1113
1115
int result = -1 ; // default is "not found"
1114
1116
{
@@ -1126,28 +1128,34 @@ AqlValue Functions::Contains(arangodb::aql::Query* query,
1126
1128
char const * found = static_cast <char const *>(memmem (buffer->c_str (), valueLength, buffer->c_str () + searchOffset, searchLength));
1127
1129
1128
1130
if (found != nullptr ) {
1129
- // find offset into string
1130
- int bytePosition = static_cast <int >(found - buffer->c_str ());
1131
- char const * p = buffer->c_str ();
1132
- int pos = 0 ;
1133
- while (pos < bytePosition) {
1134
- unsigned char c = static_cast <unsigned char >(*p);
1135
- if (c < 128 ) {
1136
- ++pos;
1137
- } else if (c < 224 ) {
1138
- pos += 2 ;
1139
- } else if (c < 240 ) {
1140
- pos += 3 ;
1141
- } else if (c < 248 ) {
1142
- pos += 4 ;
1131
+ if (willReturnIndex) {
1132
+ // find offset into string
1133
+ int bytePosition = static_cast <int >(found - buffer->c_str ());
1134
+ char const * p = buffer->c_str ();
1135
+ int pos = 0 ;
1136
+ while (pos < bytePosition) {
1137
+ unsigned char c = static_cast <unsigned char >(*p);
1138
+ if (c < 128 ) {
1139
+ ++pos;
1140
+ } else if (c < 224 ) {
1141
+ pos += 2 ;
1142
+ } else if (c < 240 ) {
1143
+ pos += 3 ;
1144
+ } else if (c < 248 ) {
1145
+ pos += 4 ;
1146
+ }
1143
1147
}
1148
+ result = pos;
1149
+ } else {
1150
+ // fake result position, but it does not matter as it will
1151
+ // only be compared to -1 later
1152
+ result = 0 ;
1144
1153
}
1145
- result = pos;
1146
1154
}
1147
1155
}
1148
1156
}
1149
1157
1150
- if (returnIndex. toBoolean () ) {
1158
+ if (willReturnIndex ) {
1151
1159
// return numeric value
1152
1160
return NumberValue (trx, result);
1153
1161
}
0 commit comments