char *ft_strtrim(char const *s) { int d; int trim_start; unsigned int c; char *new_str; d = 0; c = 0; trim_start = 0; new_str = ft_strnew (ft_strlen (s)); while (c < ft_strlen (s)) { if (!trim_start && ft_isblank (s[c])) c++; else { trim_start = 1; new_str[d++] = s[c++]; } } while (ft_isblank (new_str[--d])) new_str[d] = '\0'; return (new_str); }
static int count_words(char *s) { int words; while (*s && ft_isblank(*s) == 1) ++s; words = (*s) ? 1 : 0; while (*s) { if (ft_isblank(*s) == 1 && s[1] && ft_isblank(s[1]) == 0) ++words; ++s; } return (words); }
char *ft_strtrim(char const *s) { int begbl; int endbl; char *trim; size_t i; i = 0; while (ft_isblank(s[i]) == 1) { i++; if (i == ft_strlen(s)) return (""); } begbl = ft_beginblank((char *)s); endbl = ft_endblank((char *)s); trim = (char *)malloc((ft_strlen(s) + 1) - (begbl + endbl) * sizeof(*trim)); if (trim == NULL) return (NULL); i = 0; while (i < ft_strlen(s) - (begbl + endbl)) { trim[i] = s[i + begbl]; i++; } trim[i] = '\0'; return (trim); }
int ft_atoi(const char *str) { int res; int i; int c; res = 0; i = 0; c = 0; while (ft_isblank(str[i])) i++; if (str[i] == '+') i++; else if (str[i] == '-') { c = 1; i++; } while (str[i] != '\0' && ft_isdigit(str[i])) { res = res * 10 + str[i] - '0'; i++; } if (c == 1) return (-res); return (res); }
int ft_atoi(const char *c) { int result; int i; i = 0; result = 0; while (ft_isblank(*c)) c++; if (ft_isdigit(c[0]) == 0 && c[0] != '-' && c[0] != '+') return (0); if ((c[0] == '-' || c[0] == '+') && ft_isdigit(c[1]) == 0) return (0); if (c[0] == '-' || c[0] == '+') i = 1; while (c[i] != '\0' && ft_isdigit(c[i]) == 1) { if (ft_isdigit(c[i]) == 1) result = result * 10 + c[i] - '0'; i++; } if (c[0] == '-' && ft_isdigit(c[1]) == 1) result = result * -1; return (result); }
static void test_3(void) { printf("\ttest 3: ft_isblank(128): "); if (ft_isblank(128) == isblank(128)) puts(SUCCESS); else puts(ERROR); }
static void test_1(void) { printf("\ttest 1: ft_isblank(-1): "); if (ft_isblank(-1) == isblank(-1)) puts(SUCCESS); else puts(ERROR); }
int is_only_spaces(char *buf) { size_t i; size_t len; i = 0; len = ft_strlen(buf); if (len == 1 && !ft_isblank(buf[i])) return (1); while (i < len - 1) { if (ft_isblank(buf[i])) i++; else return (0); } return (1); }
static int is_digit(char const *str) { while (ft_isblank(*str)) str++; if (*str == '+' || *str == '-') str++; while (ft_isdigit(*str)) str++; return (*str == '\0'); }
char *ft_strtrim(char const *s) { int i; int j; char *strim; i = 0; if (!s) return (NULL); j = ft_strlen(s) - 1; while (ft_isblank(s[i]) && s[i] != '\0') i++; while (j > -1 && ft_isblank(s[j])) j--; if (j < 0) return (ft_strdup("")); strim = ft_strsub(s, i, (j + 1 - i)); return (strim); }
char *ft_strtrim(char const *s) { const char *start; const char *end; char *str; size_t len; start = s; end = s + ft_strlen(s) - 1; while (*start && ft_isblank(*start)) start++; if (!*start) return (ft_strnew(0)); while (ft_isblank(*end) && end > s) end--; len = end - start + 1; str = ft_strnew(len); str = ft_strncpy(str, start, len); return (str); }
static int empty_buffer(\ char *buffer) { while (*buffer) { if (!ft_isblank(*buffer)) return (0); buffer++; } return (1); }
char *ft_strtrim(char const *s) { size_t a; size_t b; char *s2; a = 0; b = 0; if (!s) return (NULL); s2 = (char *)ft_memalloc(sizeof(char) * strlen(s) + 1); if (s2 == NULL) return (NULL); while (ft_isblank(s[a]) == 1) a++; while (s[a]) s2[b++] = s[a++]; while (ft_isblank(s2[--b]) == 1) s2[b] = '\0'; return (s2); }
static int ft_beginblank(char *str) { int begblank; begblank = 0; while (ft_isblank(*str) == 1) { begblank++; str++; } str = str - begblank; return (begblank); }
t_bool ft_vcmd(char *cmd) { int i; i = -1; while (cmd[++i]) { if (!ft_isprint(cmd[i]) && !ft_isblank(cmd[i])) { ft_sherror("Invalid command", NULL, FALSE); return (FAILURE); } } return (SUCCESS); }
static void fill_av(t_av *av, char *str) { int j; int k; j = 0; ft_bzero(av,sizeof(t_av)); while (ft_isblank(str[j]) == 1 && str[j] != '\0') j++; k = j; while (ft_isspace(str[k]) == 0 && str[k] != '\0') k++; av->cmd = ft_strsub(str, j, k - j); av->arg = ft_strsplit_blank(str + k); k = -1; while (av->arg != NULL && av->arg[++k] != NULL) av->argc++; }
static void test_2(void) { int i; printf("\ttest 2: ft_isblank([0-127]): "); i = 0; while (i < 128) { if (ft_isblank(i) != isblank(i)) { puts(ERROR); break ; } i++; } if (i == 128) puts(SUCCESS); }
long ft_atol(const char *nptr) { long i; int neg; i = 0; neg = 1; while (ft_isblank(*nptr)) nptr++; if (*nptr == '-' || *nptr == '+') neg = *nptr++ == '-' ? -1 : 1; while (ft_isdigit(*nptr)) { i *= 10; i += *nptr++ - '0'; } return (i * neg); }
static int ft_endblank(char *str) { int endblank; endblank = 0; while (*str != '\0') { str++; } str--; while (ft_isblank(*str) == 1) { endblank++; str--; } str = str + endblank - ft_strlen(str); return (endblank); }
int ft_isspace(int c) { return (ft_isblank(c) || c == '\r' || c == '\v' || c == '\f'); }
static int ft_isblank_nl(int c) { return (ft_isblank(c) || (c == '\n')); }
int ft_iswhitespace(int c) { if (c == '\n' || ft_isblank(c)) return (1); return (0); }
int ft_isblank2(int c) { if (ft_isblank(c) || c == '\n') return (1); return (0); }
static t_bool ft_iswhite(char c) { return ((ft_isblank(c) || c == '\n') ? TRUE : FALSE); }