Skip to content

StrPushBackR

Description

R-form sibling of StrPushBackL: appends a single character by copy. The source is not modified. Accepts any value implicitly convertible to char (in particular, int character literals like 'x').

Success

Returns true; the character is appended at the tail.

Failure

Returns false on allocation failure. str unchanged.

Usage example (Cross-references)

Usage examples (Cross-references)
            Str UNPL(buf) = StrInit();                                                                                     \
            StrAppendFmt(&UNPL(buf), __VA_ARGS__);                                                                         \
            StrPushBackR(&UNPL(buf), '\n');                                                                                 \
            ProcWriteToStdin((p), &UNPL(buf));                                                                             \
            StrDeinit(&UNPL(buf));                                                                                         \
            bool ___is_first___ = true;                                                                                    \
            (void)___is_first___;                                                                                          \
            StrPushBackR(&(j), '{');                                                                                       \
            {writer};                                                                                                      \
            StrPushBackR(&(j), '}');                                                                                       \
            StrPushBackR(&(j), '{');                                                                                       \
            {writer};                                                                                                      \
            StrPushBackR(&(j), '}');                                                                                       \
        } while (0)
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            bool ___is_first___ = true;                                                                                    \
            (void)___is_first___;                                                                                          \
            StrPushBackR(&(j), '[');                                                                                       \
            VecForeach(&(arr), item) {                                                                                     \
                if (___is_first___) {                                                                                      \
                    ___is_first___ = false;                                                                                \
                } else {                                                                                                   \
                    StrPushBackR(&(j), ',');                                                                               \
                }                                                                                                          \
                { writer }                                                                                                 \
                { writer }                                                                                                 \
            }                                                                                                              \
            StrPushBackR(&(j), ']');                                                                                       \
        } while (0)
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
                ___is_first___ = false;                                                                                    \
            } else {                                                                                                       \
                StrPushBackR(&(j), ',');                                                                                   \
            }                                                                                                              \
            StrAppendFmt(&(j), "\"{}\":", (Zstr)(k));                                                                      \
            if (c >= 'a' && c <= 'z')
                c = (char)(c - 'a' + 'A');
            StrPushBackR(out, c);
        }
    }
        StrPushBackMany(out, "  ");
        if (sp->role == ARG_ROLE_POSITIONAL) {
            StrPushBackR(out, '<');
            StrPushBackMany(out, sp->long_name);
            StrPushBackR(out, '>');
            StrPushBackR(out, '<');
            StrPushBackMany(out, sp->long_name);
            StrPushBackR(out, '>');
        } else {
            if (sp->short_name) {
                StrPushBackMany(out, sp->long_name);
            if (sp->role == ARG_ROLE_REQUIRED || sp->role == ARG_ROLE_OPTIONAL) {
                StrPushBackR(out, ' ');
                StrPushBackR(out, '<');
                append_metavar(out, sp);
            if (sp->role == ARG_ROLE_REQUIRED || sp->role == ARG_ROLE_OPTIONAL) {
                StrPushBackR(out, ' ');
                StrPushBackR(out, '<');
                append_metavar(out, sp);
                StrPushBackR(out, '>');
                StrPushBackR(out, '<');
                append_metavar(out, sp);
                StrPushBackR(out, '>');
            }
        }
            if (sp->role != ARG_ROLE_REQUIRED)
                continue;
            StrPushBackR(&usage, ' ');
            if (sp->long_name)
                StrPushBackMany(&usage, sp->long_name);
            StrPushBackMany(&usage, " <");
            append_metavar(&usage, sp);
            StrPushBackR(&usage, '>');
        }
        VecForeachPtr(&self->specs, sp) {
            StrPushBackMany(&usage, " <");
            StrPushBackMany(&usage, sp->long_name);
            StrPushBackR(&usage, '>');
        }
        } else if (align == ALIGN_LEFT) {
            for (size i = 0; i < pad_len; i++) {
                if (!StrPushBackR(o, ' ')) {
                    return false;
                }
            }
            for (size i = 0; i < right_pad; i++) {
                if (!StrPushBackR(o, ' ')) {
                    return false;
                }
                // `{​{` is the escape for a literal '{'.
                if (i + 1 < fmt_len && fmt[i + 1] == '{') {
                    if (!StrPushBackR(o, '{')) {
                        return false;
                    }
                // `}}` escapes to a single literal '}'.
                if (i + 1 < fmt_len && fmt[i + 1] == '}') {
                    if (!StrPushBackR(o, '}')) {
                        return false;
                    }
                return false;
            } else {
                if (!StrPushBackR(o, fmt[i])) {
                    return false;
                }
        // each other's output.
        if (ok && append_newline) {
            StrPushBackR(&out, '\n');
        }
            if (fc != '{') {
                // Literal byte: emit verbatim (mirrors the read side's match).
                if (!StrPushBackR(out, fc)) {
                    return false;
                }
            char esc = 0;
            if (StrIterPeek(&fsi, &esc) && esc == '{') {
                if (!StrPushBackR(out, '{')) {
                    return false;
                }
            char buf_byte = 0;
            while (FileRead(file, &buf_byte, 1) == 1) {
                StrPushBackR(&buffer, buf_byte);
            }
            str_read_fmt(StrBegin(&buffer), fmtstr, argv, argc);
                // 'c' leaves it clear so source bytes pass through untouched.
                if (force_case) {
                    if (!StrPushBackR(o, is_caps ? TO_UPPER(byte) : TO_LOWER(byte))) {
                        return false;
                    }
                    }
                } else {
                    if (!StrPushBackR(o, byte)) {
                        return false;
                    }
                char c2  = low < 10 ? '0' + low : is_caps ? 'A' + (low - 10) : 'a' + (low - 10);
    
                if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, c1) || !StrPushBackR(o, c2)) {
                    return false;
                }
                // See `write_int_as_chars` for the force_case / 'c' split.
                if (force_case) {
                    if (!StrPushBackR(o, is_caps ? TO_UPPER(*vs) : TO_LOWER(*vs))) {
                        return false;
                    }
                    }
                } else {
                    if (!StrPushBackR(o, *vs)) {
                        return false;
                    }
                char c1  = hiw < 10 ? '0' + hiw : is_caps ? 'A' + (hiw - 10) : 'a' + (hiw - 10);
                char c2  = low < 10 ? '0' + low : is_caps ? 'A' + (low - 10) : 'a' + (low - 10);
                if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, c1) || !StrPushBackR(o, c2)) {
                    return false;
                }
            }
    
            if (!StrPushBackR(out, uppercase ? 'E' : 'e') || !StrPushBackR(out, sign)) {
                ok = false;
                break;
    
            if (digit_count < 2) {
                if (!StrPushBackR(out, '0')) {
                    ok = false;
                    break;
    
            while (digit_count > 0) {
                if (!StrPushBackR(out, data[--digit_count])) {
                    ok = false;
                    break;
    
            if (StrBegin(&canonical)[0] == '-') {
                if (!StrPushBackR(&result, '-')) {
                    goto fail;
                }
    
                if (precision > 0) {
                    if (!StrPushBackR(&result, '.')) {
                        goto fail;
                    }
                    }
                    for (u32 i = 0; i < precision; i++) {
                        if (!StrPushBackR(&result, '0')) {
                            goto fail;
                        }
            }
            if (precision > 0) {
                if (!StrPushBackR(&result, '.')) {
                    goto fail;
                }
                }
                for (u32 i = (u32)MIN2(frac, (u64)precision); i < precision; i++) {
                    if (!StrPushBackR(&result, '0')) {
                        goto fail;
                    }
        if (FloatIsZero(value)) {
            if (value->negative) {
                if (!StrPushBackR(&result, '-')) {
                    goto fail;
                }
                }
            }
            if (!StrPushBackR(&result, '0')) {
                goto fail;
            }
            }
            if (has_precision && precision > 0) {
                if (!StrPushBackR(&result, '.')) {
                    goto fail;
                }
                }
                for (u32 i = 0; i < precision; i++) {
                    if (!StrPushBackR(&result, '0')) {
                        goto fail;
                    }
    
        if (value->negative) {
            if (!StrPushBackR(&result, '-')) {
                goto fail;
            }
    
        exponent = value->exponent + (i64)StrLen(&digits) - 1;
        if (!StrPushBackR(&result, StrBegin(&digits)[0])) {
            goto fail;
        }
        frac_digits = has_precision ? precision : (StrLen(&digits) > 0 ? StrLen(&digits) - 1 : 0);
        if (frac_digits > 0) {
            if (!StrPushBackR(&result, '.')) {
                goto fail;
            }
            for (u64 i = 0; i < frac_digits; i++) {
                if (i + 1 < StrLen(&digits)) {
                    if (!StrPushBackR(&result, StrBegin(&digits)[i + 1])) {
                        goto fail;
                    }
                    }
                } else {
                    if (!StrPushBackR(&result, '0')) {
                        goto fail;
                    }
                StrForeachIdx(s, c, i) {
                    if (i > 0) {
                        if (!StrPushBackR(o, ' ')) {
                            return false;
                        }
                    StrForeachInRange(s, c, 0, len) {
                        if (IS_PRINTABLE(c)) {
                            if (!StrPushBackR(o, c)) {
                                return false;
                            }
                        } else {
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(c >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[c & 0xf])) {
                                return false;
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(c >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[c & 0xf])) {
                                return false;
                            }
                while (xs[i]) {
                    if (i > 0) {
                        if (!StrPushBackR(o, ' ')) {
                            return false;
                        }
                    for (size i = 0; i < len; i++) {
                        if (IS_PRINTABLE(xs[i])) {
                            if (!StrPushBackR(o, xs[i])) {
                                return false;
                            }
                        } else {
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(xs[i] >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[xs[i] & 0xf])) {
                                return false;
                            Zstr digits = "0123456789abcdef";
                            if (!StrPushBackMany(o, "\\x") || !StrPushBackR(o, digits[(xs[i] >> 4) & 0xf]) ||
                                !StrPushBackR(o, digits[xs[i] & 0xf])) {
                                return false;
                            }
        } else if (F64IsInf(*v)) {
            if (*v < 0) {
                if (!StrPushBackR(o, '-')) {
                    return false;
                }
                    }
    
                    StrPushBackR(s, c);
                } else if (*i == quote) {
                    i++;
                    }
    
                    StrPushBackR(s, c);
                }
            } else {
                    }
    
                    StrPushBackR(s, c);
                } else {
                    char c = *i++;
                    }
    
                    StrPushBackR(s, c);
                }
            }
        }
    
        return StrPushBackR(o, *v);
    }
        switch (fmt_info->endian) {
            case ENDIAN_BIG : {
                return StrPushBackR(o, ((x >> 8) & 0xff)) && StrPushBackR(o, (x & 0xff));
            }
            case ENDIAN_LITTLE : {
            }
            case ENDIAN_LITTLE : {
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, ((x >> 8) & 0xff));
            }
            case ENDIAN_NATIVE :
        switch (fmt_info->endian) {
            case ENDIAN_BIG : {
                return StrPushBackR(o, ((x >> 24) & 0xff)) && StrPushBackR(o, (x >> 16) & 0xff) &&
                       StrPushBackR(o, (x >> 8) & 0xff) && StrPushBackR(o, (x & 0xff));
            }
            case ENDIAN_BIG : {
                return StrPushBackR(o, ((x >> 24) & 0xff)) && StrPushBackR(o, (x >> 16) & 0xff) &&
                       StrPushBackR(o, (x >> 8) & 0xff) && StrPushBackR(o, (x & 0xff));
            }
            case ENDIAN_LITTLE : {
            }
            case ENDIAN_LITTLE : {
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, (x >> 8) & 0xff) &&
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, ((x >> 24) & 0xff));
            }
            case ENDIAN_LITTLE : {
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, (x >> 8) & 0xff) &&
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, ((x >> 24) & 0xff));
            }
            case ENDIAN_NATIVE :
        switch (fmt_info->endian) {
            case ENDIAN_BIG : {
                return StrPushBackR(o, ((x >> 56) & 0xff)) && StrPushBackR(o, (x >> 48) & 0xff) &&
                       StrPushBackR(o, (x >> 40) & 0xff) && StrPushBackR(o, (x >> 32) & 0xff) &&
                       StrPushBackR(o, (x >> 24) & 0xff) && StrPushBackR(o, (x >> 16) & 0xff) &&
            case ENDIAN_BIG : {
                return StrPushBackR(o, ((x >> 56) & 0xff)) && StrPushBackR(o, (x >> 48) & 0xff) &&
                       StrPushBackR(o, (x >> 40) & 0xff) && StrPushBackR(o, (x >> 32) & 0xff) &&
                       StrPushBackR(o, (x >> 24) & 0xff) && StrPushBackR(o, (x >> 16) & 0xff) &&
                       StrPushBackR(o, (x >> 8) & 0xff) && StrPushBackR(o, (x & 0xff));
                return StrPushBackR(o, ((x >> 56) & 0xff)) && StrPushBackR(o, (x >> 48) & 0xff) &&
                       StrPushBackR(o, (x >> 40) & 0xff) && StrPushBackR(o, (x >> 32) & 0xff) &&
                       StrPushBackR(o, (x >> 24) & 0xff) && StrPushBackR(o, (x >> 16) & 0xff) &&
                       StrPushBackR(o, (x >> 8) & 0xff) && StrPushBackR(o, (x & 0xff));
            }
                       StrPushBackR(o, (x >> 40) & 0xff) && StrPushBackR(o, (x >> 32) & 0xff) &&
                       StrPushBackR(o, (x >> 24) & 0xff) && StrPushBackR(o, (x >> 16) & 0xff) &&
                       StrPushBackR(o, (x >> 8) & 0xff) && StrPushBackR(o, (x & 0xff));
            }
            case ENDIAN_LITTLE : {
            }
            case ENDIAN_LITTLE : {
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, (x >> 8) & 0xff) &&
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, (x >> 24) & 0xff) &&
                       StrPushBackR(o, (x >> 32) & 0xff) && StrPushBackR(o, (x >> 40) & 0xff) &&
            case ENDIAN_LITTLE : {
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, (x >> 8) & 0xff) &&
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, (x >> 24) & 0xff) &&
                       StrPushBackR(o, (x >> 32) & 0xff) && StrPushBackR(o, (x >> 40) & 0xff) &&
                       StrPushBackR(o, (x >> 48) & 0xff) && StrPushBackR(o, ((x >> 56) & 0xff));
                return StrPushBackR(o, (x & 0xff)) && StrPushBackR(o, (x >> 8) & 0xff) &&
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, (x >> 24) & 0xff) &&
                       StrPushBackR(o, (x >> 32) & 0xff) && StrPushBackR(o, (x >> 40) & 0xff) &&
                       StrPushBackR(o, (x >> 48) & 0xff) && StrPushBackR(o, ((x >> 56) & 0xff));
            }
                       StrPushBackR(o, (x >> 16) & 0xff) && StrPushBackR(o, (x >> 24) & 0xff) &&
                       StrPushBackR(o, (x >> 32) & 0xff) && StrPushBackR(o, (x >> 40) & 0xff) &&
                       StrPushBackR(o, (x >> 48) & 0xff) && StrPushBackR(o, ((x >> 56) & 0xff));
            }
            case ENDIAN_NATIVE :
    
        if (config->use_prefix) {
            if (!StrPushBackR(str, '0')) {
                return NULL;
            }
            }
            if (config->base == 2) {
                if (!StrPushBackR(str, 'b')) {
                    return NULL;
                }
                }
            } else if (config->base == 8) {
                if (!StrPushBackR(str, 'o')) {
                    return NULL;
                }
                }
            } else if (config->base == 16) {
                if (!StrPushBackR(str, 'x')) {
                    return NULL;
                }
    
        if (value == 0) {
            if (!StrPushBackR(str, '0')) {
                return NULL;
            }
                // them in reverse so the destination ends up MSB-first.
                while (pos > 0) {
                    if (!StrPushBackR(str, data[--pos])) {
                        ok = false;
                        break;
            Zstr nan_str = config->uppercase ? "NAN" : "nan";
            for (size i = 0; i < 3; i++) {
                if (!StrPushBackR(str, nan_str[i])) {
                    return NULL;
                }
        if (isinf_f64(value)) {
            if (value < 0) {
                if (!StrPushBackR(str, '-')) {
                    return NULL;
                }
                }
            } else if (config->always_sign) {
                if (!StrPushBackR(str, '+')) {
                    return NULL;
                }
            Zstr inf_str = config->uppercase ? "INF" : "inf";
            for (size i = 0; i < 3; i++) {
                if (!StrPushBackR(str, inf_str[i])) {
                    return NULL;
                }
    
        if (value < 0) {
            if (!StrPushBackR(str, '-')) {
                return NULL;
            }
            value = -value;
        } else if (config->always_sign) {
            if (!StrPushBackR(str, '+')) {
                return NULL;
            }
    
            i64 int_part = (i64)mantissa;
            if (!StrPushBackR(str, '0' + int_part)) {
                return NULL;
            }
    
            if (config->precision > 0) {
                if (!StrPushBackR(str, '.')) {
                    return NULL;
                }
                    if (digit >= 10)
                        digit = 9;
                    if (!StrPushBackR(str, '0' + digit)) {
                        return NULL;
                    }
            }
    
            if (!StrPushBackR(str, config->uppercase ? 'E' : 'e')) {
                return NULL;
            }
            }
            if (exp >= 0) {
                if (!StrPushBackR(str, '+')) {
                    return NULL;
                }
                }
            } else {
                if (!StrPushBackR(str, '-')) {
                    return NULL;
                }
            if (exp == 0) {
                // Two-digit minimum matches printf("%e") convention.
                if (!StrPushBackR(str, '0') || !StrPushBackR(str, '0')) {
                    return NULL;
                }
                    }
                    while (exp_pos > 0) {
                        if (!StrPushBackR(str, data[--exp_pos])) {
                            ok = false;
                            break;
    
            if (int_part == 0) {
                if (!StrPushBackR(str, '0')) {
                    return NULL;
                }
                    }
                    while (int_pos > 0) {
                        if (!StrPushBackR(str, data[--int_pos])) {
                            ok = false;
                            break;
    
            if (config->precision > 0) {
                if (!StrPushBackR(str, '.')) {
                    return NULL;
                }
                    }
    
                    if (!StrPushBackR(str, '0' + digit)) {
                        return NULL;
                    }
    
        if (IntIsZero(value)) {
            return StrPushBackR(out, '0');
        }
            // place value); the most significant chunk stops at its top digit.
            for (u32 k = 0; (k < chunk_digits) && !(last && rem == 0 && k > 0); k++) {
                if (!StrPushBackR(&result, int_radix_char((u8)(rem % radix), uppercase))) {
                    IntDeinit(&chunk_divisor);
                    IntDeinit(&quotient);
    
            if (ch >= '0' && ch <= '9') {
                if (!StrPushBackR(&digits, ch)) {
                    goto fail;
                }
    
        if (FloatIsZero(value)) {
            return StrPushBackR(out, '0');
        }
    
        if (value->negative) {
            if (!StrPushBackR(&result, '-')) {
                goto fail;
            }
    
            for (i64 i = 0; i < value->exponent; i++) {
                if (!StrPushBackR(&result, '0')) {
                    goto fail;
                }
            if (split > 0) {
                for (i64 i = 0; i < split; i++) {
                    if (!StrPushBackR(&result, StrCharAt(&digits, i))) {
                        goto fail;
                    }
                }
    
                if (!StrPushBackR(&result, '.')) {
                    goto fail;
                }
    
                for (u64 i = (u64)split; i < StrLen(&digits); i++) {
                    if (!StrPushBackR(&result, StrCharAt(&digits, i))) {
                        goto fail;
                    }
    
                for (i64 i = 0; i < -split; i++) {
                    if (!StrPushBackR(&result, '0')) {
                        goto fail;
                    }
        for (u64 i = 0; i < bv->length; i++) {
            char bit_char = BitVecGet(bv, i) ? '1' : '0';
            if (!StrPushBackR(out, bit_char)) {
                StrDeinit(out);
                *out = StrInit(alloc);
        if (n == 0)
            return;
        StrPushBackR(out, hex[id[0] >> 4]);
        StrPushBackR(out, hex[id[0] & 0xf]);
        StrPushBackR(out, '/');
            return;
        StrPushBackR(out, hex[id[0] >> 4]);
        StrPushBackR(out, hex[id[0] & 0xf]);
        StrPushBackR(out, '/');
        for (u32 i = 1; i < n; ++i) {
        StrPushBackR(out, hex[id[0] >> 4]);
        StrPushBackR(out, hex[id[0] & 0xf]);
        StrPushBackR(out, '/');
        for (u32 i = 1; i < n; ++i) {
            StrPushBackR(out, hex[id[i] >> 4]);
        StrPushBackR(out, '/');
        for (u32 i = 1; i < n; ++i) {
            StrPushBackR(out, hex[id[i] >> 4]);
            StrPushBackR(out, hex[id[i] & 0xf]);
        }
        for (u32 i = 1; i < n; ++i) {
            StrPushBackR(out, hex[id[i] >> 4]);
            StrPushBackR(out, hex[id[i] & 0xf]);
        }
    }
            StrResize(&path, 0);
            sys_append_dirname(&path, main_path);
            StrPushBackR(&path, '/');
            StrPushBackMany(&path, main->debuglink_name);
            if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
            StrPushBackMany(&path, cand_prefix);
            sys_append_dirname(&path, main_path);
            StrPushBackR(&path, '/');
            StrPushBackMany(&path, main->debuglink_name);
            if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
        sys_append_dirname(out_path, pe_path);
        if (StrLen(out_path) > 0)
            StrPushBackR(out_path, '/');
        StrPushBackMany(out_path, pdb_base);
        if (sys_path_exists(StrBegin(out_path)))
                c = (char)(c + ('a' - 'A'));
            }
            StrPushBackR(out, c);
        }
    }
                StrAppendFmt(out, " ({}:{})", fname, (u32)line.LineNumber);
            }
            StrPushBackR(out, '\n');
        }
            }
        }
        StrPushBackR(out, '\n');
    }
        StrPushBackMany(&cmdline, filepath);
        for (char **arg = argv + 1; *arg; ++arg) {
            StrPushBackR(&cmdline, ' ');
            StrPushBackMany(&cmdline, *arg);
        }
        u64 len = (u64)(last_sep - path);
        for (u64 i = 0; i < len; ++i)
            StrPushBackR(out, path[i]);
    }
                        u64 offset = StrLen(pool);
                        for (u64 i = 0; i < nlen; ++i) {
                            if (!StrPushBackR(pool, src[i]))
                                return false;
                        }
                                return false;
                        }
                        if (!StrPushBackR(pool, '\0'))
                            return false;
                        PendingFn pf = {.low_pc = low_pc, .high_pc = hi, .name_offset_in_pool = offset};
            }
            if (label_idx > 0) {
                StrPushBackR(out_name, '.');
                ++name_len;
            }
            }
            for (u64 i = 0; i < label_len; ++i) {
                StrPushBackR(out_name, (char)*IterDataAt(it, cur + 1 + i));
            }
            name_len += label_len;
            }
    
            StrPushBackR(key, c);
            StrIterMustNext(&si);
        }
                    switch (c) {
                        case 'n' :
                            StrPushBackR(value, '\n');
                            break;
                        case 'r' :
                            break;
                        case 'r' :
                            StrPushBackR(value, '\r');
                            break;
                        case 't' :
                            break;
                        case 't' :
                            StrPushBackR(value, '\t');
                            break;
                        default :
                        default :
                            // Pass any other escaped character through verbatim.
                            StrPushBackR(value, c);
                            break;
                    }
                }
    
                StrPushBackR(value, c);
                StrIterMustNext(&si);
            }
            }
    
            StrPushBackR(value, c);
            StrIterMustNext(&si);
        }
        if (!StrPushBackMany(pool, s))
            return false;
        return StrPushBackR(pool, '\0');
    }
                            // escape sequence
                            case '\\' :
                                StrPushBackR(str, '\\');
                                StrIterMustNext(&si);
                                break;
    
                            case '"' :
                                StrPushBackR(str, '"');
                                StrIterMustNext(&si);
                                break;
    
                            case '/' :
                                StrPushBackR(str, '/');
                                StrIterMustNext(&si);
                                break;
    
                            case 'b' :
                                StrPushBackR(str, '\b');
                                StrIterMustNext(&si);
                                break;
    
                            case 'f' :
                                StrPushBackR(str, '\f');
                                StrIterMustNext(&si);
                                break;
    
                            case 'n' :
                                StrPushBackR(str, '\n');
                                StrIterMustNext(&si);
                                break;
    
                            case 'r' :
                                StrPushBackR(str, '\r');
                                StrIterMustNext(&si);
                                break;
    
                            case 't' :
                                StrPushBackR(str, '\t');
                                StrIterMustNext(&si);
                                break;
                    // default allowed characters
                    default :
                        StrPushBackR(str, c);
                        StrIterMustNext(&si);
                        break;
                    has_exp = true;
                    is_flt  = true;
                    StrPushBackR(&ns, c);
                    StrIterMustNext(&si);
                    break;
                    }
                    is_flt = true;
                    StrPushBackR(&ns, c);
                    StrIterMustNext(&si);
                    break;
                case '8' :
                case '9' :
                    StrPushBackR(&ns, c);
                    StrIterMustNext(&si);
                    break;
                    }
                    has_exp_plus_minus = true;
                    StrPushBackR(&ns, c);
                    StrIterMustNext(&si);
                    break;
        if (!StrPushBackMany(pool, s))
            return false;
        if (!StrPushBackR(pool, '\0'))
            return false;
        *out_offset = start;
        // Pattern "101" as a Str on a separate (untracked) allocator.
        Str pattern = StrInit(pbase);
        StrPushBackR(&pattern, '1');
        StrPushBackR(&pattern, '0');
        StrPushBackR(&pattern, '1');
        Str pattern = StrInit(pbase);
        StrPushBackR(&pattern, '1');
        StrPushBackR(&pattern, '0');
        StrPushBackR(&pattern, '1');
        StrPushBackR(&pattern, '1');
        StrPushBackR(&pattern, '0');
        StrPushBackR(&pattern, '1');
    
        bool matched = bitvec_regex_match_str(&bv, &pattern);
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x0F); // single byte 0x0F -> "f"
    
        StrAppendFmt(&output, "{X}", s);
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x0F);
    
        StrAppendFmt(&output, "{x}", s);
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x02);
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x02);
    
        StrAppendFmt(&output, "{x}", s);
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x05);
    
        StrAppendFmt(&output, "{x}", s);
        // 0x1A: hi nibble 0x01 (<10 -> '1'), low nibble 0x0A (>=10 -> 'a') => "\x1a".
        Str src = StrInit(&alloc);
        StrPushBackR(&src, 0x1A);
        StrAppendFmt(&out, "{c}", src);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\x1a") == 0);
        // 0xA1: low nibble 0x01 (<10 -> '1') -- pins the low digit on the <10 side
        // of the boundary too => "\xa1".
        StrPushBackR(&src, 0xA1);
        StrAppendFmt(&out, "{c}", src);
        ok = ok && (ZstrCompare(StrBegin(&out), "\\xa1") == 0);
        DBG_BEGIN(dbg, out);
        Str s = StrInit(&dbg);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x4F); // multi-digit so StrLen(&hex)!=1 path
        StrAppendFmt(&out, "{x}", s);
        Str s = StrInit(&dbg);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x4F); // multi-digit so StrLen(&hex)!=1 path
        StrAppendFmt(&out, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "0x01 0x4f") == 0);
        DBG_BEGIN(dbg, out);
        Str s = StrInit(&dbg);
        StrPushBackR(&s, (char)0x05);
        StrAppendFmt(&out, "{x}", s);
        bool ok = (ZstrCompare(StrBegin(&out), "0x05") == 0);
        Str           s  = StrInit(ALLOCATOR_OF(&sa));
        for (int i = 0; i < 8; ++i)
            StrPushBackR(&s, (char)0xAB);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            out = StrInit(ALLOCATOR_OF(&dbg));
    
        // Push characters at the back
        StrPushBackR(&s, ' ');
        StrPushBackR(&s, 'W');
        StrPushBackR(&s, 'o');
        // Push characters at the back
        StrPushBackR(&s, ' ');
        StrPushBackR(&s, 'W');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'r');
        StrPushBackR(&s, ' ');
        StrPushBackR(&s, 'W');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'r');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'W');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'r');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'd');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'r');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'd');
        StrPushBackR(&s, 'r');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'd');
    
        // Check that the characters were inserted correctly
    
        // Check that it behaves like a Vec of chars
        StrPushBackR(&s, 'H');
        StrPushBackR(&s, 'e');
        StrPushBackR(&s, 'l');
        // Check that it behaves like a Vec of chars
        StrPushBackR(&s, 'H');
        StrPushBackR(&s, 'e');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'H');
        StrPushBackR(&s, 'e');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'e');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'o');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'l');
        StrPushBackR(&s, 'o');
    
        bool result = (StrLen(&s) == 5 && ZstrCompare(StrBegin(&s), "Hello") == 0);
        StrForeach(&s, chr) {
            // Append the character to the result string
            StrPushBackR(&result, chr);
        }
        StrForeachReverse(&s, chr) {
            // Append the character to the result string
            StrPushBackR(&result, chr);
            char_count++;
        }
        StrForeachPtr(&s, chrptr) {
            // Append the character (via pointer) to the result string
            StrPushBackR(&result, *chrptr);
    
            // Modify the original string by converting to uppercase
        StrForeachPtrReverse(&s, chrptr) {
            // Append the character (via pointer) to the result string
            StrPushBackR(&result, *chrptr);
    
            // Modify the original string by converting to uppercase
        StrForeachInRangeIdx(&s, chr, idx, 3, 3) {
            // This block should not execute
            StrPushBackR(&empty_result, chr);
        }
        StrForeachInRange(&s, chr, 0, 5) {
            // Append the character to the result string
            StrPushBackR(&result, chr);
        }
        StrForeachInRange(&s, chr, 6, 11) {
            // Append the character to the result string
            StrPushBackR(&end_result, chr);
        }
        StrForeachPtrInRange(&s, chrptr, 0, 5) {
            // Append the character to the result string
            StrPushBackR(&result, *chrptr);
    
            // Modify the original string by converting to uppercase
        result      = result && StrEmpty(&s);
    
        StrPushBackR(&s, 'H');
        StrPushBackR(&s, 'i');
    
        StrPushBackR(&s, 'H');
        StrPushBackR(&s, 'i');
    
        result = result && (StrLen(&s) == 2);
            char c = StrBegin(output)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&output_clean, c);
            }
        }
            char c = StrBegin(&expected_str)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&expected_clean, c);
            }
        }
            char c = StrBegin(output)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&output_clean, c);
            }
        }
            char c = StrBegin(&expected_str)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&expected_clean, c);
            }
        }
            char c = StrBegin(output)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&output_clean, c);
            }
        }
            char c = StrBegin(&expected_str)[i];
            if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
                StrPushBackR(&expected_clean, c);
            }
        }
Last updated on