|
@@ -45,7 +45,7 @@ void SCDString_free(SCDString *const dstr) {
|
|
|
dstr->capacity = 0;
|
|
dstr->capacity = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void SCDString_resize_to_fit(SCDString *const dstr) {
|
|
|
|
|
|
|
+void SCDString_shrink_to_fit(SCDString *const dstr) {
|
|
|
if (dstr->capacity > dstr->len + 1) {
|
|
if (dstr->capacity > dstr->len + 1) {
|
|
|
dstr->capacity = dstr->len + 1;
|
|
dstr->capacity = dstr->len + 1;
|
|
|
dstr->data = (char *) realloc(dstr->data, dstr->capacity);
|
|
dstr->data = (char *) realloc(dstr->data, dstr->capacity);
|
|
@@ -248,7 +248,7 @@ ScufContResult SCDString_char_mod(SCDString *const dstr, const size_t at, const
|
|
|
return SCUFCONT_SUCCESS;
|
|
return SCUFCONT_SUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-ScufContResult SCDString_char_remove_no_resize(SCDString *const dstr, const size_t at) {
|
|
|
|
|
|
|
+ScufContResult SCDString_char_remove_no_shrink(SCDString *const dstr, const size_t at) {
|
|
|
if (at > dstr->len - 1) {
|
|
if (at > dstr->len - 1) {
|
|
|
return SCUFCONT_OUT_OF_BOUNDS;
|
|
return SCUFCONT_OUT_OF_BOUNDS;
|
|
|
}
|
|
}
|
|
@@ -259,12 +259,12 @@ ScufContResult SCDString_char_remove_no_resize(SCDString *const dstr, const size
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ScufContResult SCDString_char_remove(SCDString *const dstr, const size_t at) {
|
|
ScufContResult SCDString_char_remove(SCDString *const dstr, const size_t at) {
|
|
|
- const ScufContResult res = SCDString_char_remove_no_resize(dstr, at);
|
|
|
|
|
|
|
+ const ScufContResult res = SCDString_char_remove_no_shrink(dstr, at);
|
|
|
if (res != SCUFCONT_SUCCESS) {
|
|
if (res != SCUFCONT_SUCCESS) {
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SCDString_resize_to_fit(dstr);
|
|
|
|
|
|
|
+ SCDString_shrink_to_fit(dstr);
|
|
|
|
|
|
|
|
return SCUFCONT_SUCCESS;
|
|
return SCUFCONT_SUCCESS;
|
|
|
}
|
|
}
|
|
@@ -287,3 +287,28 @@ ScufContResult SCDString_char_insert(SCDString *const dstr, const size_t at, con
|
|
|
|
|
|
|
|
return SCUFCONT_SUCCESS;
|
|
return SCUFCONT_SUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ScufContResult SCDString_replace_c_str_no_shrink(SCDString *const dstr, const char *str, const size_t str_len) {
|
|
|
|
|
+ if (dstr->capacity < str_len + 1) {
|
|
|
|
|
+ const ScufContResult res = SCDString_reserve(dstr, str_len + 1);
|
|
|
|
|
+ if (res != SCUFCONT_SUCCESS) {
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ memcpy(dstr->data, str, str_len);
|
|
|
|
|
+ dstr->len = str_len;
|
|
|
|
|
+
|
|
|
|
|
+ return SCUFCONT_SUCCESS;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+ScufContResult SCDString_replace_c_str(SCDString *const dstr, const char *str, const size_t str_len) {
|
|
|
|
|
+ const ScufContResult res = SCDString_replace_c_str_no_shrink(dstr, str, str_len);
|
|
|
|
|
+ if (res != SCUFCONT_SUCCESS) {
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SCDString_shrink_to_fit(dstr);
|
|
|
|
|
+
|
|
|
|
|
+ return SCUFCONT_SUCCESS;
|
|
|
|
|
+}
|