Copyright (c) Hyperion Entertainment and contributors.

String Functions

From AmigaOS Documentation Wiki
Jump to navigation Jump to search

String Functions

Regular String Functions

These functions perform operations on strings with no regard for localization.

Currently implemented are:

Strlcat() Length limited string concatenation.
Strlcpy() Length limited string copy.
VASPrintf Formatted output conversion with result are stored in dynamically allocated buffer.
VSNPrintf Length limited formatted output conversion.

International String Functions

When the localization library is opened, these functions will be replaced by ones which will take the locale as defined by the user into account. This means that the compare order may change according to the locale, so care should be taken not to rely on obtaining specific compare sequences.

Currently implemented are:

Stricmp() Compare string case-insensitive.
Strnicmp() Compare string case-insensitive, with a specified length.
ToLower() Convert a character to lower case.
ToUpper() Convert a character to upper case.

These functions operate in the same manner as their ANSI C equivalents, for the most part. For more information, see the "Utility Library" Autodocs in the SDK. Here is a simple example of the usage of the international string functions.

/*
** istr.c
*/
 
#include <exec/types.h>
 
#include <proto/exec.h>
#include <proto/utility.h>
 
int main()
{
    CONST_STRPTR butter = "Bøtervløøt";
    CONST_STRPTR bread = "Knåckerbrøt";
 
    int32 result = IUtility->Stricmp(butter, bread);
 
    IDOS->Printf("comparing %s with %s yields %ld\n", butter, bread, result );
 
    result = IUtility->Strnicmp(bread, butter, strlen(bread));
 
    IDOS->Printf("comparing (with length) %s with %s yields %ld\n", bread, butter, result );
 
    uint8 ch1 = IUtility->ToUpper(0xE6); /* ASCII character 230 ae ligature */
    uint8 ch2 = IUtility->ToLower(0xD0); /* ASCII character 208 Icelandic Eth */
 
    IDOS->Printf("Chars %lc %lc\n", ch1, ch2);
 
    return 0;
}