| 2662 | |
| 2663 | |
| 2664 | void XMLPrinter::PrintString( const char* p, bool restricted ) |
| 2665 | { |
| 2666 | // Look for runs of bytes between entities to print. |
| 2667 | const char* q = p; |
| 2668 | |
| 2669 | if ( _processEntities ) { |
| 2670 | const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag; |
| 2671 | while ( *q ) { |
| 2672 | TIXMLASSERT( p <= q ); |
| 2673 | // Remember, char is sometimes signed. (How many times has that bitten me?) |
| 2674 | if ( *q > 0 && *q < ENTITY_RANGE ) { |
| 2675 | // Check for entities. If one is found, flush |
| 2676 | // the stream up until the entity, write the |
| 2677 | // entity, and keep looking. |
| 2678 | if ( flag[static_cast<unsigned char>(*q)] ) { |
| 2679 | while ( p < q ) { |
| 2680 | const size_t delta = q - p; |
| 2681 | const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta); |
| 2682 | Write( p, toPrint ); |
| 2683 | p += toPrint; |
| 2684 | } |
| 2685 | bool entityPatternPrinted = false; |
| 2686 | for( int i=0; i<NUM_ENTITIES; ++i ) { |
| 2687 | if ( entities[i].value == *q ) { |
| 2688 | Putc( '&' ); |
| 2689 | Write( entities[i].pattern, entities[i].length ); |
| 2690 | Putc( ';' ); |
| 2691 | entityPatternPrinted = true; |
| 2692 | break; |
| 2693 | } |
| 2694 | } |
| 2695 | if ( !entityPatternPrinted ) { |
| 2696 | // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release |
| 2697 | TIXMLASSERT( false ); |
| 2698 | } |
| 2699 | ++p; |
| 2700 | } |
| 2701 | } |
| 2702 | ++q; |
| 2703 | TIXMLASSERT( p <= q ); |
| 2704 | } |
| 2705 | // Flush the remaining string. This will be the entire |
| 2706 | // string if an entity wasn't found. |
| 2707 | if ( p < q ) { |
| 2708 | const size_t delta = q - p; |
| 2709 | const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta); |
| 2710 | Write( p, toPrint ); |
| 2711 | } |
| 2712 | } |
| 2713 | else { |
| 2714 | Write( p ); |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | |
| 2719 | void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) |