General Info

Interface: StringMan
Files: stringman.h
Last Change: 10/05/2005
Author: Luiz Henrique Shigunov
Description
System Functions

0x00 - Compare - Compare two strings
0x01 - Concatenate - Concatenate two strings
0x02 - Copy - Copy a string
0x03 - FindChar - Find a char in a string
0x04 - FindLastChar - Find the last char in a string
0x05 - Length - Get a string size
0x06 - NCompare - Compare N chars from two strings
0x07 - NConcatenate - Concatenate N chars from two strings

0x08 - NCopy - Copy N chars from a string
0x0c - NLength - Get a string size
0x0d - NPrintF - Format a string
0x0a - NPrintFArgs - Format a string passing a parameters array
0x09 - PrintF - Format a string
0x0e - ScanF - Input format conversion
0x0f - ScanFArgs - Input format conversion passing a parameters array
0x0b - StrToInt - Convert a string into a integer

Description

This page describes the StringMan interface which provides many functions to manipulate strings.

0x00 - Compare

Syntax

long StringMan_Compare(const char *s1, const char *s2);

Properties

Description

This function compares s1 with s2. It's a case sensive comparation.

Return value

< 0 - if s1 is less than s2;
= 0 - if s1 is equal to s2;
> 0 - if s1 is greater than s2.

0x01 - Concatenate

Syntax

void StringMan_Concatenate(char *dest, const char *src);

Properties

Description

This function concatenates src in dest overwriting the last 0 of dest and putting a 0 in the end of dest.

The strings may not overlap and dest must have enough space.

Return value

Nothing.

0x02 - Copy

Syntax

void StringMan_Copy(char *dest, const char *src);

Properties

Description

This function copies the string src (including final 0) to the string dest.

The strings may not overlap and dest must have enough space.

Return value

Nothing.

0x03 - FindChar

Syntax

char *StringMan_FindChar(const char *s, long c);

Properties

Description

This function finds the first ocurrence of the char c in the string s.

Return value

A pointer to the matched char;
NULL if not found.

0x04 - FindLastChar

Syntax

char *StringMan_FindLastChar(const char *s, long c);

Properties

Description

This function finds the last ocurrence of the char c in the string s.

Return value

A pointer to the matched char;
NULL if not found.

0x05 - Length

Syntax

unsigned long StringMan_Length(const char *s);

Properties

Description

This function gets the size of the string s not including the last zero.

Return value

The number of chars in s.

0x06 - NCompare

Syntax

long StringMan_NCompare(const char *s1, const char *s2, unsigned long count);

Properties

Description

This function compares no more than count bytes from s1 with s2. It's a case sensive comparation.

Return value

< 0 - if s1 is less than s2;
= 0 - if s1 is equal to s2;
> 0 - if s1 is greater than s2.

0x07 - NConcatenate

Syntax

void StringMan_NConcatenate(char *dest, const char *src, unsigned long count);

Properties

Description

This function concatenates no more than count bytes from src in dest overwriting the final zero from dest.

The strings may not overlap and dest must have enough space.

Return value

Nothing.

0x08 - NCopy

Syntax

long StringMan_NCopy(char *dest, const char *src, unsigned long count);

Properties

Description

This function copies no more than count minus 1 bytes from the string src to the string dest, ending dest with a zero, that is, dest will always be a valid string.

The strings may not overlap and dest must have enough space.

If count is zero nothing happens and it returns zero.

If count is one, dest will be terminated with zero and it returns zero only if src is an empty string, that is, it copied till the end.

Return value

Zero if copied till the end of src other value otherwise.

0x0c - NLength

Syntax

unsigned long StringMan_NLength(const char *s, unsigned long count);

Properties

Description

This function gets the size of the string s not including the terminating zero, but at most count.

This way, s will only be examined at the first count characters.

Return value

The number of chars in s or count if the size of s is greater then count.

0x0d - NPrintF

Syntax

long StringMan_NPrintF(char *buf, unsigned long size, const char *fmt, ...);

Properties

Description

This function puts in buf the formated string according to fmt, but it won't write more than size characters.

fmt accepts the same options as NPrintFArgs.

Return value

The number of written bytes or the number of bytes which would have been written in case size is not big enough.

0x0a - NPrintFArgs

Syntax

long StringMan_NPrintFArgs(char *buf, unsigned long size, const char *fmt, va_list args);

Properties

Description

This function puts in buf the formated string according to fmt, but it won't write more than size characters. args is an array of parameters.

The stdarg.h file must be included. Is in this file that va_list is defined.

This function supports the following flags: #, 0, -, + and ' ' (space), the following length modifier: h, l, ll, L and Z and the following conversion specifier: d, i, o, u, x, X, c, s, p, n and %.

Return value

The number of written bytes or the number of bytes which would have been written in case size is not big enough.

0x09 - PrintF

Syntax

long StringMan_PrintF(char *buf, const char *fmt, ...);

Properties

Description

This function puts in buf the formated string according to fmt.

fmt accepts the same options as NPrintFArgs.

Return value

The number of written bytes.

0x0e - ScanF

Syntax

long StringMan_ScanF(const char *buf, const char *fmt, ...);

Properties

Description

This function scans buf according to fmt.

fmt accepts the same options as ScanFArgs.

Return value

The number of assigned items.

0x0f - ScanFArgs

Syntax

long StringMan_ScanFArgs(const char *buf, const char *fmt, va_list args);

Properties

Description

This function scans buf according to fmt. args is an array of parameters.

The stdarg.h file must be included. Is in this file that va_list is defined.

This function supports the following flags: *, the following length modifier: h, l, L and Z and the following conversion specifier: d, i, o, u, x, X, c, s, n and %.

Return value

The number of assigned items.

0x0b - StrToInt

Syntax

long StringMan_StrToInt(const char *str, char **endstr, long base, long *error);

Properties

Description

This function converts the string in str to a long integer value according to the given base, which must be between 2 and 36 inclusive, or be the special value 0.

The string must begin with an arbitrary amount of white space (' ', '\n', '\t', '\r', '\f', '\v') followed by a single optional '+' or '-' sign. If base is zero or 16, the string may then include a '0x' prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal).

The remainder of the string is converted to a long int value in the obvious manner, stopping at the first character which is not a valid digit in the given base. (In bases above 10, the letter 'A' in either upper or lower case represents 10, 'B' represents 11, and so forth, with 'Z' representing 35).

If endstr is not NULL, this function stores the address of the first invalid character in *endstr. If there were no digits at all, this function stores the original value of str in *endstr. (Thus, if *str is not '\0' but **endstr is '\0' on return, the entire string is valid).

error can be NULL.

Return value

The converted number;
0 if base is wrong and error is 1;
The biggest positive number if overflow occurs and error is 2;
The smallest negative number if underflow occurs and error is 2.