Ejemplo n.º 1
0
fractionUnit parse_period_unit (const char **c) {
  // units: invalid=-1, S=0,  M=1, H=2, d=3, w=4, m=5, y=6
  // SKIP_NON_ALPHANUMS(*c);   //  why this macro doesn't work here?
  while(**c && !(ALPHA(**c) || DIGIT(**c) || **c == '.')) (*c)++;;

  fractionUnit out;
  out.unit = -1;
  out.val = parse_int(c, 100, FALSE);
  if (**c == '.') {
    (*c)++;
    // allow fractions without leading 0
    if (out.val == -1)
      out.val = 0;
    out.fraction = parse_fractional(c);
  } else {
    out.fraction = 0.0;
  }

  if(**c){
    out.unit = parse_alphanum(c, en_units, N_EN_UNITS, 0);
    if (out.unit < 0){
      return out;
    } else {
      // if only unit name supplied, default to 1 units
      if(out.val == -1)
        out.val = 1;
      if (out.unit < 3) out.unit = 0;
      else if (out.unit < 6) out.unit = 1;
      else if (out.unit < 8) out.unit = 2;
      else out.unit = out.unit - 5;
      return out;
    }
  } else {
    return out;
  }
}
Ejemplo n.º 2
0
// increment **c and return month ix in 1..12 if parsing was successful, 0 if not.
int parse_alpha_month(const char **c){
  return (parse_alphanum(c, en_months, 12) + 1);
}