BOOTSTRAP (kutils) functions
LIBRARY ROUTINE
kstring_replace - replace one substring with another
LIBRARY CALL
char *kstring_replace(
const char *istr,
const char *scan_str,
const char *replace_str,
char *ostr)
INPUT
- istr - The string to be changed.
- scan_str - The search string to be replaced.
- replace_str - The string that replaces the search string.
OUTPUT
- ostr - The string that holds the converted output
string. If it is NULL, this routine will
allocate the space necessary.
RETURN VALUE
The converted string, 'ostr', if the variable is not NULL,
or a pointer to the resulting allocated string.
NULL is returned if 'istr' or 'scan_str' are NULL, or if
an error occurs.
DESCRIPTION
This function performs a global change of text on
the input string. It returns a string where every
occurrence of the scan string is replaced with the
replacement string. If 'ostr' is sent in as NULL,
the result will be allocated for you. If 'ostr'
is provided as non-NULL, the result will be stored in it.
Note that if the latter use is chosen, ostr must
be previously allocated with a sufficient amount of storage
space before this routine is called.
Note that if 'ostr' is non-NULL, the calling routine
must ensure that 'ostr' points to a memory buffer
large enough to hold the copied string and terminating
null character. If the buffer is not large enough,
memory will be overwritten resulting in unpredicable
program failure.
ADDITIONAL INFORMATION
none
EXAMPLES
For example, if we call:
new_string = kstring_replace("Welcome to Khoros", "Khoros",
"the Twilight Zone", NULL);
the result will be:
new_string = "Welcome to the Twilight Zone".
SIDE EFFECTS
This routine allocates the space for the output if 'ostr'
is NULL.
RESTRICTIONS
none
MODIFICATION
none
FILES
$BOOTSTRAP/objects/library/kutils/src/strings.c
SEE ALSO
kutils(3)
COPYRIGHT
Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.