static bool *uf_string_fill_bool(t_string *v_this, const char *charset) { size_t i; size_t size; bool *active; i = 0; if ((active = uf_malloc_s(v_this->v_size, sizeof(*active))) == NULL) return ((bool *)M_ERROR((size_t)NULL, "Bad alloc")); uf_memset(active, false, v_this->v_size * sizeof(*active)); size = uf_str_len(charset); if (size == 0) i = v_this->v_size; while (i < v_this->v_size) { if (uf_strncmp(v_this->v_str + i, charset, size) == 0) { uf_memset(active + i, true, size * sizeof(*active)); i = i + size; } else i = i + 1; } return (active); }
static bool uf_getopt_init_option(t_getopt *v_this, size_t ac, const char **av) { size_t i; size_t size; t_string string; i = 1; if (D_STRING(init)(&string, 0) == false) return (M_ERROR(false, "Could not initialize string")); while (i < ac) { size = uf_str_len(av[i]); if (uf_fmt_av(v_this, &string, size == 2 && av[i][0] == '-' && av[i][1] != '-', av[i] + 1) == false || uf_fmt_av(v_this, &string, size > 3 && av[i][0] == '-' && av[i][1] == '-' && av[i][2] != '-', av[i] + 2) == false) break ; i = i + 1; } if (i == ac) { v_this->v_option = D_STRING(split)(&string, " "); if (v_this->v_option == NULL) i = 0; } D_STRING(destroy)(&string); return (i == ac); }
size_t uf_strlcat(char *dest, const char *src, size_t size) { char *p_dest; const char *p_src; size_t tmp; size_t dlen; tmp = size; p_src = src; p_dest = dest; p_dest = uf_goto_end(p_dest, tmp); dlen = (size_t)(p_dest - dest); tmp = size - dlen; if (tmp == 0) return (dlen + uf_str_len(p_src)); while (*p_src != '\0') { if (tmp != 1) { *p_dest = *p_src; p_dest = p_dest + 1; tmp = tmp - 1; } p_src = p_src + 1; } *p_dest = '\0'; return (dlen + (size_t)(p_src - src)); }
void D_UNIT_FUNCT(ret_val) { F_UNIT_ASSERT(uf_is_upper('A') == true); F_UNIT_ASSERT(uf_is_upper('a') == false); F_UNIT_ASSERT(uf_is_lower('A') == false); F_UNIT_ASSERT(uf_is_lower('a') == true); F_UNIT_ASSERT(uf_is_alpha('a') == true); F_UNIT_ASSERT(uf_is_alpha('9') == false); F_UNIT_ASSERT(uf_is_printable(0) == false); F_UNIT_ASSERT(uf_is_printable('a') == true); F_UNIT_ASSERT(uf_is_digit('a') == false); F_UNIT_ASSERT(uf_is_digit('9') == true); F_UNIT_ASSERT(uf_is_space(' ') == true); F_UNIT_ASSERT(uf_is_space('9') == false); F_UNIT_ASSERT(uf_str_len("") == 0); F_UNIT_ASSERT(uf_str_len("foo") == 3); F_UNIT_ASSERT(uf_strcmp("foo", "foo") == 0); F_UNIT_ASSERT(uf_strcmp("foo", "fDo") != 0); F_UNIT_ASSERT(uf_strncmp("foo", "foo", 2) == 0); F_UNIT_ASSERT(uf_strncmp("foo", "fDo", 2) != 0); }
char *uf_strdup(const char *str) { size_t size; char *ret; size = uf_str_len(str); if (size == 0) return (NULL); ret = malloc(sizeof(*ret) * (size + 1)); if (ret != NULL) uf_strcpy(ret, str); return (ret); }
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); }
void uf_crypto_xor(void *data, const unsigned char *key, size_t data_size) { size_t i; size_t len; i = 0; len = uf_str_len((const char *)key); if (len == 0) return ; while (i < data_size) { if (((unsigned char *)data)[i] != 0 && ((unsigned char *)data)[i] != key[i % len]) ((unsigned char *)data)[i] = ((unsigned char *)data)[i] ^ key[i % len]; i = i + 1; } }
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); }
bool f_getopt_option(t_getopt *v_this) { size_t size; char *av; while (v_this->v_current_argc < v_this->v_argc) { av = v_this->v_argv[v_this->v_current_argc]; size = uf_str_len(av); if (size == 2 && av[0] == '-' && av[1] != '-' && uf_getopt_check_option(v_this, av + 1) == true) return (true); if (size > 3 && av[0] == '-' && av[1] == '-' && av[2] != '-' && uf_getopt_check_option(v_this, av + 2) == true) return (true); v_this->v_current_argc = v_this->v_current_argc + 1; } return (false); }