/* read the final number from a sequence string and return it. * if given "numstart", return a pointer to the start of * that number in the string */ EXPORTED unsigned int seq_lastnum(const char *list, const char **numstart) { const char *tail; uint32_t retval = 0; if (numstart) *numstart = list; /* empty */ if (!list) return 0; if (!list[0]) return 0; /* find the end of the string */ tail = list + strlen(list); /* work back until first non-digit */ while (tail > list && cyrus_isdigit(tail[-1])) tail--; /* read the number */ if (parseuint32(tail, NULL, &retval)) retval = 0; if (numstart) *numstart = tail; return retval; }
static int read_num(const char **input, unsigned maxval, unsigned *res) { const char *ptr = *input; if (*ptr == '*') { *res = maxval ? maxval : UINT_MAX; ptr++; *input = ptr; return 0; } else if (cyrus_isdigit((int) *ptr)) { *res = 0; while (cyrus_isdigit((int) *ptr)) { *res = (*res)*10 + *ptr - '0'; ptr++; } *input = ptr; return 0; } /* not expected */ return -1; }
static int _parseliteral(struct dlistsax_state *s, struct buf *buf) { size_t len = 0; if (*s->p++ != '{') return IMAP_INVALID_IDENTIFIER; while (s->p < s->end) { if (cyrus_isdigit(*s->p)) { len = (len * 10) + (*s->p++ - '0'); } else if (*s->p == '}') { if (s->p + 3 + len >= s->end) break; if (s->p[1] != '\r') break; if (s->p[2] != '\n') break; buf_setmap(buf, s->p+3, len); s->p += len = 3; return 0; } } return IMAP_INVALID_IDENTIFIER; }