* Remove multiple whitespace from the separator, and add a space to the * beginning and end. This simplifies the separator-skipping code below. */
| 121 | * beginning and end. This simplifies the separator-skipping code below. |
| 122 | */ |
| 123 | static char * |
| 124 | swab_separator(const char *sep) |
| 125 | { |
| 126 | int skip_space = 0; |
| 127 | char *s, *start; |
| 128 | |
| 129 | s = start = malloc(strlen(sep)+3); |
| 130 | if (s == NULL) { |
| 131 | PyErr_NoMemory(); |
| 132 | return NULL; |
| 133 | } |
| 134 | /* add space to front if there isn't one */ |
| 135 | if (*sep != '\0' && !isspace(*sep)) { |
| 136 | *s = ' '; s++; |
| 137 | } |
| 138 | while (*sep != '\0') { |
| 139 | if (isspace(*sep)) { |
| 140 | if (skip_space) { |
| 141 | sep++; |
| 142 | } |
| 143 | else { |
| 144 | *s = ' '; |
| 145 | s++; |
| 146 | sep++; |
| 147 | skip_space = 1; |
| 148 | } |
| 149 | } |
| 150 | else { |
| 151 | *s = *sep; |
| 152 | s++; |
| 153 | sep++; |
| 154 | skip_space = 0; |
| 155 | } |
| 156 | } |
| 157 | /* add space to end if there isn't one */ |
| 158 | if (s != start && s[-1] == ' ') { |
| 159 | *s = ' '; |
| 160 | s++; |
| 161 | } |
| 162 | *s = '\0'; |
| 163 | return start; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Assuming that the separator is the next bit in the string (file), skip it. |
no test coverage detected