/
| 191 | |
| 192 | /*****************************************************************************/ |
| 193 | char *pj_shrink (char *c) { |
| 194 | /****************************************************************************** |
| 195 | Collapse repeated whitespace. Remove '+' and ';'. Make ',' and '=' greedy, |
| 196 | consuming their surrounding whitespace. |
| 197 | ******************************************************************************/ |
| 198 | size_t i, j, n; |
| 199 | |
| 200 | /* Flag showing that a whitespace (ws) has been written after last non-ws */ |
| 201 | bool ws = false; |
| 202 | |
| 203 | if (nullptr==c) |
| 204 | return nullptr; |
| 205 | |
| 206 | pj_chomp (c); |
| 207 | n = strlen (c); |
| 208 | if (n==0) |
| 209 | return c; |
| 210 | |
| 211 | /* First collapse repeated whitespace (including +/;) */ |
| 212 | i = 0; |
| 213 | bool in_string = false; |
| 214 | for (j = 0; j < n; j++) { |
| 215 | |
| 216 | if( in_string ) { |
| 217 | if( c[j] == '"' && c[j+1] == '"' ) { |
| 218 | c[i++] = c[j]; |
| 219 | j++; |
| 220 | } else if( c[j] == '"' ) { |
| 221 | in_string = false; |
| 222 | } |
| 223 | c[i++] = c[j]; |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | /* Eliminate prefix '+', only if preceded by whitespace */ |
| 228 | /* (i.e. keep it in 1.23e+08) */ |
| 229 | if ((i > 0) && ('+'==c[j]) && ws) |
| 230 | c[j] = ' '; |
| 231 | if ((i==0) && ('+'==c[j])) |
| 232 | c[j] = ' '; |
| 233 | |
| 234 | // Detect a string beginning after '=' |
| 235 | if( c[j] == '"' && i > 0 && c[i-1] == '=' ) { |
| 236 | in_string = true; |
| 237 | ws = false; |
| 238 | c[i++] = c[j]; |
| 239 | continue; |
| 240 | } |
| 241 | |
| 242 | if (isspace (c[j]) || ';'==c[j]) { |
| 243 | if (false==ws && (i > 0)) |
| 244 | c[i++] = ' '; |
| 245 | ws = true; |
| 246 | continue; |
| 247 | } |
| 248 | else { |
| 249 | ws = false; |
| 250 | c[i++] = c[j]; |
no test coverage detected