Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int parseMonth(const char *input) {
- int rv=-1;
- const char *p=input;
- int len=strlen(input);
- /* Short cut when the length falls outside of
- expected ranges */
- if(len < 3 || len > 3) {
- return rv;
- }
- /* Collapsing anything with fewer than 4 paths */
- /* 12 matches for "" */
- switch(p[0]) {
- case 'A':
- /* 2 match(es) for "A" */
- if(memcmp(p, "Apr\0", 4) == 0) {
- rv=3;
- } else if(memcmp(p, "Aug\0", 4) == 0) {
- rv=7;
- }
- break;
- case 'D':
- /* 1 match(es) for "D" */
- if(memcmp(p, "Dec\0", 4) == 0) {
- rv=11;
- }
- break;
- case 'F':
- /* 1 match(es) for "F" */
- if(memcmp(p, "Feb\0", 4) == 0) {
- rv=1;
- }
- break;
- case 'J':
- /* 3 match(es) for "J" */
- if(memcmp(p, "Jan\0", 4) == 0) {
- rv=0;
- } else if(memcmp(p, "Jun\0", 4) == 0) {
- rv=5;
- } else if(memcmp(p, "Jul\0", 4) == 0) {
- rv=6;
- }
- break;
- case 'M':
- /* 2 match(es) for "M" */
- if(memcmp(p, "Mar\0", 4) == 0) {
- rv=2;
- } else if(memcmp(p, "May\0", 4) == 0) {
- rv=4;
- }
- break;
- case 'O':
- /* 1 match(es) for "O" */
- if(memcmp(p, "Oct\0", 4) == 0) {
- rv=9;
- }
- break;
- case 'N':
- /* 1 match(es) for "N" */
- if(memcmp(p, "Nov\0", 4) == 0) {
- rv=10;
- }
- break;
- case 'S':
- /* 1 match(es) for "S" */
- if(memcmp(p, "Sep\0", 4) == 0) {
- rv=8;
- }
- break;
- }
- return rv;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement