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

Diff for /pegasus/src/Pegasus/Common/XmlGenerator.cpp between version 1.3 and 1.6.4.6

version 1.3, 2008/04/29 20:40:24 version 1.6.4.6, 2009/10/27 18:38:08
Line 1 
Line 1 
 //%2006////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development  // Licensed to The Open Group (TOG) under one or more contributor license
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;  // this work for additional information regarding copyright ownership.
 // IBM Corp.; EMC Corporation, The Open Group.  // Each contributor licenses this file to you under the OpenPegasus Open
 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;  // Source License; you may not use this file except in compliance with the
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.  // License.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;  
 // EMC Corporation; VERITAS Software Corporation; The Open Group.  
 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;  
 // EMC Corporation; Symantec Corporation; The Open Group.  
 //  
 // Permission is hereby granted, free of charge, to any person obtaining a copy  
 // of this software and associated documentation files (the "Software"), to  
 // deal in the Software without restriction, including without limitation the  
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  
 // sell copies of the Software, and to permit persons to whom the Software is  
 // furnished to do so, subject to the following conditions:  
 //  
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  
 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
 // //
 //==============================================================================  // Permission is hereby granted, free of charge, to any person obtaining a
   // copy of this software and associated documentation files (the "Software"),
   // to deal in the Software without restriction, including without limitation
   // the rights to use, copy, modify, merge, publish, distribute, sublicense,
   // and/or sell copies of the Software, and to permit persons to whom the
   // Software is furnished to do so, subject to the following conditions:
   //
   // The above copyright notice and this permission notice shall be included
   // in all copies or substantial portions of the Software.
   //
   // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   //
   //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 206 
Line 204 
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
 }; };
  
   // If _isSpecialChar7[ch] is true, then ch is a special character, which must
   // have a special encoding in XML. But only use 7-biat ASCII characters to
   // index this array.
   static const int _isNormalChar7[] =
   {
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,
       1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,
       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
   };
   
   
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 Buffer& operator<<(Buffer& out, const Char16& x) Buffer& operator<<(Buffer& out, const Char16& x)
Line 250 
Line 260 
     return out;     return out;
 } }
  
   const StrLit XmlGenerator::_XmlWriterTypeStrings[17] =
   {
       STRLIT("TYPE=\"boolean\""),   STRLIT("TYPE=\"uint8\""),
       STRLIT("TYPE=\"sint8\""),     STRLIT("TYPE=\"uint16\""),
       STRLIT("TYPE=\"sint16\""),    STRLIT("TYPE=\"uint32\""),
       STRLIT("TYPE=\"sint32\""),    STRLIT("TYPE=\"uint64\""),
       STRLIT("TYPE=\"sint64\""),    STRLIT("TYPE=\"real32\""),
       STRLIT("TYPE=\"real64\""),    STRLIT("TYPE=\"char16\""),
       STRLIT("TYPE=\"string\""),    STRLIT("TYPE=\"datetime\""),
       STRLIT("TYPE=\"reference\""), STRLIT("TYPE=\"object\""),
       STRLIT("TYPE=\"instance\"")
   };
   
   const StrLit XmlGenerator::_XmlWriterKeyTypeStrings[17] =
   {
       STRLIT("boolean"), STRLIT("numeric"),
       STRLIT("numeric"), STRLIT("numeric"),
       STRLIT("numeric"), STRLIT("numeric"),
       STRLIT("numeric"), STRLIT("numeric"),
       STRLIT("numeric"), STRLIT("numeric"),
       STRLIT("numeric"), STRLIT("string"),
       STRLIT("string"),  STRLIT("string"),
       /* The following are not valid values for a keytype, but left in here
          so in case something is going wrong it can be easily concluded from the
          generated XML */
       STRLIT("reference"), STRLIT("object"),
       STRLIT("instance")
   };
   
 void XmlGenerator::_appendChar(Buffer& out, const Char16& c) void XmlGenerator::_appendChar(Buffer& out, const Char16& c)
 { {
     // We need to convert the Char16 to UTF8 then append the UTF8     // We need to convert the Char16 to UTF8 then append the UTF8
Line 362 
Line 401 
         _appendSpecialChar(os, *str++);         _appendSpecialChar(os, *str++);
 } }
  
 // On windows sprintf outputs 3 digit precision exponent prepending  
 // zeros. Make it 2 digit precision if first digit is zero in the exponent.  
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
 void XmlGenerator::_normalizeRealValueString(char* str)  
 {  
     // skip initial sign value...  
     if (*str == '-' || *str == '+')  
     {  
         ++str;  
     }  
     while (*str && *str != '+' && *str != '-')  
     {  
         ++str;  
     }  
     if (*str && * ++str == '0')  
     {  
         *str = *(str+1);  
         *(str+1) = *(str+2);  
         *(str+2) = 0;  
     }  
 }  
 #endif  
   
 void XmlGenerator::append(Buffer& out, const Char16& x) void XmlGenerator::append(Buffer& out, const Char16& x)
 { {
     _appendChar(out, x);     _appendChar(out, x);
Line 432 
Line 448 
  
 void XmlGenerator::append(Buffer& out, Real32 x) void XmlGenerator::append(Buffer& out, Real32 x)
 { {
       Uint32 outputLength=0;
     char buffer[128];     char buffer[128];
     // %.7e gives '[-]m.ddddddde+/-xx', which seems compatible with the format      const char * output = Real32ToString(buffer, x, outputLength);
     // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec      out.append(output, outputLength);
     // (4 byte IEEE floating point)  
     sprintf(buffer, "%.7e", x);  
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     _normalizeRealValueString(buffer);  
 #endif  
     append(out, buffer);  
 } }
  
 void XmlGenerator::append(Buffer& out, Real64 x) void XmlGenerator::append(Buffer& out, Real64 x)
 { {
       Uint32 outputLength=0;
     char buffer[128];     char buffer[128];
     // %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible      const char * output = Real64ToString(buffer, x, outputLength);
     // with the format given in the CIM/XML spec, and the precision required      out.append(output, outputLength);
     // by the CIM 2.2 spec (8 byte IEEE floating point)  
     sprintf(buffer, "%.16e", x);  
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     _normalizeRealValueString(buffer);  
 #endif  
     append(out, buffer);  
 } }
  
 void XmlGenerator::append(Buffer& out, const char* str) void XmlGenerator::append(Buffer& out, const char* str)
Line 599 
Line 605 
     }     }
 } }
  
   // str has to be UTF-8 encoded
   // that means the characters used cannot be larger than 7bit ASCII in value
   // range
   void XmlGenerator::appendSpecial(Buffer& out, const char* str, Uint32 size)
   {
       // employ loop unrolling and a less checking optimized Buffer access
   
       // Buffer cannot grow more than 6*size characters (ie. 4*size+2*size)
       Uint32 newMaxSize = (size << 2) + (size << 1);
       if (out.size() + newMaxSize >= out.capacity())
       {
           out.reserveCapacity(out.capacity() + newMaxSize);
       }
   
       // Before using a loop unrolled algorithm to pick out the special chars
       // we are going to assume there is no special char as this is the case most
       // of the time anyway
       Uint32 sizeStart=size;
       const Uint8* p= (const Uint8*) str;
   
       while (size >= 4 &&
                (_isNormalChar7[p[0]] |
                 _isNormalChar7[p[1]] |
                 _isNormalChar7[p[2]] |
                 _isNormalChar7[p[3]]))
       {
           size -= 4;
           p += 4;
       }
       out.append_unchecked(str,sizeStart-size);
       str=(const char*)p;
   
       while (size>=8)
       {
           register int c;
           c = str[0];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[1];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[2];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[3];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[4];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[5];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[6];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[7];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           str+=8;
           size-=8;
       }
   
       while (size>=4)
       {
           register int c;
           c = str[0];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[1];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[2];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           c = str[3];
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           str+=4;
           size-=4;
       }
   
       while (size--)
       {
           register int c;
           c=*str;
           if (_isSpecialChar7[c])
           {
               out.append_unchecked(
                   _specialChars[c].str,
                   _specialChars[c].size);
           }
           else
           {
               out.append_unchecked(c);
           }
           str++;
       }
   }
   
   
 // See http://www.ietf.org/rfc/rfc2396.txt section 2 // See http://www.ietf.org/rfc/rfc2396.txt section 2
 // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ',' // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ','
 // Excluded characters: // Excluded characters:


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.6.4.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2