"Sputnik" help  
Sputnik Help
strcasecmp

Description

The strcasecmp function in Sputnik's preprocessor is specifically designed for case-insensitive string comparison. This function is a variation of the strcmp function, allowing developers to compare two strings, <s1> and <s2>, without considering the case of the characters. strcasecmp is particularly useful within conditional statements, such as #if directives, where case-insensitive string comparison is a common requirement. Developers can utilize StrCaseCmp to make decisions based on the lexicographical relationship between two strings, ignoring the case of the characters.

Parameters

<s1> The first string to be compared.
<s2> The second string to be compared.
[<start>] (Optional) Specifies the starting position for the comparison. If provided, the comparison starts from this position in both strings. Default is 0.
[<len>] (Optional) Specifies the length of the substring to be considered in the comparison. If provided, only a substring of the strings is compared. Default is the length of the shorter string.

Return Value

Success: Returns 0.
Failure: Returns lower/higher than zero.

Remarks

The strcasecmp function provides a convenient tool for case-insensitive string comparisons within the Sputnik preprocessor. It offers flexibility by supporting optional parameters for specifying starting positions and substring lengths, allowing developers to have precise control over the case-insensitive comparison process.

It's important to note that strcasecmp is particularly valuable within the context of #if directives, where conditional code execution depends on the result of case-insensitive string comparisons. Developers can leverage this function to create dynamic and adaptable code that responds to the lexicographical relationship between strings while ignoring the case of the characters.

Related

StrCmp

Example (#)

Example of usage:

#define foo "cat"

#if strcasecmp(foo, "CaT") == 0
    say "Condition is true";
#else
    say "Condition is false";
#endif
// PRINTS
// Condition is true

 

Example (.)

Example of usage:

#macro foo(x)
    .if strcasecmp(x, "foO") == 0
        say "It is foo";
    .elif strcasecmp(x, "bAr") == 0
        say "It is bar";
    .elif strcasecmp(x, "BAR") == 0
        say "It is BAR";
    .else
        say "It is unknown";
    .endif
#endm

foo("CAT");
foo("FoO");
foo("BaR");
foo("BAR");

// PRINTS
// It is unknown
// It is foo
// It is bar
// It is bar

Another example:

#macro Test1(x, y)
    .eq PAX, x
    .app PAX, "dog"
    .if strcasecmp(PAX, y) == 0
        "Match"
    .else
        "No Match"
    .endif
#endm

say Test1("cat", "catDOG");
// PRINTS
// Match

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org