bool f_string_add_ptr(t_string *v_this, void *addr) { size_t nbr; size_t digit; ui size; size = 1; digit = 1; nbr = (size_t)addr; while ((nbr / digit) >= 16) { digit = digit * 16; size = size + 1; } size = size + 1; if (v_this->v_size + size + 2 > v_this->v_capacity && uf_string_realloc(v_this, size) == false) return (false); D_STRING(add_str)(v_this, "0x"); while (digit > 0) { v_this->v_str[v_this->v_size] = v_this->v_hex[nbr / digit % 16]; v_this->v_size = v_this->v_size + 1; digit = digit / 16; } v_this->v_str[v_this->v_size] = '\0'; return (true); }
bool f_string_add_nbr_base(t_string *v_this, ssize_t nbr, ui base) { ui size; ui digit; digit = uf_string_get_digit(nbr, base, &size); if (base == 16 && D_STRING(add_str)(v_this, "0x") == false) return (false); if (v_this->v_size + size > v_this->v_capacity && uf_string_realloc(v_this, size) == false) return (false); if (nbr < 0) { v_this->v_str[v_this->v_size] = '-'; v_this->v_size = v_this->v_size + 1; nbr = -nbr; } while (digit > 0) { v_this->v_str[v_this->v_size] = v_this->v_hex[nbr / digit % base]; v_this->v_size = v_this->v_size + 1; digit = digit / base; } v_this->v_str[v_this->v_size] = '\0'; return (true); }
bool f_string_add_char(t_string *v_this, unsigned char c) { if (v_this->v_size + 2 > v_this->v_capacity && uf_string_realloc(v_this, 2) == false) return (false); v_this->v_str[v_this->v_size] = (char)c; v_this->v_size = v_this->v_size + 1; v_this->v_str[v_this->v_size] = '\0'; return (true); }
bool f_string_add_nstr(t_string *v_this, const char *str, size_t size) { if (size == 0) return (true); if (v_this->v_size + size + 1 > v_this->v_capacity && uf_string_realloc(v_this, size + 1) == false) return (false); uf_strncat(v_this->v_str + v_this->v_size, str, size); v_this->v_size = v_this->v_size + size; return (true); }
bool f_string_add_str(t_string *v_this, const char *str) { size_t size; size = uf_str_len(str); if (size == 0) return (true); size = size + 1; if (v_this->v_size + size > v_this->v_capacity && uf_string_realloc(v_this, size) == false) return (false); uf_strcat(v_this->v_str + v_this->v_size, str); v_this->v_size = v_this->v_size + size - 1; return (true); }
bool f_string_insert(t_string *v_this, const char *insert, ui at) { ui size; if (at >= v_this->v_size) return (D_STRING(add_str)(v_this, insert)); size = uf_str_len(insert); if (size == 0) return (true); if (v_this->v_size + size + 1 > v_this->v_capacity && uf_string_realloc(v_this, size + 1) == false) return (false); uf_memcpy(v_this->v_str + at + size, v_this->v_str + at, v_this->v_size - at); uf_memcpy(v_this->v_str + at, insert, size); v_this->v_size = v_this->v_size + size; return (true); }