The xtype C Library, Version 1.00
The XSTR Type
Contents:
- fgetxstr
- xstrcast
- xstrcat
- xstrcatc
- xstrch
- xstrcpy
- xstrcvt
- xstrdel
- xstrfree
- xstrlen
- xstrncat
- xstrncpy
- xstrnew
- xstrtrunc
XSTR *fgetxstr(XSTR *xstr, FILE *f)
Function
Read one line of a stream f, terminated by a line feed ('\n') character, into a
string pointed to by xstr, as fgets().
Returns
- NULL, if there is an error. If feof(f) and ferror(f) are both false, then
there was a memory allocation failure.
- xstr, otherwise.
char *xstrcast(XSTR *xstr)
Function
Typecast the string pointed to by xstr as a normal null-terminated character
string. xstrcast() is implemented as a macro.
Returns
- A pointer to the null-terminated string represented by xstr.
XSTR *xstrcat(XSTR *xstr, char *psz)
Function
Concatenate the string pointed to by psz to the end of the string pointed to by
xstr, as strcat().
Returns
- NULL, if there was a memory allocation failure. The string pointed to by
xstr will not be changed if this is the case.
- xstr, otherwise
XSTR *xstrcatc(XSTR *xstr, char ch)
Function
Concatenate the character ch to the end of the string pointed to by xstr.
Returns
- NULL, if there was a memory allocation failure. The string pointed to by
xstr will not be changed if this is the case.
- xstr, otherwise
char xstrch(XSTR *xstr, int n)
Function
Pick out the nth character of the string pointed to by xstr; equivalent to
xstrcast(xstr)[n]. xstrch() is implemented as a macro.
Returns
- The character in position n in the string pointed to by xstr.
XSTR *xstrcpy(XSTR *xstr, char *psz)
Function
Copy the string pointed to by psz into the string pointed to by xstr, as
strcpy().
Returns
- NULL, if there was a memory allocation failure. The string pointed to by
xstr will not be changed if this is the case.
- xstr, otherwise
char *xstrcvt(XSTR *xstr)
Function
Convert the string pointed to by xstr into a normal null-terminated character
string. All the memory associated with xstr will be de-allocated, so do not
use xstr after calling this function. The pointer returned should be freed
with free() when it is no longer required.
Returns
- A pointer to a null-terminated character string containing the string
pointed to by xstr.
XSTR *xstrdel(XSTR *xstr, int n1, int n2)
Function
Shorten the string pointed to by xstr by removing characters n1 to n2,
inclusive.
Returns
void xstrfree(XSTR *xstr)
Function
De-allocate the memory used by the string pointed to by xstr. Do not use xstr
after calling this function.
int xstrlen(XSTR *xstr)
Function
Compute the length of the string pointed to by xstr, equivalent to
strlen(xstrcast(xstr)). xstrlen() is implemented as a macro.
Returns
- The number of characters in the string pointed to by xstr.
XSTR *xstrncat(XSTR *xstr, char *psz, int n)
Function
Concatenate at most n characters from the string pointed to by psz to the string
pointed to by xstr. Unlike strncat(), this function will ensure that the
resulting string is null-terminated.
Returns
- NULL, if there was a memory allocation failure. The string pointed to by
xstr will not be changed if this is the case.
- xstr, otherwise
XSTR *xstrncpy(XSTR *xstr, char *psz, int n)
Function
Copy at most n characters from the string pointed to by psz into the string
pointed to by xstr. Unlike strncpy(), this function will ensure that the
resulting string is null-terminated.
Returns
- NULL, if there was a memory allocation failure. The string pointed to by
xstr will not be changed if this is the case.
- xstr, otherwise
XSTR *xstrnew(int n, int b)
Function
Create a new string with initial space for n characters. The space allocated for
the string will grow by b characters whenever the string exceeds the length
currently set aside for it.
Returns
- NULL, if there was a memory allocation failure.
- a pointer to the newly-created string, otherwise, which can be de-allocated
by using xstrfree(), or xstrcvt() and free().
XSTR *xstrtrunc(XSTR *xstr, int n)
Function
Truncate the string pointed to by xstr to be no longer than n characters. If
the length of xstr is less than n, this function does nothing.
Returns