* String tokenizer that ignores separator characters within quoted strings * and escaped characters, as per RFC2616 section 2.2. */
| 927 | * and escaped characters, as per RFC2616 section 2.2. |
| 928 | */ |
| 929 | char *cache_strqtok(char *str, const char *sep, char **last) |
| 930 | { |
| 931 | char *token; |
| 932 | int quoted = 0; |
| 933 | |
| 934 | if (!str) { /* subsequent call */ |
| 935 | str = *last; /* start where we left off */ |
| 936 | } |
| 937 | |
| 938 | if (!str) { /* no more tokens */ |
| 939 | return NULL; |
| 940 | } |
| 941 | |
| 942 | /* skip characters in sep (will terminate at '\0') */ |
| 943 | while (*str && ap_strchr_c(sep, *str)) { |
| 944 | ++str; |
| 945 | } |
| 946 | |
| 947 | if (!*str) { /* no more tokens */ |
| 948 | return NULL; |
| 949 | } |
| 950 | |
| 951 | token = str; |
| 952 | |
| 953 | /* skip valid token characters to terminate token and |
| 954 | * prepare for the next call (will terminate at '\0) |
| 955 | * on the way, ignore all quoted strings, and within |
| 956 | * quoted strings, escaped characters. |
| 957 | */ |
| 958 | *last = token; |
| 959 | while (**last) { |
| 960 | if (!quoted) { |
| 961 | if (**last == '\"' && !ap_strchr_c(sep, '\"')) { |
| 962 | quoted = 1; |
| 963 | ++*last; |
| 964 | } |
| 965 | else if (!ap_strchr_c(sep, **last)) { |
| 966 | ++*last; |
| 967 | } |
| 968 | else { |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | else { |
| 973 | if (**last == '\"') { |
| 974 | quoted = 0; |
| 975 | ++*last; |
| 976 | } |
| 977 | else if (**last == '\\') { |
| 978 | ++*last; |
| 979 | if (**last) { |
| 980 | ++*last; |
| 981 | } |
| 982 | } |
| 983 | else { |
| 984 | ++*last; |
| 985 | } |
| 986 | } |
no test coverage detected