#if !defined(TRIO_MINIMAL)
/**
Append @p source at the end of @p target.
-
+
@param target Target string.
@param source Source string.
@return Boolean value indicating success or failure.
-
+
@pre @p target must point to a memory chunk with sufficient room to
contain the @p target string and @p source string.
@pre No boundary checking is performed, so insufficient memory will
{
assert(target);
assert(source);
-
+
return (strcat(target, source) != NULL);
}
#endif /* !defined(TRIO_MINIMAL) */
#if !defined(TRIO_MINIMAL)
/**
Append at most @p max characters from @p source to @p target.
-
+
@param target Target string.
@param max Maximum number of characters to append.
@param source Source string.
@return Boolean value indicating success or failure.
-
+
@pre @p target must point to a memory chuck with sufficient room to
contain the @p target string and the @p source string (at most @p max
characters).
TRIO_CONST char *source)
{
size_t length;
-
+
assert(target);
assert(source);
length = trio_length(target);
-
+
if (max > length)
{
strncat(target, source, max - length - 1);
{
assert(string);
assert(substring);
-
+
return (0 != strstr(string, substring));
}
#endif /* !defined(TRIO_MINIMAL) */
#if !defined(TRIO_MINIMAL)
/**
Copy @p source to @p target.
-
+
@param target Target string.
@param source Source string.
@return Boolean value indicating success or failure.
-
+
@pre @p target must point to a memory chunk with sufficient room to
contain the @p source string.
@pre No boundary checking is performed, so insufficient memory will
{
assert(target);
assert(source);
-
+
(void)strcpy(target, source);
return TRUE;
}
/**
Copy at most @p max characters from @p source to @p target.
-
+
@param target Target string.
@param max Maximum number of characters to append.
@param source Source string.
@return Boolean value indicating success or failure.
-
+
@pre @p target must point to a memory chunk with sufficient room to
contain the @p source string (at most @p max characters).
@pre No boundary checking is performed, so insufficient memory will
/**
Duplicate @p source.
-
+
@param source Source string.
@return A copy of the @p source string.
-
+
@post @p target will be zero terminated.
*/
TRIO_STRING_PUBLIC char *
#if !defined(TRIO_MINIMAL)
/**
Duplicate at most @p max characters of @p source.
-
+
@param source Source string.
@param max Maximum number of characters to duplicate.
@return A copy of the @p source string.
-
+
@post @p target will be zero terminated.
*/
TRIO_STRING_PUBLIC char *
/**
Compare if two strings are equal.
-
+
@param first First string.
@param second Second string.
@return Boolean indicating whether the two strings are equal or not.
-
+
Case-insensitive comparison.
*/
TRIO_STRING_PUBLIC int
/**
Compare if two strings are equal.
-
+
@param first First string.
@param second Second string.
@return Boolean indicating whether the two strings are equal or not.
-
+
Case-sensitive comparison.
*/
TRIO_STRING_PUBLIC int
#if !defined(TRIO_MINIMAL)
/**
Compare if two strings up until the first @p max characters are equal.
-
+
@param first First string.
@param max Maximum number of characters to compare.
@param second Second string.
@return Boolean indicating whether the two strings are equal or not.
-
+
Case-sensitive comparison.
*/
TRIO_STRING_PUBLIC int
/**
Compare if two strings are equal.
-
+
@param first First string.
@param second Second string.
@return Boolean indicating whether the two strings are equal or not.
/**
Compare if two strings up until the first @p max characters are equal.
-
+
@param first First string.
@param max Maximum number of characters to compare.
@param second Second string.
@return Boolean indicating whether the two strings are equal or not.
-
+
Case-insensitive comparison.
*/
TRIO_STRING_PUBLIC int
int error_number)
{
#if defined(USE_STRERROR)
-
+
return strerror(error_number);
#elif defined(USE_SYS_ERRLIST)
return ((error_number < 0) || (error_number >= sys_nerr))
? "unknown"
: sys_errlist[error_number];
-
+
#else
-
+
return "unknown";
-
+
#endif
}
assert(format);
assert(datetime);
assert(max > 0);
-
+
return strftime(target, max, format, datetime);
}
#endif /* !defined(TRIO_MINIMAL) */
char ch;
assert(string);
-
+
switch (type)
{
case TRIO_HASH_PLAIN:
@return Boolean value indicating success or failure.
Case-insensitive comparison.
-
+
The following wildcards can be used
@li @c * Match any number of characters.
@li @c ? Match a single character.
{
assert(string);
assert(pattern);
-
+
for (; ('*' != *pattern); ++pattern, ++string)
{
if (NIL == *string)
}
}
while (*string++);
-
+
return FALSE;
}
#endif /* !defined(TRIO_MINIMAL) */
@return Boolean value indicating success or failure.
Case-sensitive comparison.
-
+
The following wildcards can be used
@li @c * Match any number of characters.
@li @c ? Match a single character.
{
assert(string);
assert(pattern);
-
+
for (; ('*' != *pattern); ++pattern, ++string)
{
if (NIL == *string)
}
}
while (*string++);
-
+
return FALSE;
}
#endif /* !defined(TRIO_MINIMAL) */
assert(target);
assert(source);
assert(Function);
-
+
while (*source != NIL)
{
*target++ = Function(*source++);
assert(string);
assert(substring);
-
+
size = trio_length(substring);
if (size <= max)
{
TRIO_CONST char *delimiters)
{
assert(delimiters);
-
+
return strtok(string, delimiters);
}
#endif /* !defined(TRIO_MINIMAL) */
}
}
}
-
+
value = integer + fraction;
if (exponent != 0)
{
{
assert(string);
assert((base >= 2) && (base <= 36));
-
+
return strtol(string, endp, base);
}
int source)
{
#if defined(USE_TOLOWER)
-
+
return tolower(source);
-
+
#else
/* Does not handle locales or non-contiguous alphabetic characters */
return ((source >= (int)'A') && (source <= (int)'Z'))
? source - 'A' + 'a'
: source;
-
+
#endif
}
#endif /* !defined(TRIO_MINIMAL) */
{
assert(string);
assert((base >= 2) && (base <= 36));
-
+
return strtoul(string, endp, base);
}
#endif /* !defined(TRIO_MINIMAL) */
int source)
{
#if defined(USE_TOUPPER)
-
+
return toupper(source);
-
+
#else
/* Does not handle locales or non-contiguous alphabetic characters */
return ((source >= (int)'a') && (source <= (int)'z'))
? source - 'a' + 'A'
: source;
-
+
#endif
}
TrioStringAlloc(TRIO_NOARGS)
{
trio_string_t *self;
-
+
self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t));
if (self)
{
new_size = (delta == 0)
? ( (self->allocated == 0) ? 1 : self->allocated * 2 )
: self->allocated + delta;
-
+
new_content = (char *)TRIO_REALLOC(self->content, new_size);
if (new_content)
{
#if !defined(TRIO_MINIMAL)
/**
Create a new dynamic string.
-
+
@param initial_size Initial size of the buffer.
@return Newly allocated dynamic string, or NULL if memory allocation failed.
*/
/**
Deallocate the dynamic string and its contents.
-
+
@param self Dynamic string
*/
TRIO_STRING_PUBLIC void
trio_string_t *self)
{
assert(self);
-
+
if (self)
{
trio_destroy(self->content);
#if !defined(TRIO_MINIMAL)
/**
Get a pointer to the content.
-
+
@param self Dynamic string.
@param offset Offset into content.
@return Pointer to the content.
-
+
@p Offset can be zero, positive, or negative. If @p offset is zero,
then the start of the content will be returned. If @p offset is positive,
then a pointer to @p offset number of characters from the beginning of the
int offset)
{
char *result = NULL;
-
+
assert(self);
if (self->content != NULL)
/**
Extract the content.
-
+
@param self Dynamic String
@return Content of dynamic string.
-
+
The content is removed from the dynamic string. This enables destruction
of the dynamic string without deallocation of the content.
*/
trio_string_t *self)
{
char *result;
-
+
assert(self);
result = self->content;
#if !defined(TRIO_MINIMAL)
/**
Set the content of the dynamic string.
-
+
@param self Dynamic String
@param buffer The new content.
-
+
Sets the content of the dynamic string to a copy @p buffer.
An existing content will be deallocated first, if necessary.
-
+
@remark
This function will make a copy of @p buffer.
You are responsible for deallocating @p buffer yourself.
#if !defined(TRIO_MINIMAL)
/**
Append the second string to the first.
-
+
@param self Dynamic string to be modified.
@param other Dynamic string to copy from.
@return Boolean value indicating success or failure.
trio_string_t *other)
{
size_t length;
-
+
assert(self);
assert(other);
trio_copy(&self->content[self->length], other->content);
self->length = length;
return TRUE;
-
+
error:
return FALSE;
}
TRIO_CONST char *other)
{
size_t length;
-
+
assert(self);
assert(other);
trio_copy(&self->content[self->length], other);
self->length = length;
return TRUE;
-
+
error:
return FALSE;
}
self->content[self->length] = character;
self->length++;
return TRUE;
-
+
error:
return FALSE;
}
#if !defined(TRIO_MINIMAL)
/**
Search for the first occurrence of second parameter in the first.
-
+
@param self Dynamic string to be modified.
@param other Dynamic string to copy from.
@return Boolean value indicating success or failure.
trio_string_t *other)
{
trio_string_t *self;
-
+
assert(other);
self = TrioStringAlloc();
TRIO_CONST char *other)
{
trio_string_t *self;
-
+
assert(other);
self = TrioStringAlloc();