object: string: add front, back, and pop_back functions
This commit is contained in:
@@ -51,6 +51,11 @@ BLUE_API void b_string_clear(b_string *str);
|
||||
BLUE_API size_t b_string_get_size(const b_string *str, b_strlen_flags flags);
|
||||
BLUE_API size_t b_string_get_capacity(const b_string *str);
|
||||
|
||||
BLUE_API char b_string_front(const b_string *str);
|
||||
BLUE_API char b_string_back(const b_string *str);
|
||||
|
||||
BLUE_API void b_string_pop_back(b_string *str);
|
||||
|
||||
BLUE_API const char *b_string_ptr(const b_string *str);
|
||||
|
||||
BLUE_API char *b_strdup(const char *s);
|
||||
|
||||
@@ -26,6 +26,7 @@ typedef enum b_fundamental_type_id {
|
||||
B_OBJECT_TYPE_STRING,
|
||||
B_OBJECT_TYPE_TREE,
|
||||
B_OBJECT_TYPE_UUID,
|
||||
B_OBJECT_TYPE_PATH,
|
||||
B_OBJECT_TYPE_FILE,
|
||||
B_OBJECT_TYPE_DIRECTORY,
|
||||
} b_fundamental_type_id;
|
||||
|
||||
@@ -324,6 +324,38 @@ size_t b_string_get_capacity(const struct b_string *str)
|
||||
return str->s_max;
|
||||
}
|
||||
|
||||
char b_string_front(const struct b_string *str)
|
||||
{
|
||||
if (str->s_len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
return s[0];
|
||||
}
|
||||
|
||||
char b_string_back(const struct b_string *str)
|
||||
{
|
||||
if (str->s_len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
return s[str->s_len - 1];
|
||||
}
|
||||
|
||||
void b_string_pop_back(struct b_string *str)
|
||||
{
|
||||
if (str->s_len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *s = string_ptr(str);
|
||||
|
||||
s[str->s_len - 1] = '\0';
|
||||
str->s_len--;
|
||||
}
|
||||
|
||||
const char *b_string_ptr(const struct b_string *str)
|
||||
{
|
||||
if (string_is_inline(str)) {
|
||||
|
||||
Reference in New Issue
Block a user