Skip to content

StrCmpZstr

StrCmpZstr

Description

Compare string with a null-terminated const char* string

Parameters

Name Direction Description
str in Pointer to Str object to compare with.
zstr in Null-terminated string to compare with.

Returns

+ve or -ve depending on above or below in lexical ordering 0 if both are equal

Usage example (Cross-references)

Usage examples (Cross-references)
                    char *zstr = generate_cstring(data, offset, size, 20);
                    if (zstr) {
                        int result = StrCmpZstr(str, zstr);
                        (void)result; // Suppress unused variable warning
                        free(zstr);
        result = result && (KvConfigLen(&cfg) == 3);
        result = result && KvConfigContains(&cfg, "host");
        result = result && host && StrCmpZstr(host, "localhost") == 0;
        result = result && KvConfigGetI64(&cfg, "port", &port) && (port == 8080);
        result = result && KvConfigGetBool(&cfg, "debug", &debug) && debug;
        result = result && (si.pos == si.length);
        result = result && (KvConfigLen(&cfg) == 4);
        result = result && path && StrCmpZstr(path, "/srv/my app") == 0;
        result = result && user && StrCmpZstr(user, "root") == 0;
        result = result && greet && StrCmpZstr(greet, "hello world") == 0;
        result = result && (KvConfigLen(&cfg) == 4);
        result = result && path && StrCmpZstr(path, "/srv/my app") == 0;
        result = result && user && StrCmpZstr(user, "root") == 0;
        result = result && greet && StrCmpZstr(greet, "hello world") == 0;
        result = result && empty && (empty->length == 0);
        result = result && path && StrCmpZstr(path, "/srv/my app") == 0;
        result = result && user && StrCmpZstr(user, "root") == 0;
        result = result && greet && StrCmpZstr(greet, "hello world") == 0;
        result = result && empty && (empty->length == 0);
        result = result && (host_copy.length > 0);
        result = result && (host_copy.data != stored_host->data);
        result = result && (StrCmpZstr(&host_copy, "localhost") == 0);
        result = result && (StrCmpZstr(stored_host, "localhost") == 0);
        result = result && (host_copy.data != stored_host->data);
        result = result && (StrCmpZstr(&host_copy, "localhost") == 0);
        result = result && (StrCmpZstr(stored_host, "localhost") == 0);
    
        host_copy.data[0] = 'L';
        host_copy.data[0] = 'L';
    
        result = result && (StrCmpZstr(&host_copy, "Localhost") == 0);
        result = result && (StrCmpZstr(stored_host, "localhost") == 0);
    
        result = result && (StrCmpZstr(&host_copy, "Localhost") == 0);
        result = result && (StrCmpZstr(stored_host, "localhost") == 0);
    
        StrDeinit(&host_copy);
            WriteFmt("Input: '{}', Output: '{} {}'", in, result1, result2);
    
            bool test2_pass  = (StrCmpZstr(&result1, "HELLO") == 0);
            test2_pass      &= (StrCmpZstr(&result2, "WORLD") == 0);
            WriteFmt("Expected: 'HELLO WORLD', Pass: {}\n\n", test2_pass ? "true" : "false");
    
            bool test2_pass  = (StrCmpZstr(&result1, "HELLO") == 0);
            test2_pass      &= (StrCmpZstr(&result2, "WORLD") == 0);
            WriteFmt("Expected: 'HELLO WORLD', Pass: {}\n\n", test2_pass ? "true" : "false");
            success = success && test2_pass;
            WriteFmt("Input: '{}', Output: '{}{}'", in, result1, result2);
    
            bool test2_pass  = (StrCmpZstr(&result1, "HELLO") == 0);
            test2_pass      &= (StrCmpZstr(&result2, " WORLD MIGHTY MISRA") == 0); // notice the extra space
            WriteFmt("Expected: 'HELLO WORLD MIGHTY MISRA', Pass: {}\n\n", test2_pass ? "true" : "false");
    
            bool test2_pass  = (StrCmpZstr(&result1, "HELLO") == 0);
            test2_pass      &= (StrCmpZstr(&result2, " WORLD MIGHTY MISRA") == 0); // notice the extra space
            WriteFmt("Expected: 'HELLO WORLD MIGHTY MISRA', Pass: {}\n\n", test2_pass ? "true" : "false");
            success = success && test2_pass;
    #define JR_STR_KV(si, k, str)                                                                                          \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                Str my_str = StrInit();                                                                                    \
                si         = JReadString((si), &my_str);                                                                   \
    #define JR_INT_KV(si, k, i)                                                                                            \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                i64 my_int = 0;                                                                                            \
                si         = JReadInteger((si), &my_int);                                                                  \
    #define JR_FLT_KV(si, k, f)                                                                                            \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                f64 my_flt = 0;                                                                                            \
                si         = JReadFloat((si), &my_flt);                                                                    \
    #define JR_BOOL_KV(si, k, b)                                                                                           \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                bool my_b = 0;                                                                                             \
                si        = JReadBool((si), &my_b);                                                                        \
    #define JR_OBJ_KV(si, k, reader)                                                                                       \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                JR_OBJ(si, reader);                                                                                        \
            }                                                                                                              \
    #define JR_ARR_KV(si, k, reader)                                                                                       \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                JR_ARR(si, reader);                                                                                        \
            }                                                                                                              \
Last updated on