* ArrayCount * Determines the dimensions for an array string. * * Returns number of dimensions as function result. The axis lengths are * returned in dim[], which must be of size MAXDIM. */
| 456 | * returned in dim[], which must be of size MAXDIM. |
| 457 | */ |
| 458 | static int |
| 459 | ArrayCount(const char *str, int *dim, char typdelim) |
| 460 | { |
| 461 | int nest_level = 0, |
| 462 | i; |
| 463 | int ndim = 1, |
| 464 | temp[MAXDIM], |
| 465 | nelems[MAXDIM], |
| 466 | nelems_last[MAXDIM]; |
| 467 | bool in_quotes = false; |
| 468 | bool eoArray = false; |
| 469 | bool empty_array = true; |
| 470 | const char *ptr; |
| 471 | ArrayParseState parse_state = ARRAY_NO_LEVEL; |
| 472 | |
| 473 | for (i = 0; i < MAXDIM; ++i) |
| 474 | { |
| 475 | temp[i] = dim[i] = nelems_last[i] = 0; |
| 476 | nelems[i] = 1; |
| 477 | } |
| 478 | |
| 479 | ptr = str; |
| 480 | while (!eoArray) |
| 481 | { |
| 482 | bool itemdone = false; |
| 483 | |
| 484 | while (!itemdone) |
| 485 | { |
| 486 | if (parse_state == ARRAY_ELEM_STARTED || |
| 487 | parse_state == ARRAY_QUOTED_ELEM_STARTED) |
| 488 | empty_array = false; |
| 489 | |
| 490 | switch (*ptr) |
| 491 | { |
| 492 | case '\0': |
| 493 | /* Signal a premature end of the string */ |
| 494 | ereport(ERROR, |
| 495 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 496 | errmsg("malformed array literal: \"%s\"", str), |
| 497 | errdetail("Unexpected end of input."))); |
| 498 | break; |
| 499 | case '\\': |
| 500 | |
| 501 | /* |
| 502 | * An escape must be after a level start, after an element |
| 503 | * start, or after an element delimiter. In any case we |
| 504 | * now must be past an element start. |
| 505 | */ |
| 506 | if (parse_state != ARRAY_LEVEL_STARTED && |
| 507 | parse_state != ARRAY_ELEM_STARTED && |
| 508 | parse_state != ARRAY_QUOTED_ELEM_STARTED && |
| 509 | parse_state != ARRAY_ELEM_DELIMITED) |
| 510 | ereport(ERROR, |
| 511 | (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), |
| 512 | errmsg("malformed array literal: \"%s\"", str), |
| 513 | errdetail("Unexpected \"%c\" character.", |
| 514 | '\\'))); |
| 515 | if (parse_state != ARRAY_QUOTED_ELEM_STARTED) |
no test coverage detected