Logo Search packages:      
Sourcecode: libical version File versions  Download package

struct icalrecurrencetype icalrecurrencetype_from_string ( const char *  str  )  [read]

Recurrance rule parser Convert between strings and recurrencetype structures.

Convert between strings and recurrencetype structures.

Definition at line 398 of file icalrecur.c.

References ICAL_BY_SECOND_SIZE, and icalmemory_strdup().

Referenced by icalrecur_expand_recurrence().

{
    struct icalrecur_parser parser;

    memset(&parser,0,sizeof(parser));
    icalrecurrencetype_clear(&parser.rt);

    icalerror_check_arg_re(str!=0,"str",parser.rt);


    /* Set up the parser struct */
    parser.rule = str;
    parser.copy = icalmemory_strdup(parser.rule);
    parser.this_clause = parser.copy;

    if(parser.copy == 0){
      icalerror_set_errno(ICAL_NEWFAILED_ERROR);
      return parser.rt;
    }

    /* Loop through all of the clauses */
    for(icalrecur_first_clause(&parser); 
      parser.this_clause != 0;
      icalrecur_next_clause(&parser))
    {
      char *name, *value;
      icalrecur_clause_name_and_value(&parser,&name,&value);

      if(name == 0){
          icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
          icalrecurrencetype_clear(&parser.rt);
            free(parser.copy);
          return parser.rt;
      }

      if (strcasecmp(name,"FREQ") == 0){
          parser.rt.freq = icalrecur_string_to_freq(value);
      } else if (strcasecmp(name,"COUNT") == 0){
          parser.rt.count = atoi(value);
      } else if (strcasecmp(name,"UNTIL") == 0){
          parser.rt.until = icaltime_from_string(value);
      } else if (strcasecmp(name,"INTERVAL") == 0){
          parser.rt.interval = (short)atoi(value);
      } else if (strcasecmp(name,"WKST") == 0){
          parser.rt.week_start = icalrecur_string_to_weekday(value);
          sort_bydayrules(&parser);
      } else if (strcasecmp(name,"BYSECOND") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_second,
                          ICAL_BY_SECOND_SIZE,value);
      } else if (strcasecmp(name,"BYMINUTE") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_minute,
                          ICAL_BY_MINUTE_SIZE,value);
      } else if (strcasecmp(name,"BYHOUR") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_hour,
                          ICAL_BY_HOUR_SIZE,value);
      } else if (strcasecmp(name,"BYDAY") == 0){
          icalrecur_add_bydayrules(&parser,value);
      } else if (strcasecmp(name,"BYMONTHDAY") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_month_day,
                          ICAL_BY_MONTHDAY_SIZE,value);
      } else if (strcasecmp(name,"BYYEARDAY") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_year_day,
                          ICAL_BY_YEARDAY_SIZE,value);
      } else if (strcasecmp(name,"BYWEEKNO") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_week_no,
                          ICAL_BY_WEEKNO_SIZE,value);
      } else if (strcasecmp(name,"BYMONTH") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_month,
                          ICAL_BY_MONTH_SIZE,value);
      } else if (strcasecmp(name,"BYSETPOS") == 0){
          icalrecur_add_byrules(&parser,parser.rt.by_set_pos,
                          ICAL_BY_SETPOS_SIZE,value);
      } else {
          icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
          icalrecurrencetype_clear(&parser.rt);
            free(parser.copy);
          return parser.rt;
      }
      
    }

    free(parser.copy);

    return parser.rt;

}


Generated by  Doxygen 1.6.0   Back to index