MCPcopy Create free account
hub / github.com/apache/cloudberry / strlen_max_width

Function strlen_max_width

src/fe_utils/print.c:3624–3655  ·  view source on GitHub ↗

* Compute the byte distance to the end of the string or *target_width * display character positions, whichever comes first. Update *target_width * to be the number of display character positions actually filled. */

Source from the content-addressed store, hash-verified

3622 * to be the number of display character positions actually filled.
3623 */
3624static int
3625strlen_max_width(unsigned char *str, int *target_width, int encoding)
3626{
3627 unsigned char *start = str;
3628 unsigned char *end = str + strlen((char *) str);
3629 int curr_width = 0;
3630
3631 while (str < end)
3632 {
3633 int char_width = PQdsplen((char *) str, encoding);
3634
3635 /*
3636 * If the display width of the new character causes the string to
3637 * exceed its target width, skip it and return. However, if this is
3638 * the first character of the string (curr_width == 0), we have to
3639 * accept it.
3640 */
3641 if (*target_width < curr_width + char_width && curr_width != 0)
3642 break;
3643
3644 curr_width += char_width;
3645
3646 str += PQmblen((char *) str, encoding);
3647
3648 if (str > end) /* Don't overrun invalid string */
3649 str = end;
3650 }
3651
3652 *target_width = curr_width;
3653
3654 return str - start;
3655}

Callers 2

print_aligned_textFunction · 0.85
print_aligned_verticalFunction · 0.85

Calls 2

PQdsplenFunction · 0.85
PQmblenFunction · 0.85

Tested by

no test coverage detected