returns new length
| 3426 | |
| 3427 | // returns new length |
| 3428 | void PreProcessXmlString( lString16 & s, lUInt32 flags, const lChar16 * enc_table ) |
| 3429 | { |
| 3430 | lChar16 * str = s.modify(); |
| 3431 | int len = s.length(); |
| 3432 | int state = 0; |
| 3433 | lChar16 nch = 0; |
| 3434 | lChar16 lch = 0; |
| 3435 | lChar16 nsp = 0; |
| 3436 | bool pre = (flags & TXTFLG_PRE); |
| 3437 | bool pre_para_splitting = (flags & TXTFLG_PRE_PARA_SPLITTING)!=0; |
| 3438 | if ( pre_para_splitting ) |
| 3439 | pre = false; |
| 3440 | //CRLog::trace("before: '%s' %s", LCSTR(s), pre ? "pre ":" "); |
| 3441 | int tabCount = 0; |
| 3442 | int j = 0; |
| 3443 | for (int i=0; i<len; ++i ) |
| 3444 | { |
| 3445 | lChar16 ch = str[i]; |
| 3446 | if ( pre && ch=='\t' ) |
| 3447 | tabCount++; |
| 3448 | if ( !pre && (ch=='\r' || ch=='\n' || ch=='\t') ) |
| 3449 | ch = ' '; |
| 3450 | if (ch=='\r') |
| 3451 | { |
| 3452 | if ((i==0 || lch!='\n') && (i==len-1 || str[i+1]!='\n')) |
| 3453 | str[j++] = '\n'; |
| 3454 | } |
| 3455 | else if (ch=='\n') |
| 3456 | { |
| 3457 | str[j++] = '\n'; |
| 3458 | } |
| 3459 | else if (ch=='&') |
| 3460 | { |
| 3461 | state = 1; |
| 3462 | nch = 0; |
| 3463 | } |
| 3464 | else if (state==0) |
| 3465 | { |
| 3466 | if (ch==' ') |
| 3467 | { |
| 3468 | if ( pre || !nsp ) |
| 3469 | str[j++] = ch; |
| 3470 | nsp++; |
| 3471 | } |
| 3472 | else |
| 3473 | { |
| 3474 | str[j++] = ch; |
| 3475 | nsp = 0; |
| 3476 | } |
| 3477 | } |
| 3478 | else |
| 3479 | { |
| 3480 | if (state == 2 && ch=='x') |
| 3481 | state = 22; |
| 3482 | else if (state == 22 && hexDigit(ch)>=0) |
| 3483 | nch = (nch << 4) | hexDigit(ch); |
| 3484 | else if (state == 2 && ch>='0' && ch<='9') |
| 3485 | nch = nch * 10 + (ch - '0'); |