(file) Return to XmlWriter.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/XmlWriter.cpp between version 1.133 and 1.134

version 1.133, 2006/01/10 19:41:15 version 1.134, 2006/01/10 22:40:29
Line 574 
Line 574 
 void XmlWriter::appendSpecial(Buffer& out, const String& str) void XmlWriter::appendSpecial(Buffer& out, const String& str)
 { {
     const Uint16* p = (const Uint16*)str.getChar16Data();     const Uint16* p = (const Uint16*)str.getChar16Data();
     size_t n = str.size();      // prevCharIsSpace is true when the last character written to the Buffer
       // is a space character (not a character reference).
     // Handle leading ASCII 7 characers in these next two loops (use unrolling).      Boolean prevCharIsSpace = false;
   
     while (n >= 8)      // If the first character is a space, use a character reference to avoid
     {      // space compression.
         // The following condition is equivalent to this:      if (*p == ' ')
         //     (p[0] < 128 && p[1] < 128 && p[2] < 128 && p[3] < 128 &&  
         //      p[4] < 128 && p[5] < 128 && p[6] < 128 && p[7] < 128)  
   
         if (((p[0]|p[1]|p[2]|p[3]|p[4]|p[5]|p[6]|p[7]) & 0xFF80) == 0)  
         {  
             // Note: "|" is faster than "||" and achieves the same effect  
             // since p[i] is either 0 or 1.  
   
             if (_isSpecialChar7[p[0]] | _isSpecialChar7[p[1]] |  
                 _isSpecialChar7[p[2]] | _isSpecialChar7[p[3]] |  
                 _isSpecialChar7[p[4]] | _isSpecialChar7[p[5]] |  
                 _isSpecialChar7[p[6]] | _isSpecialChar7[p[7]])  
             {  
                 // Rare case.  
                 _appendSpecialChar7(out, p[0]);  
                 _appendSpecialChar7(out, p[1]);  
                 _appendSpecialChar7(out, p[2]);  
                 _appendSpecialChar7(out, p[3]);  
                 _appendSpecialChar7(out, p[4]);  
                 _appendSpecialChar7(out, p[5]);  
                 _appendSpecialChar7(out, p[6]);  
                 _appendSpecialChar7(out, p[7]);  
             }  
             else  
             {             {
                 // Common case.          out.append(STRLIT_ARGS("&#32;"));
                 out.append(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);          p++;
             }  
             p += 8;  
             n -= 8;  
         }  
         else  
             break;  
     }     }
  
     while (n >= 4)      Uint16 c;
       while ((c = *p++) != 0)
     {     {
         // The following condition is equivalent to this:          if (c < 128)
         //     (p[0] < 128 && p[1] < 128 && p[2] < 128 && p[3] < 128)  
   
         if (((p[0]|p[1]|p[2]|p[3]) & 0xFF80) == 0)  
         {         {
             if (_isSpecialChar7[p[0]] | _isSpecialChar7[p[1]] |              if (_isSpecialChar7[c])
                 _isSpecialChar7[p[2]] | _isSpecialChar7[p[3]])  
             {             {
                 // Rare case:                  // Write the character reference for the special character
                 _appendSpecialChar7(out, p[0]);                  out.append(
                 _appendSpecialChar7(out, p[1]);                      _specialChars[int(c)].str, _specialChars[int(c)].size);
                 _appendSpecialChar7(out, p[2]);                  prevCharIsSpace = false;
                 _appendSpecialChar7(out, p[3]);              }
               else if (prevCharIsSpace && (c == ' '))
               {
                   // Write the character reference for the space character, to
                   // avoid compression
                   out.append(STRLIT_ARGS("&#32;"));
                   prevCharIsSpace = false;
             }             }
             else             else
             {             {
                 // Common case:                  out.append(c);
                 out.append(p[0], p[1], p[2], p[3]);                  prevCharIsSpace = (c == ' ');
             }             }
   
             p += 4;  
             n -= 4;  
         }         }
         else         else
             break;  
     }  
   
     // Process remaining characters. A UTF8 character must have been  
     // encountered or this would have never been reached.  
   
     while (n--)  
     {     {
         Uint16 c = *p++;              // Handle UTF8 case
  
         // Special processing for UTF8 case:              if ((((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
                    ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) &&
         if (c < 128)                  *p)
         {         {
             _appendSpecialChar7(out, c);                  _xmlWritter_appendSurrogatePair(out, c, *p++);
             continue;  
         }         }
               else
         // Hanlde UTF8 case (if reached).  
   
         if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||  
            ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))  
         {         {
             Char16 highSurrogate = p[-1];                  _xmlWritter_appendChar(out, c);
             Char16 lowSurrogate = p[0];              }
             p++;  
             n--;  
  
             _xmlWritter_appendSurrogatePair(              prevCharIsSpace = false;
                 out, Uint16(highSurrogate),Uint16(lowSurrogate));  
         }         }
         else  
         {  
             _xmlWritter_appendSpecialChar(out, c);  
         }         }
   
       // If the last character is a space, use a character reference to avoid
       // space compression.
       if (prevCharIsSpace)
       {
           out.remove(out.size() - 1);
           out.append(STRLIT_ARGS("&#32;"));
     }     }
 } }
  
Line 3432 
Line 3391 
             case XmlEntry::CDATA:             case XmlEntry::CDATA:
             {             {
                 _xmlWritter_indent(os, stack.size(), indentChars);                 _xmlWritter_indent(os, stack.size(), indentChars);
                 os << "<![CDATA[...]]>";                  os << "<![CDATA[" << entry.text << "]]>";
                 break;                 break;
             }             }
  


Legend:
Removed from v.1.133  
changed lines
  Added in v.1.134

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2