/** * 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; }
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); }
/** 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; }
/** return MS_TRUE if the time string matchs the timeformat. else return MS_FALSE. */ int msTimeMatchPattern(const char *timestring, const char *timeformat) { int i =-1; if(msTimeSetup() != MS_SUCCESS) { return MS_FALSE; } /* 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) { int match = ms_regexec(ms_timeFormats[i].regex, timestring, 0, NULL, 0); if(match == 0) return MS_TRUE; } return MS_FALSE; }
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); }