Exemplo n.º 1
0
/**
 * Parse the time string and return the reslution
 */
int msTimeGetResolution(const char *timestring)
{
  int i=0;

  if (!timestring)
    return -1;

  for(i=0; i<MS_NUMTIMEFORMATS; i++) {
    ms_regex_t *regex = (ms_regex_t *) msSmallMalloc(sizeof(ms_regex_t));
    if(ms_regcomp(regex, ms_timeFormats[i].pattern,
                  MS_REG_EXTENDED|MS_REG_NOSUB) != 0) {
      msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msParseTime()", ms_timeFormats[i].pattern);
      msFree(regex);
      return -1;
    }
    /* test the expression against the string */
    if(ms_regexec(regex, timestring, 0, NULL, 0) == 0) {
      /* match    */
      ms_regfree(regex);
      msFree(regex);
      return ms_timeFormats[i].resolution;
    }
    ms_regfree(regex);
    msFree(regex);
  }

  return -1;
}
Exemplo n.º 2
0
/**
   return MS_TRUE if the time string matchs the timeformat.
   else return MS_FALSE.
 */
int msTimeMatchPattern(char *timestring, char *timeformat)
{
    int i =-1;

    /* match the pattern format first and then check if the time string  */
    /* matchs the pattern. If it is the case retrurn the MS_TRUE */
    for (i=0; i<MS_NUMTIMEFORMATS; i++)
    {
        if (strcasecmp(ms_timeFormats[i].userformat, timeformat) == 0)
          break;
    }
     
    if (i >= 0 && i < MS_NUMTIMEFORMATS)
    {
        if(!ms_timeFormats[i].regex)
        {
            ms_timeFormats[i].regex = (ms_regex_t *) msSmallMalloc(sizeof(ms_regex_t));
            ms_regcomp(ms_timeFormats[i].regex, 
                    ms_timeFormats[i].pattern, MS_REG_EXTENDED|MS_REG_NOSUB);
        }
        if (ms_regexec(ms_timeFormats[i].regex, timestring, 0,NULL, 0) == 0)
          return MS_TRUE;
        
    }
    return MS_FALSE;
}
Exemplo n.º 3
0
int msTimeSetup() {
  if(!ms_time_inited) {
    msAcquireLock(TLOCK_TIME);
    if(!ms_time_inited) {
      int i;
      for(i=0;i<MS_NUMTIMEFORMATS;i++) {
        ms_timeFormats[i].regex = msSmallMalloc(sizeof(ms_regex_t));
        if(0!=ms_regcomp(ms_timeFormats[i].regex, ms_timeFormats[i].pattern, MS_REG_EXTENDED|MS_REG_NOSUB)) {
          msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msTimeSetup()", ms_timeFormats[i].pattern);
          return MS_FAILURE;
          /* TODO: free already inited regexes */
        }
      }
      ms_limited_pattern = (int *)msSmallMalloc(sizeof(int)*MS_NUMTIMEFORMATS);
      ms_num_limited_pattern = 0;
      ms_time_inited = 1;
    }
    msReleaseLock(TLOCK_TIME);
  }
  return MS_SUCCESS;
}
Exemplo n.º 4
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);
}