Beispiel #1
0
int		get_nb_pieces(char *text)
{
	int i;
	int nb_n;
	int	nb_pieces;

	if (!text || ft_strlen(text) < 5 * 4)
		return (-1);
	if (!has_valid_structure(text, 0, 0, 0) || !has_valid_chars(text))
		return (-1);
	nb_pieces = 0;
	i = 0;
	nb_n = 0;
	while (text[i] != '\0')
	{
		if (text[i] == '\n')
		{
			nb_n++;
			if (nb_n % 5 == 0)
				nb_pieces++;
		}
		i++;
	}
	nb_n++;
	nb_pieces++;
	return ((double)nb_pieces == (double)nb_n / 5) ? nb_pieces : -1;
}
Beispiel #2
0
static int
parse_int (const char *s) {
  int valid, num;
  valid = has_valid_chars(s, NUMBERS);
  if (valid == 0) return -1;

  num = strtol(s, NULL, 10);
  if (num > MAX_SAFE_INT) return -1;

  return num;
}
Beispiel #3
0
int
semver_is_valid (const char *s) {
  return has_valid_length(s)
      && has_valid_chars(s, VALID_CHARS);
}