Skip to content

StrPushFront

StrPushFront

Description

Push char into string front.

Parameters

Name Direction Description
str in Str to push char into
chr in Pointer to value to be pushed

Success

Returns str the string itself on success.

Failure

Returns NULL otherwise.

Usage example (Cross-references)

Usage examples (Cross-references)
                if (*offset + 1 <= size) {
                    char ch = (char)extract_u8(data, offset, size);
                    StrPushFront(str, ch);
                }
                break;
            // Pad on left
            for (size i = 0; i < pad_len; i++) {
                StrPushFront(o, ' ');
            }
        } else if (align == ALIGN_LEFT) {
            // Pad on left
            for (size i = 0; i < left_pad; i++) {
                StrPushFront(o, ' ');
            }
    
            if (canonical.data[0] == '-') {
                StrPushFront(&result, '-');
            }
                    // Ensure 2 digits with leading zero
                    if (hex.length == 1) {
                        StrPushFront(&hex, '0');
                    }
                    StrPushBackZstr(o, "0x");
                    // Ensure 2 digits with leading zero
                    if (hex.length == 1) {
                        StrPushFront(&hex, '0');
                    }
                    StrPushBackZstr(o, "0x");
    
                    // complete relative file path
                    StrPushFront(&output_path, '/');
                    LOG_INFO("{}", output_path);
                    StrPushFrontCstr(&output_path, project.build_dir.data, project.build_dir.length);
    // Test StrPushFront function
    bool test_str_push_front(void) {
        WriteFmt("Testing StrPushFront\n");
    
        Str s = StrInitFromZstr("World");
    
        // Push characters at the front
        StrPushFront(&s, ' ');
        StrPushFront(&s, 'o');
        StrPushFront(&s, 'l');
        // Push characters at the front
        StrPushFront(&s, ' ');
        StrPushFront(&s, 'o');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'l');
        StrPushFront(&s, ' ');
        StrPushFront(&s, 'o');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'e');
        StrPushFront(&s, 'o');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'e');
        StrPushFront(&s, 'H');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'e');
        StrPushFront(&s, 'H');
        StrPushFront(&s, 'l');
        StrPushFront(&s, 'e');
        StrPushFront(&s, 'H');
    
        // Check that the characters were inserted correctly
Last updated on