Exemple #1
0
int		my_getnbr_base(char *nbr, char *base)
{
  int		i;
  int		cmp;
  int		nb;
  int		num;

  i = 0;
  cmp = 0;
  nb = 0;
  if (nbr == NULL || base == NULL || my_strlen(nbr) < 0
      || my_check_base(base) < 2 || my_check_conv(nbr, base) < 0)
    return (0);
  while (nbr[i] != 0 && (nbr[i] == '-' || nbr[i] == '+'))
    if (nbr[i++] == '-')
      cmp = (cmp + 1) % 2;
  while (nbr[i] != 0 && (num = my_find_rank(nbr[i], base)) != -1)
    {
      if (cmp == 0 && (INT_OVER_P - (nb * 10) - num) >= 0)
	nb = nb * 10 + num;
      else if (cmp == 1 && (INT_OVER_N - (nb * 10) + num) <= 0)
	nb = nb * 10 - num;
      else
	return (0);
      ++i;
    }
  return (nb);
}
long	my_getnbr_base_x(char *str, char *base)
{
  long	res;
  int	sign;
  int	j;
  int	base_len;
  int	nbr_pos;

  j = 0;
  base_len = my_strlen_x(base);
  res = 0;
  nbr_pos = 0;
  sign = my_get_sign(str, &nbr_pos);
  if (!my_check_base(base) || !my_strlen_x(str))
    return (0);
  while (str[nbr_pos])
    {
      while (j <= base_len && str[nbr_pos] != base[j])
	j = j + 1;
      if (str[nbr_pos] == base[j] && checkint_limit(res))
	res = res * base_len + j;
      else
	return (0);
      j = 0;
      nbr_pos = nbr_pos + 1;
    }
  return (res > 0) ? (res * sign) : (0);
}
Exemple #3
0
int		my_find_rank(char c, char *base)
{
  int		i;

  i = 0;
  if (c <= CHAR_MIN || c >= CHAR_MAX_EXT
      || base == NULL || my_check_base(base) < 2)
    return (-1);
  while (base[i] != 0 && base[i] != c)
    ++i;
  if (base[i] == 0)
    return (-1);
  return (i);
}
Exemple #4
0
int		my_check_conv(char *str, char *base)
{
  int		i;
  int		j;

  i = 0;
  if (str == NULL || base == NULL
      || my_strlen(str) < 0 || my_check_base(base) < 2)
    return (-1);
  while (str[i] != 0)
    {
      while (base[j] != 0 && base[j] != str[i])
	++j;
      if (base[j] == 0)
	return (-1);
      j = 0;
      ++i;
    }
  return (1);
}