📄 triostr.c.svn-base
字号:
{ 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 /* !defined(TRIO_MINIMAL) *//** 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_PUBLIC 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;}#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.*/TRIO_STRING_PUBLIC voidtrio_xstring_setTRIO_ARGS2((self, buffer), trio_string_t *self, char *buffer){ assert(self); trio_destroy(self->content); self->content = trio_duplicate(buffer);}#endif /* !defined(TRIO_MINIMAL) *//* * trio_string_size */TRIO_STRING_PUBLIC inttrio_string_sizeTRIO_ARGS1((self), trio_string_t *self){ assert(self); return self->allocated;}/* * trio_string_terminate */TRIO_STRING_PUBLIC voidtrio_string_terminateTRIO_ARGS1((self), trio_string_t *self){ trio_xstring_append_char(self, 0);}#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_PUBLIC 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 (!TrioStringGrowTo(self, length)) goto error; trio_copy(&self->content[self->length], other->content); self->length = length; return TRUE; error: return FALSE;}#endif /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_append */TRIO_STRING_PUBLIC 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 (!TrioStringGrowTo(self, length)) goto error; trio_copy(&self->content[self->length], other); self->length = length; return TRUE; error: return FALSE;}#endif /* !defined(TRIO_MINIMAL) *//* * trio_xstring_append_char */TRIO_STRING_PUBLIC inttrio_xstring_append_charTRIO_ARGS2((self, character), trio_string_t *self, char character){ assert(self); if ((int)self->length >= trio_string_size(self)) { if (!TrioStringGrow(self, 0)) goto error; } 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_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_contains */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_copy */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_copy */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_duplicate */TRIO_STRING_PUBLIC trio_string_t *trio_string_duplicateTRIO_ARGS1((other), trio_string_t *other){ trio_string_t *self; assert(other); self = TrioStringAlloc(); if (self) { self->content = TrioDuplicateMax(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 /* !defined(TRIO_MINIMAL) *//* * trio_xstring_duplicate */TRIO_STRING_PUBLIC trio_string_t *trio_xstring_duplicateTRIO_ARGS1((other), TRIO_CONST char *other){ trio_string_t *self; assert(other); self = TrioStringAlloc(); if (self) { self->content = TrioDuplicateMax(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;}#if !defined(TRIO_MINIMAL)/* * trio_string_equal */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_equal */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_equal_max */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_equal_max */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_equal_case */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_equal_case */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_equal_case_max */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_equal_case_max */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_format_data_max */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_index */TRIO_STRING_PUBLIC char *trio_string_indexTRIO_ARGS2((self, character), trio_string_t *self, int character){ assert(self); return trio_index(self->content, character);}#endif /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_index_last */TRIO_STRING_PUBLIC char *trio_string_index_lastTRIO_ARGS2((self, character), trio_string_t *self, int character){ assert(self); return trio_index_last(self->content, character);}#endif /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_length */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_lower */TRIO_STRING_PUBLIC inttrio_string_lowerTRIO_ARGS1((self), trio_string_t *self){ assert(self); return trio_lower(self->content);}#endif /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_match */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_match */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_match_case */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_match_case */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_substring */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_xstring_substring */TRIO_STRING_PUBLIC 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 /* !defined(TRIO_MINIMAL) */#if !defined(TRIO_MINIMAL)/* * trio_string_upper */TRIO_STRING_PUBLIC inttrio_string_upperTRIO_ARGS1((self), trio_string_t *self){ assert(self); return trio_upper(self->content);}#endif /* !defined(TRIO_MINIMAL) *//** @} End of DynamicStrings */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -