Skip to content

StrPad

Description

Pad o with ASCII spaces so its total length reaches width. content_len is the length already considered “content” (typically StrLen(o) at call time, or the length the caller plans to fill in afterwards). Padding lands on the left, right, or both sides depending on align. If content_len >= width the call is a no-op.

Parameters

Name Direction Description
o in,out Str to pad. Grows through its inline allocator.
width in Target minimum width.
align in ALIGN_LEFT / ALIGN_RIGHT / ALIGN_CENTER.
content_len in Current content length to anchor padding against.

Success

Returns true. o carries the requested padding.

Failure

Returns false on allocator OOM mid-pad. o may be left partially padded.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool StrPad(Str *o, size width, Alignment align, size content_len) {
        if (content_len >= width)
            return true;
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
                    return false;
                }
            } else if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
                    return false;
                }
            } else if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
        if (fmt_info->width > 0) {
            size content_len = o->length - start_len;
            if (!StrPad(o, fmt_info->width, fmt_info->align, content_len)) {
                return false;
            }
Last updated on