/ Make a valid key from the passed argument. */ /
| 376 | /* Make a valid key from the passed argument. */ |
| 377 | /*********************************************************************************/ |
| 378 | PSZ BJNX::MakeKey(UDF_ARGS *args, int i) |
| 379 | { |
| 380 | if (args->arg_count > (unsigned)i) { |
| 381 | int j = 0, n = args->attribute_lengths[i]; |
| 382 | my_bool b; // true if attribute is zero terminated |
| 383 | PSZ p; |
| 384 | PCSZ s = args->attributes[i]; |
| 385 | |
| 386 | if (s && *s && (n || *s == '\'')) { |
| 387 | if ((b = (!n || !s[n]))) |
| 388 | n = strlen(s); |
| 389 | |
| 390 | if (IsArgJson(args, i)) |
| 391 | j = (int)(strchr(s, '_') - s + 1); |
| 392 | |
| 393 | if (j && n > j) { |
| 394 | s += j; |
| 395 | n -= j; |
| 396 | } else if (*s == '\'' && s[n-1] == '\'') { |
| 397 | s++; |
| 398 | n -= 2; |
| 399 | b = false; |
| 400 | } // endif *s |
| 401 | |
| 402 | if (n < 1) |
| 403 | return NewStr((PSZ)"Key"); |
| 404 | |
| 405 | if (!b) { |
| 406 | p = (PSZ)BsonSubAlloc(n + 1); |
| 407 | memcpy(p, s, n); |
| 408 | p[n] = 0; |
| 409 | return p; |
| 410 | } // endif b |
| 411 | |
| 412 | } // endif s |
| 413 | |
| 414 | return NewStr((PSZ)s); |
| 415 | } // endif count |
| 416 | |
| 417 | return NewStr((PSZ)"Key"); |
| 418 | } // end of MakeKey |
| 419 | |
| 420 | /*********************************************************************************/ |
| 421 | /* MakeJson: Make the Json tree to serialize. */ |
no test coverage detected