StrPushFront

Table of Contents

StrPushFront

Description

Push char into string front.

Parameters

NameDirectionDescription
strinStr to push char into
chrinPointer to value to be pushed

Success

Returns str the string itself on success.

Failure

Returns NULL otherwise.

Usage example (Cross-references)

    // 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, ' ');
    }
    // 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) {
    printf("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

Share :