📄 triostr.c
字号:
}#endif/** 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 content is returned. If @p offset is negative, then a pointer to @p offset number of characters from the ending of the string, starting at the terminating zero, is returned.*/#if defined(TRIO_FUNCT_STRING_GET)TRIO_PUBLIC_STRING char *trio_string_getTRIO_ARGS2((self, offset), trio_string_t *self, int offset){ char *result = NULL; assert(self); if (self->content != NULL) { if (self->length == 0) { (void)trio_string_length(self); } if (offset >= 0) { if (offset > (int)self->length) { offset = self->length; } } else { offset += self->length + 1; if (offset < 0) { offset = 0; } } result = &(self->content[offset]); } return result;}#endif/** 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.*/#if defined(TRIO_FUNC_STRING_EXTRACT)TRIO_PUBLIC_STRING char *trio_string_extractTRIO_ARGS1((self), trio_string_t *self){ char *result; assert(self); result = self->content; /* FIXME: Allocate new empty buffer? */ self->content = NULL; self->length = self->allocated = 0; return result;}#endif/** 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_FUNC_XSTRING_SET)TRIO_PUBLIC_STRING voidtrio_xstring_setTRIO_ARGS2((self, buffer), trio_string_t *self, char *buffer){ assert(self); trio_destroy(self->content); self->content = trio_duplicate(buffer);}#endif/* * trio_string_size */#if defined(TRIO_FUNC_STRING_SIZE)TRIO_PUBLIC_STRING inttrio_string_sizeTRIO_ARGS1((self), trio_string_t *self){ assert(self); return self->allocated;}#endif/* * trio_string_terminate */#if defined(TRIO_FUNC_STRING_TERMINATE)TRIO_PUBLIC_STRING voidtrio_string_terminateTRIO_ARGS1((self), trio_string_t *self){ trio_xstring_append_char(self, 0);}#endif/** 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.*/#if defined(TRIO_FUNC_STRING_APPEND)TRIO_PUBLIC_STRING inttrio_string_appendTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ size_t length; assert(self); assert(other); length = self->length + other->length; if (!internal_string_grow_to(self, length)) goto error; trio_copy(&self->content[self->length], other->content); self->length = length; return TRUE; error: return FALSE;}#endif/* * trio_xstring_append */#if defined(TRIO_FUNC_XSTRING_APPEND)TRIO_PUBLIC_STRING inttrio_xstring_appendTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ size_t length; assert(self); assert(other); length = self->length + trio_length(other); if (!internal_string_grow_to(self, length)) goto error; trio_copy(&self->content[self->length], other); self->length = length; return TRUE; error: return FALSE;}#endif/* * trio_xstring_append_char */#if defined(TRIO_FUNC_XSTRING_APPEND_CHAR)TRIO_PUBLIC_STRING inttrio_xstring_append_charTRIO_ARGS2((self, character), trio_string_t *self, char character){ assert(self); if ((int)self->length >= trio_string_size(self)) { if (!internal_string_grow(self, 0)) goto error; } self->content[self->length] = character; self->length++; return TRUE; error: return FALSE;}#endif/** 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.*/#if defined(TRIO_FUNC_STRING_CONTAINS)TRIO_PUBLIC_STRING inttrio_string_containsTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_contains(self->content, other->content);}#endif/* * trio_xstring_contains */#if defined(TRIO_FUNC_XSTRING_CONTAINS)TRIO_PUBLIC_STRING inttrio_xstring_containsTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_contains(self->content, other);}#endif/* * trio_string_copy */#if defined(TRIO_FUNC_STRING_COPY)TRIO_PUBLIC_STRING inttrio_string_copyTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); self->length = 0; return trio_string_append(self, other);}#endif/* * trio_xstring_copy */#if defined(TRIO_FUNC_XSTRING_COPY)TRIO_PUBLIC_STRING inttrio_xstring_copyTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); self->length = 0; return trio_xstring_append(self, other);}#endif/* * trio_string_duplicate */#if defined(TRIO_FUNC_STRING_DUPLICATE)TRIO_PUBLIC_STRING trio_string_t *trio_string_duplicateTRIO_ARGS1((other), trio_string_t *other){ trio_string_t *self; assert(other); self = internal_string_alloc(); if (self) { self->content = internal_duplicate_max(other->content, other->length); if (self->content) { self->length = other->length; self->allocated = self->length + 1; } else { self->length = self->allocated = 0; } } return self;}#endif/* * trio_xstring_duplicate */#if defined(TRIO_FUNC_XSTRING_DUPLICATE)TRIO_PUBLIC_STRING trio_string_t *trio_xstring_duplicateTRIO_ARGS1((other), TRIO_CONST char *other){ trio_string_t *self; assert(other); self = internal_string_alloc(); if (self) { self->content = internal_duplicate_max(other, trio_length(other)); if (self->content) { self->length = trio_length(self->content); self->allocated = self->length + 1; } else { self->length = self->allocated = 0; } } return self;}#endif/* * trio_string_equal */#if defined(TRIO_FUNC_STRING_EQUAL)TRIO_PUBLIC_STRING inttrio_string_equalTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_equal(self->content, other->content);}#endif/* * trio_xstring_equal */#if defined(TRIO_FUNC_XSTRING_EQUAL)TRIO_PUBLIC_STRING inttrio_xstring_equalTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_equal(self->content, other);}#endif/* * trio_string_equal_max */#if defined(TRIO_FUNC_STRING_EQUAL_MAX)TRIO_PUBLIC_STRING inttrio_string_equal_maxTRIO_ARGS3((self, max, other), trio_string_t *self, size_t max, trio_string_t *other){ assert(self); assert(other); return trio_equal_max(self->content, max, other->content);}#endif/* * trio_xstring_equal_max */#if defined(TRIO_FUNC_XSTRING_EQUAL_MAX)TRIO_PUBLIC_STRING inttrio_xstring_equal_maxTRIO_ARGS3((self, max, other), trio_string_t *self, size_t max, TRIO_CONST char *other){ assert(self); assert(other); return trio_equal_max(self->content, max, other);}#endif/* * trio_string_equal_case */#if defined(TRIO_FUNC_STRING_EQUAL_CASE)TRIO_PUBLIC_STRING inttrio_string_equal_caseTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_equal_case(self->content, other->content);}#endif/* * trio_xstring_equal_case */#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE)TRIO_PUBLIC_STRING inttrio_xstring_equal_caseTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_equal_case(self->content, other);}#endif/* * trio_string_equal_case_max */#if defined(TRIO_FUNC_STRING_EQUAL_CASE_MAX)TRIO_PUBLIC_STRING inttrio_string_equal_case_maxTRIO_ARGS3((self, max, other), trio_string_t *self, size_t max, trio_string_t *other){ assert(self); assert(other); return trio_equal_case_max(self->content, max, other->content);}#endif/* * trio_xstring_equal_case_max */#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE_MAX)TRIO_PUBLIC_STRING inttrio_xstring_equal_case_maxTRIO_ARGS3((self, max, other), trio_string_t *self, size_t max, TRIO_CONST char *other){ assert(self); assert(other); return trio_equal_case_max(self->content, max, other);}#endif/* * trio_string_format_data_max */#if defined(TRIO_FUNC_STRING_FORMAT_DATE_MAX)TRIO_PUBLIC_STRING size_ttrio_string_format_date_maxTRIO_ARGS4((self, max, format, datetime), trio_string_t *self, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime){ assert(self); return trio_format_date_max(self->content, max, format, datetime);}#endif/* * trio_string_index */#if defined(TRIO_FUNC_STRING_INDEX)TRIO_PUBLIC_STRING char *trio_string_indexTRIO_ARGS2((self, character), trio_string_t *self, int character){ assert(self); return trio_index(self->content, character);}#endif/* * trio_string_index_last */#if defined(TRIO_FUNC_STRING_INDEX_LAST)TRIO_PUBLIC_STRING char *trio_string_index_lastTRIO_ARGS2((self, character), trio_string_t *self, int character){ assert(self); return trio_index_last(self->content, character);}#endif/* * trio_string_length */#if defined(TRIO_FUNC_STRING_LENGTH)TRIO_PUBLIC_STRING inttrio_string_lengthTRIO_ARGS1((self), trio_string_t *self){ assert(self); if (self->length == 0) { self->length = trio_length(self->content); } return self->length;}#endif/* * trio_string_lower */#if defined(TRIO_FUNC_STRING_LOWER)TRIO_PUBLIC_STRING inttrio_string_lowerTRIO_ARGS1((self), trio_string_t *self){ assert(self); return trio_lower(self->content);}#endif/* * trio_string_match */#if defined(TRIO_FUNC_STRING_MATCH)TRIO_PUBLIC_STRING inttrio_string_matchTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_match(self->content, other->content);}#endif/* * trio_xstring_match */#if defined(TRIO_FUNC_XSTRING_MATCH)TRIO_PUBLIC_STRING inttrio_xstring_matchTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_match(self->content, other);}#endif/* * trio_string_match_case */#if defined(TRIO_FUNC_STRING_MATCH_CASE)TRIO_PUBLIC_STRING inttrio_string_match_caseTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_match_case(self->content, other->content);}#endif/* * trio_xstring_match_case */#if defined(TRIO_FUNC_XSTRING_MATCH_CASE)TRIO_PUBLIC_STRING inttrio_xstring_match_caseTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_match_case(self->content, other);}#endif/* * trio_string_substring */#if defined(TRIO_FUNC_STRING_SUBSTRING)TRIO_PUBLIC_STRING char *trio_string_substringTRIO_ARGS2((self, other), trio_string_t *self, trio_string_t *other){ assert(self); assert(other); return trio_substring(self->content, other->content);}#endif/* * trio_xstring_substring */#if defined(TRIO_FUNC_XSTRING_SUBSTRING)TRIO_PUBLIC_STRING char *trio_xstring_substringTRIO_ARGS2((self, other), trio_string_t *self, TRIO_CONST char *other){ assert(self); assert(other); return trio_substring(self->content, other);}#endif/* * trio_string_upper */#if defined(TRIO_FUNC_STRING_UPPER)TRIO_PUBLIC_STRING inttrio_string_upperTRIO_ARGS1((self), trio_string_t *self){ assert(self); return trio_upper(self->content);}#endif/** @} End of DynamicStrings */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -