1#include "include/pw.h"
2#include "src/types/string/string_internal.h"
3
4[[nodiscard]] bool pw_string_truncate(PwValuePtr str, unsigned position)
5{
6 if (position >= pw_strlen(str)) {
7 return true;
8 }
9 if (!_pw_string_copy_on_write(str)) {
10 return false;
11 }
12 _pw_string_set_length(str, position);
13
14 if (str->embedded) {
15 // clean remainder for fast comparison to work
16 unsigned i = str->char_size * position;
17 while (i < sizeof(str->str_1)) {
18 str->str_1[i++] = 0;
19 }
20 }
21 return true;
22}