StrCmpCstr

Table of Contents

StrCmpCstr

Description

Compare string with another const char* of specified length

Parameters

NameDirectionDescription
strinPointer to Str object to compare with.
cstrinString to compare with.
cstr_leninLength of the C string to compare.

Usage example (Cross-references)

    });
    
    if (StrCmpCstr(&name, "Alice", 5) != 0) {
    printf("[DEBUG] Name check failed: expected 'Alice', got '");
    for (size i = 0; i < name.length; i++) {
    }
    
    if (StrCmpCstr(&city, "New York", 8) != 0) {
    printf("[DEBUG] City check failed: expected 'New York', got '");
    for (size i = 0; i < city.length; i++) {
    }
    
    if (StrCmpCstr(&person.name, "Bob", 3) != 0) {
    printf("[DEBUG] Person name check failed: expected 'Bob', got '");
    for (size i = 0; i < person.name.length; i++) {
    }
    
    if (StrCmpCstr(&config.log_level, "INFO", 4) != 0) {
    printf("[DEBUG] Log level check failed: expected 'INFO', got '");
    for (size i = 0; i < config.log_level.length; i++) {
    Str* lang3 = &VecAt(&languages, 2);
    
    if (StrCmpCstr(lang1, "C", 1) != 0) {
    printf("[DEBUG] Language 1 check failed: expected 'C', got '");
    for (size i = 0; i < lang1->length; i++) {
    }
    
    if (StrCmpCstr(lang2, "Python", 6) != 0) {
    printf("[DEBUG] Language 2 check failed: expected 'Python', got '");
    for (size i = 0; i < lang2->length; i++) {
    }
    
    if (StrCmpCstr(lang3, "Rust", 4) != 0) {
    printf("[DEBUG] Language 3 check failed: expected 'Rust', got '");
    for (size i = 0; i < lang3->length; i++) {
    });
    
    if (StrCmpCstr(&data.user.name, "Charlie", 7) != 0) {
    printf("[DEBUG] User name check failed: expected 'Charlie', got '");
    for (size i = 0; i < data.user.name.length; i++) {
    }
    
    if (StrCmpCstr(&data.user.email, "charlie@example.com", 19) != 0) {
    printf("[DEBUG] User email check failed: expected 'charlie@example.com', got '");
    for (size i = 0; i < data.user.email.length; i++) {
    }
    
    if (StrCmpCstr(&product.name, "Laptop", 6) != 0) {
    printf("[DEBUG] Product name check failed: expected 'Laptop', got '");
    for (size i = 0; i < product.name.length; i++) {
    Str* tag3 = &VecAt(&product.tags, 2);
    
    if (StrCmpCstr(tag1, "electronics", 11) != 0) {
    printf("[DEBUG] Tag 1 check failed: expected 'electronics', got '");
    for (size i = 0; i < tag1->length; i++) {
    }
    
    if (StrCmpCstr(tag2, "computers", 9) != 0) {
    printf("[DEBUG] Tag 2 check failed: expected 'computers', got '");
    for (size i = 0; i < tag2->length; i++) {
    }
    
    if (StrCmpCstr(tag3, "portable", 8) != 0) {
    printf("[DEBUG] Tag 3 check failed: expected 'portable', got '");
    for (size i = 0; i < tag3->length; i++) {
    });
    
    if (StrCmpCstr(&obj.name, "test", 4) == 0 && obj.value == 42 && obj.flag == true) {
    printf(
    "[DEBUG] Whitespace variations test passed - name: %s, value: %d, flag: %s\n",
    }
    
    if (StrCmpCstr(&data.name, "test", 4) != 0) {
    printf("[DEBUG] Name check failed: expected 'test', got '");
    for (size i = 0; i < data.name.length; i++) {
    }
    
    if (StrCmpCstr(&data.user.profile.name, "Alice", 5) != 0) {
    printf("[DEBUG] Profile name check failed: expected 'Alice', got '");
    for (size i = 0; i < data.user.profile.name.length; i++) {
    }
    
    if (StrCmpCstr(&data.status, "active", 6) != 0) {
    printf("[DEBUG] Status check failed: expected 'active', got '");
    for (size i = 0; i < data.status.length; i++) {
    });
    
    if (StrCmpCstr(&data.company.departments.engineering.head, "John", 4) != 0) {
    printf("[DEBUG] Engineering head check failed: expected 'John', got '");
    for (size i = 0; i < data.company.departments.engineering.head.length; i++) {
    }
    
    if (StrCmpCstr(&data.company.name, "TechCorp", 8) != 0) {
    printf("[DEBUG] Company name check failed: expected 'TechCorp', got '");
    for (size i = 0; i < data.company.name.length; i++) {
    
    // Debug message check
    if (StrCmpCstr(&response.message, "Success", 7) != 0) {
    printf("[DEBUG] Message check failed: expected 'Success', got '");
    for (size i = 0; i < response.message.length; i++) {
    }
    
    if (StrCmpCstr(&sym->analysis_name, "test_analysis", 13) != 0) {
    printf("[DEBUG] Analysis name check failed: expected 'test_analysis', got '");
    for (size i = 0; i < sym->analysis_name.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_name, "main_func", 9) != 0) {
    printf(
    "[DEBUG] Function name check failed: expected 'main_func', got string of length %zu\n",
    }
    
    if (StrCmpCstr(&sym->sha256, "abc123", 6) != 0) {
    printf("[DEBUG] SHA256 check failed: expected 'abc123', got '");
    for (size i = 0; i < sym->sha256.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_mangled_name, "_Z4main", 7) != 0) {
    printf("[DEBUG] Mangled name check failed: expected '_Z4main', got '");
    for (size i = 0; i < sym->function_mangled_name.length; i++) {
    }
    
    if (StrCmpCstr(&info.name, "test_func", 9) != 0) {
    printf("[DEBUG] Function name check failed: expected 'test_func', got '");
    for (size i = 0; i < info.name.length; i++) {
    }
    
    if (StrCmpCstr(&info.name, "test_model", 10) != 0) {
    printf("[DEBUG] Model name check failed: expected 'test_model', got '");
    for (size i = 0; i < info.name.length; i++) {
    }
    
    if (StrCmpCstr(&result.binary_name, "test_binary", 11) != 0) {
    printf("[DEBUG] Binary name check failed: expected 'test_binary', got '");
    for (size i = 0; i < result.binary_name.length; i++) {
    }
    
    if (StrCmpCstr(&result.sha256, "abc123", 6) != 0) {
    printf("[DEBUG] SHA256 check failed: expected 'abc123', got '");
    for (size i = 0; i < result.sha256.length; i++) {
    }
    
    if (StrCmpCstr(&result.model_name, "test_model", 10) != 0) {
    printf("[DEBUG] Model name check failed: expected 'test_model', got '");
    for (size i = 0; i < result.model_name.length; i++) {
    }
    
    if (StrCmpCstr(&result.owned_by, "user1", 5) != 0) {
    printf("[DEBUG] Owned by check failed: expected 'user1', got '");
    for (size i = 0; i < result.owned_by.length; i++) {
    }
    
    if (StrCmpCstr(&response.message, "Success", 7) != 0) {
    printf("[DEBUG] Message check failed: expected 'Success', got '");
    for (size i = 0; i < response.message.length; i++) {
    }
    
    if (StrCmpCstr(&sym->analysis_name, "test_analysis", 13) != 0) {
    printf("[DEBUG] Analysis name check failed: expected 'test_analysis', got '");
    for (size i = 0; i < sym->analysis_name.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_name, "main_func", 9) != 0) {
    printf(
    "[DEBUG] Function name check failed: expected 'main_func', got string of length %zu\n",
    }
    
    if (StrCmpCstr(&sym->sha256, "abc123", 6) != 0) {
    printf("[DEBUG] SHA256 check failed: expected 'abc123', got '");
    for (size i = 0; i < sym->sha256.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_mangled_name, "_Z4main", 7) != 0) {
    printf("[DEBUG] Mangled name check failed: expected '_Z4main', got '");
    for (size i = 0; i < sym->function_mangled_name.length; i++) {
    }
    
    if (StrCmpCstr(&response.message, "Success", 7) != 0) {
    printf("[DEBUG] Message check failed: expected 'Success', got '");
    for (size i = 0; i < response.message.length; i++) {
    }
    
    if (StrCmpCstr(&sym->analysis_name, "test_analysis", 13) != 0) {
    printf("[DEBUG] Analysis name check failed: expected 'test_analysis', got '");
    for (size i = 0; i < sym->analysis_name.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_name, "main_func", 9) != 0) {
    printf("[DEBUG] Function name check failed: expected 'main_func', got '");
    for (size i = 0; i < sym->function_name.length; i++) {
    }
    
    if (StrCmpCstr(&sym->sha256, "abc123", 6) != 0) {
    printf("[DEBUG] SHA256 check failed: expected 'abc123', got '");
    for (size i = 0; i < sym->sha256.length; i++) {
    }
    
    if (StrCmpCstr(&sym->function_mangled_name, "_Z4main", 7) != 0) {
    printf("[DEBUG] Mangled name check failed: expected '_Z4main', got '");
    for (size i = 0; i < sym->function_mangled_name.length; i++) {
    str_obj = BitVecToStr(&bv);
    result  = result && (str_obj.length == 1);
    result  = result && (StrCmpCstr(&str_obj, "1", 1) == 0);
    StrDeinit(&str_obj);
    // Test string comparison functions
    bool test_str_cmp(void) {
    printf("Testing StrCmp and StrCmpCstr\n");
    
    Str s1 = StrInitFromZstr("Hello");
    
    // Test StrCmpCstr
    int cmp4 = StrCmpCstr(&s1, "Hello", 5);
    result   = result && (cmp4 == 0);
    result   = result && (cmp4 == 0);
    
    int cmp5 = StrCmpCstr(&s1, "World", 5);
    result   = result && (cmp5 != 0);

Share :