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

Diff for /pegasus/src/Pegasus/Common/XmlReader.cpp between version 1.38 and 1.46

version 1.38, 2002/03/20 17:47:07 version 1.46, 2002/03/25 20:13:58
Line 29 
Line 29 
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
   #include <Pegasus/Common/Config.h>
 #include <cassert> #include <cassert>
 #include <cctype> #include <cctype>
 #include <cstdio> #include <cstdio>
 #include <cstdlib> #include <cstdlib>
   #if defined(PEGASUS_OS_TYPE_UNIX)
   #include <errno.h>
   #endif
 #include "CIMName.h" #include "CIMName.h"
 #include "XmlReader.h" #include "XmlReader.h"
 #include "XmlWriter.h" #include "XmlWriter.h"
Line 584 
Line 587 
  
 Boolean XmlReader::stringToReal(const char* stringValue, Real64& x) Boolean XmlReader::stringToReal(const char* stringValue, Real64& x)
 { {
       //
       // Check the string against the DMTF-defined grammar
       //
     const char* p = stringValue;     const char* p = stringValue;
  
     if (!*p)     if (!*p)
Line 640 
Line 646 
     if (*p)     if (*p)
         return false;         return false;
  
       //
       // Do the conversion
       //
     char* end;     char* end;
       errno = 0;
     x = strtod(stringValue, &end);     x = strtod(stringValue, &end);
       if (*end || (errno == ERANGE))
       {
           return false;
       }
   
     return true;     return true;
 } }
  
   inline Uint8 _hexCharToNumeric(const char c)
   {
       Uint8 n;
   
       if (isdigit(c))
           n = (c - '0');
       else if (isupper(c))
           n = (c - 'A' + 10);
       else // if (islower(c))
           n = (c - 'a' + 10);
   
       return n;
   }
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // stringToSignedInteger // stringToSignedInteger
 // //
 //      [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" ) //      [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" )
   //    or
   //      [ "+" | "-" ] ( "0x" | "0X" ) 1*hexDigit
 // //
 // ATTN-B: handle conversion from hexadecimal.  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Boolean XmlReader::stringToSignedInteger( Boolean XmlReader::stringToSignedInteger(
Line 661 
Line 691 
     x = 0;     x = 0;
     const char* p = stringValue;     const char* p = stringValue;
  
     if (!*p)      if (!p || !*p)
         return false;         return false;
  
     // Skip optional sign:     // Skip optional sign:
Line 671 
Line 701 
     if (negative || *p == '+')     if (negative || *p == '+')
         p++;         p++;
  
     // If the next thing is a zero, then it must be the last:  
   
     if (*p == '0')     if (*p == '0')
         return p[1] == '\0';      {
           if ( (p[1] == 'x') || (p[1] == 'X') )
     // Expect a positive decimal digit:          {
               // Convert a hexadecimal string
  
     const char* first = p;              // Skip over the "0x"
               p+=2;
  
     if (!isdigit(*p) || *p == '0')              // At least one hexadecimal digit is required
               if (!isxdigit(*p))
         return false;         return false;
  
     p++;              // Build the Sint64 as a negative number, regardless of the
               // eventual sign (negative numbers can be bigger than positive ones)
  
     // Expect zero or more digits:              // Add on each digit, checking for overflow errors
               while (isxdigit(*p))
               {
                   // Make sure we won't overflow when we multiply by 16
                   if (x < PEGASUS_LLONG_MIN/16)
                   {
                       return false;
                   }
                   x = x << 4;
  
     while (isdigit(*p))                  // Make sure we don't overflow when we add the next digit
         p++;                  Sint64 newDigit = Sint64(_hexCharToNumeric(*p++));
                   if (PEGASUS_LLONG_MIN - x > -newDigit)
                   {
                       return false;
                   }
                   x = x - newDigit;
               }
  
               // If we found a non-hexadecimal digit, report an error
     if (*p)     if (*p)
         return false;         return false;
  
     const char* last = p;              // Return the integer to positive, if necessary, checking for an
               // overflow error
               if (!negative)
               {
                   if (x == PEGASUS_LLONG_MIN)
                   {
                       return false;
                   }
                   x = -x;
               }
               return true;
           }
           else
           {
               // A decimal string that starts with '0' must be exactly "0".
               return p[1] == '\0';
           }
       }
  
     // Build the Sint64 as a negative number, regardless of the eventual sign      // Expect a positive decimal digit:
     x = -(*first++ - '0');  
  
     while (first != last)      // At least one decimal digit is required
       if (!isdigit(*p))
           return false;
   
       // Build the Sint64 as a negative number, regardless of the
       // eventual sign (negative numbers can be bigger than positive ones)
   
       // Add on each digit, checking for overflow errors
       while (isdigit(*p))
     {     {
         if (x < -922337203685477580LL /* -(1<<63) / 10 */)          // Make sure we won't overflow when we multiply by 10
           if (x < PEGASUS_LLONG_MIN/10)
         {         {
             return false;             return false;
         }         }
         x = 10 * x;         x = 10 * x;
         Sint64 newDigit = (*first++ - '0');  
           // Make sure we won't overflow when we add the next digit
           Sint64 newDigit = (*p++ - '0');
         if (PEGASUS_LLONG_MIN - x > -newDigit)         if (PEGASUS_LLONG_MIN - x > -newDigit)
         {         {
             return false;             return false;
Line 713 
Line 787 
         x = x - newDigit;         x = x - newDigit;
     }     }
  
       // If we found a non-decimal digit, report an error
       if (*p)
           return false;
   
       // Return the integer to positive, if necessary, checking for an
       // overflow error
     if (!negative)     if (!negative)
     {     {
         if (x == PEGASUS_LLONG_MIN)         if (x == PEGASUS_LLONG_MIN)
Line 728 
Line 808 
 // //
 // stringToUnsignedInteger // stringToUnsignedInteger
 // //
 //      [ "+" ] ( positiveDecimalDigit *decimalDigit | "0" )  //      ( positiveDecimalDigit *decimalDigit | "0" )
   //    or
   //      ( "0x" | "0X" ) 1*hexDigit
 // //
 // ATTN-B: handle conversion from hexadecimal.  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Boolean XmlReader::stringToUnsignedInteger( Boolean XmlReader::stringToUnsignedInteger(
Line 740 
Line 821 
     x = 0;     x = 0;
     const char* p = stringValue;     const char* p = stringValue;
  
     if (!*p)      if (!p || !*p)
         return false;  
   
     // Skip optional sign:  
   
     if (*p == '-')  
         return false;         return false;
  
     if (*p == '+')  
         p++;  
   
     // If the next thing is a zero, then it must be the last:  
   
     if (*p == '0')     if (*p == '0')
         return p[1] == '\0';      {
           if ( (p[1] == 'x') || (p[1] == 'X') )
     // Expect a positive decimal digit:          {
               // Convert a hexadecimal string
  
     const char* first = p;              // Skip over the "0x"
               p+=2;
  
     if (!isdigit(*p) || *p == '0')              // At least one hexadecimal digit is required
               if (!*p)
         return false;         return false;
  
     p++;              // Add on each digit, checking for overflow errors
               while (isxdigit(*p))
     // Expect zero or more digits:              {
                   // Make sure we won't overflow when we multiply by 16
                   if (x > PEGASUS_ULLONG_MAX/16)
                   {
                       return false;
                   }
                   x = x << 4;
  
     while (isdigit(*p))                  // We can't overflow when we add the next digit
         p++;                  Uint64 newDigit = Uint64(_hexCharToNumeric(*p++));
                   if (PEGASUS_ULLONG_MAX - x < newDigit)
                   {
                       return false;
                   }
                   x = x + newDigit;
               }
  
               // If we found a non-hexadecimal digit, report an error
     if (*p)     if (*p)
         return false;         return false;
  
     const char* last = p;              return true;
           }
           else
           {
               // A decimal string that starts with '0' must be exactly "0".
               return p[1] == '\0';
           }
       }
   
       // Expect a positive decimal digit:
  
     while (first != last)      // Add on each digit, checking for overflow errors
       while (isdigit(*p))
     {     {
         if (x > 1844674407370955161ULL /* (1<<64 - 1) / 10 */)          // Make sure we won't overflow when we multiply by 10
           if (x > PEGASUS_ULLONG_MAX/10)
         {         {
             return false;             return false;
         }         }
         x = 10 * x;         x = 10 * x;
         Uint64 newDigit = (*first++ - '0');  
         if (18446744073709551615ULL - x < newDigit)          // Make sure we won't overflow when we add the next digit
           Uint64 newDigit = (*p++ - '0');
           if (PEGASUS_ULLONG_MAX - x < newDigit)
         {         {
             return false;             return false;
         }         }
         x = x + newDigit;         x = x + newDigit;
     }     }
  
       // If we found a non-decimal digit, report an error
       if (*p)
           return false;
   
     return true;     return true;
 } }
  
Line 811 
Line 915 
 { {
     // ATTN-B: accepting only UTF-8 for now! (affects string and char16):     // ATTN-B: accepting only UTF-8 for now! (affects string and char16):
  
   // The Specification for the Representation of CIM in XML does not indicate
   // that a default value should be used when a VALUE element is empty.
   //#if 0  ATTN-RK-P3-20020321: Take this code out when null qualifiers are fixed
     // If strlen == 0, set to default value for type     // If strlen == 0, set to default value for type
  
     if (strlen(valueString)==0)     if (strlen(valueString)==0)
Line 832 
Line 939 
             case CIMType::REAL64: return CIMValue(Real64(0));             case CIMType::REAL64: return CIMValue(Real64(0));
         }         }
     }     }
   //#endif
  
     // Create value per type     // Create value per type
     switch (type)     switch (type)
Line 975 
Line 1083 
             Real64 x;             Real64 x;
  
             if (!stringToReal(valueString, x))             if (!stringToReal(valueString, x))
                 throw XmlSemanticError(lineNumber, "Bad real value");                  throw XmlSemanticError(lineNumber, "Bad real number value");
  
             // ATTN-RK-P3-20010319: This value gets truncated.  
             return CIMValue(Real32(x));             return CIMValue(Real32(x));
         }         }
  
Line 986 
Line 1093 
             Real64 x;             Real64 x;
  
             if (!stringToReal(valueString, x))             if (!stringToReal(valueString, x))
                 throw XmlSemanticError(lineNumber, "Bad real value");                  throw XmlSemanticError(lineNumber, "Bad real number value");
  
             return CIMValue(x);             return CIMValue(x);
         }         }
Line 1311 
Line 1418 
     Boolean translatable = getCimBooleanAttribute(     Boolean translatable = getCimBooleanAttribute(
         lineNumber, entry, tagName, "TRANSLATABLE", false, false);         lineNumber, entry, tagName, "TRANSLATABLE", false, false);
  
     // ATTN: KS P1 5 Mar 2002 Should this not be CIMFlavor::DEFAULTS??      // Start with CIMFlavor::NONE.  Defaults are specified in the
     //Uint32 flavor = CIMFlavor::DEFAULTS;      // getCimBooleanAttribute() calls above.
     // ATTN-RK-P1-20020307: No, Karl.  If you initialize to the defaults,  
     // you have to unset the default flavors that don't apply.  The code  
     // below only adds qualifiers.  
     Uint32 flavor = CIMFlavor::NONE;     Uint32 flavor = CIMFlavor::NONE;
  
     if (overridable)     if (overridable)


Legend:
Removed from v.1.38  
changed lines
  Added in v.1.46

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2