| 1336 | } |
| 1337 | |
| 1338 | IntVal StringFunctions::FindInSet(FunctionContext* context, const StringVal& str, |
| 1339 | const StringVal& str_set) { |
| 1340 | if (str.is_null || str_set.is_null) return IntVal::null(); |
| 1341 | // Check str for commas. |
| 1342 | for (int i = 0; i < str.len; ++i) { |
| 1343 | if (str.ptr[i] == ',') return IntVal(0); |
| 1344 | } |
| 1345 | // The result index starts from 1 since 0 is an error condition. |
| 1346 | int32_t token_index = 1; |
| 1347 | int32_t start = 0; |
| 1348 | int32_t end; |
| 1349 | StringValue str_sv = StringValue::FromStringVal(str); |
| 1350 | do { |
| 1351 | end = start; |
| 1352 | // Position end. |
| 1353 | while (end < str_set.len && str_set.ptr[end] != ',') ++end; |
| 1354 | StringValue token(reinterpret_cast<char*>(str_set.ptr) + start, end - start); |
| 1355 | if (str_sv.Eq(token)) return IntVal(token_index); |
| 1356 | |
| 1357 | // Re-position start and end past ',' |
| 1358 | start = end + 1; |
| 1359 | ++token_index; |
| 1360 | } while (start < str_set.len); |
| 1361 | return IntVal(0); |
| 1362 | } |
| 1363 | |
| 1364 | void StringFunctions::ParseUrlPrepare( |
| 1365 | FunctionContext* ctx, FunctionContext::FunctionStateScope scope) { |