Explorar o código

Print entire substring instead of each character

Dmitry-Me %!s(int64=11) %!d(string=hai) anos
pai
achega
d95172ba47
Modificáronse 1 ficheiros con 5 adicións e 2 borrados
  1. 5 2
      tinyxml2.cpp

+ 5 - 2
tinyxml2.cpp

@@ -2066,8 +2066,11 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
                 // entity, and keep looking.
                 if ( flag[(unsigned char)(*q)] ) {
                     while ( p < q ) {
-                        Print( "%c", *p );
-                        ++p;
+                        const size_t delta = q - p;
+                        // %.*s accepts type int as "precision"
+                        const int toPrint = ( INT_MAX < delta ) ? INT_MAX : delta;
+                        Print( "%.*s", toPrint, p );
+                        p += toPrint;
                     }
                     for( int i=0; i<NUM_ENTITIES; ++i ) {
                         if ( entities[i].value == *q ) {