Beispiel #1
0
int msParseTime(const char *string, struct tm *tm)
{
  int i, indice = 0;
  int num_patterns = 0;
  
  if(msTimeSetup() != MS_SUCCESS) {
    return MS_FALSE;
  }

  /* if limited patterns are set, use then. Else use all the */
  /* patterns defined */
  if (ms_num_limited_pattern > 0)
    num_patterns = ms_num_limited_pattern;
  else
    num_patterns = MS_NUMTIMEFORMATS;

  for(i=0; i<num_patterns; i++) {
    int match;
    if (ms_num_limited_pattern > 0)
      indice = ms_limited_pattern[i];
    else
      indice = i;

    match = ms_regexec(ms_timeFormats[indice].regex, string, 0,NULL, 0);
    /* test the expression against the string */
    if(match == 0) {
      /* match    */
      msStrptime(string, ms_timeFormats[indice].format, tm);
      return(MS_TRUE);
    }
  }

  msSetError(MS_REGEXERR, "Unrecognized date or time format (%s).", "msParseTime()", string);
  return(MS_FALSE);
}
Beispiel #2
0
int msParseTime(const char *string, struct tm *tm) {
  int i, indice = 0;
  int num_patterns = 0;
  
  /* if limited patterns are set, use then. Else use all the */
  /* patterns defined */
  if (ms_limited_pattern &&  ms_num_limited_pattern > 0)
    num_patterns = ms_num_limited_pattern;
  else
    num_patterns = MS_NUMTIMEFORMATS;

  for(i=0; i<num_patterns; i++) {
      if (ms_num_limited_pattern > 0)
        indice = ms_limited_pattern[i];
      else
        indice = i;

      if(!ms_timeFormats[indice].regex) { /* compile the expression */
      ms_timeFormats[indice].regex = (ms_regex_t *) msSmallMalloc(sizeof(ms_regex_t)); 
      if(ms_regcomp(ms_timeFormats[indice].regex, ms_timeFormats[indice].pattern, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) {
	msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msParseTime()", ms_timeFormats[indice].pattern);
	return(MS_FALSE);
      }
    }  

    /* test the expression against the string */
    if(ms_regexec(ms_timeFormats[indice].regex, string, 0, NULL, 0) == 0) 
    { /* match    */
        msStrptime(string, ms_timeFormats[indice].format, tm);
        return(MS_TRUE);
    }
  }

  msSetError(MS_REGEXERR, "Unrecognized date or time format (%s).", "msParseTime()", string);
  return(MS_FALSE);
}