* Join the elements of the list separated by the specified delimiter and * return as a string. There will be no whitespace added for prettyprinting, * this is more intended for serializing. The caller is responsible for * managing the returned memory. */
| 617 | * managing the returned memory. |
| 618 | */ |
| 619 | static char * |
| 620 | list_join(List *list, char delimiter) |
| 621 | { |
| 622 | ListCell *cell; |
| 623 | StringInfoData buf; |
| 624 | |
| 625 | if (list_length(list) == 0) |
| 626 | return pstrdup(""); |
| 627 | |
| 628 | initStringInfo(&buf); |
| 629 | |
| 630 | foreach(cell, list) |
| 631 | { |
| 632 | const char *cellval; |
| 633 | |
| 634 | cellval = strVal(lfirst(cell)); |
| 635 | appendStringInfo(&buf, "%s%c", cellval, delimiter); |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * Rather than keeping track of when we're adding the last element, trim |
| 640 | * the final delimiter to keep it simple. |
| 641 | */ |
| 642 | buf.data[buf.len - 1] = '\0'; |
| 643 | |
| 644 | return buf.data; |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * Transform the FORMAT options List into a new List suitable for storing in |
no test coverage detected