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

Diff for /pegasus/src/Pegasus/Common/CommonUTF.cpp between version 1.1.2.1 and 1.19

version 1.1.2.1, 2003/08/13 19:39:50 version 1.19, 2006/09/05 19:59:33
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2003 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // 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 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 23 
Line 31 
 // //
 // Author: Dave Rosckes   (rosckes@us.ibm.com) // Author: Dave Rosckes   (rosckes@us.ibm.com)
 // //
   // Modified By: David Dillard, VERITAS Software Corp.
   //                  (david.dillard@veritas.com)
   //              Yi Zhou, Hewlett-Packard Company (yi.zhou@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/Array.h>
   #include <Pegasus/Common/Logger.h>
 #include "CommonUTF.h" #include "CommonUTF.h"
   #include <cstdio>
   #include <cstring>
   #include <cctype>
   
   #ifdef PEGASUS_HAS_ICU
   #include <unicode/uclean.h>
   #endif
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
 int isValid_U8(const Uint8 *src, int size)  
   const Uint32 halfBase = 0x0010000UL;
   const Uint32 halfMask = 0x3FFUL;
   const int halfShift  = 10;
   const Uint8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
   
   const Uint32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
                0x03C82080UL, 0xFA082080UL, 0x82082080UL };
   
   const char trailingBytesForUTF8[256] = {
       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,
       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,
       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,
       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,
       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,
       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,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,
       2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
   };
   inline Uint8 _hexCharToNumeric(Char16 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;
   }
   
   // Note: Caller must ensure that "src" contains "size" bytes.
   Boolean isValid_U8(const Uint8 *src, int size)
 { {
     Uint8 U8_char;     Uint8 U8_char;
     const Uint8 *srcptr = src+size;     const Uint8 *srcptr = src+size;
Line 85 
Line 141 
                 return false;                 return false;
             }             }
             break;             break;
           default:
           {
           return false;
               }
  
     }     }
     return true;     return true;
Line 100 
Line 160 
     Uint8* tgt = *tgtHead;     Uint8* tgt = *tgtHead;
     while (src < srcEnd)     while (src < srcEnd)
     {     {
           if (*src < 128)
           {
               if (tgt == tgtEnd)
               {
                   returnCode = -1;
                   break;
               }
   
               *tgt++ = *src++;
               continue;
           }
   
         Uint32 tempchar;         Uint32 tempchar;
         Uint16 numberOfBytes = 0;         Uint16 numberOfBytes = 0;
         const Uint16* oldsrc = src;         const Uint16* oldsrc = src;
Line 249 
Line 321 
     *tgtHead = tgt;     *tgtHead = tgt;
     return returnCode;     return returnCode;
 } }
   
   Boolean isUTF8Aux(const char *legal)
   {
       char numBytes = UTF_8_COUNT_TRAIL_BYTES(*legal)+1;
   
       // Validate that the string is long enough to hold all the expected bytes.
       // Note that if legal[0] == 0, numBytes will be 1.
       for (char i=1; i<numBytes; i++)
       {
           if (legal[i] == 0)
           {
               return false;
           }
       }
   
       return (isValid_U8((const Uint8 *)legal, numBytes));
   }
   
   Boolean isUTF8Str(const char *legal)
   {
       /*char tmp[] = {0xCE,0x99,0xCE,0xBF,0xCF,0x8D,0xCE,0xBD,0xCE,
                         0xB9,0xCE,0xBA,0xCE,0xBF,0xCE,0xBD,0xCF,0x84,
                         0x00};*/
   //  char tmp_[] = "class";
   //  char * tmp = legal;
       size_t count = 0;
       const size_t size = strlen(legal);
   //  printf("size = %d\n",size);
       while(count<size)
       {
   //      printf("count = %d\n",count);
           if(isUTF8(&legal[count]) == true){
               UTF8_NEXT(legal,count);
           }else{
   //          printf("bad string\n");
               return false;
           }
       }
   //  printf("good string\n");
       return true;
   /*
       printf("legal = %s\n\n", legal);
       Uint32 count = 0;
       Uint32 trailingBytes = 0;
           Uint32 size = strlen(legal);
       printf("size of legal is %d\n",size);
           while(count<size-1)
           {
           printf("count = %d\n", count);
                   if(isUTF8((char*)&legal[count]) == true){
                       UTF8_NEXT(legal,trailingBytes);
               count += trailingBytes;
           } else{
               printf("CommonUTF8:: returning false; position[%d]",count);
                return false;
           }
           }
        printf("CommonUTF8:: returning false; position[%d]",count);
       return true;*/
   }
   
   String escapeStringEncoder(const String& Str)
   {
       String escapeStr;
       Uint16 escChar;
       char hexencoding[6];
   
       for(Uint32 i = 0; i < Str.size(); ++i)
       {
       escChar = Str[i];
       if(escChar <= 0x7F)
           {
           escapeStr.append(escChar);
           }
       else
       {
           memset(hexencoding,0x00,sizeof(hexencoding));
               sprintf(hexencoding, "%%%03X%X", escChar/16, escChar%16);
               escapeStr.append(hexencoding);
       }
       }
       return(escapeStr);
   }
   
   String escapeStringDecoder(const String& Str)
   {
       Uint32 i;
   
       Array<Uint16> utf16Chars;
   
       for (i=0; i< Str.size(); ++i)
       {
           if (Str[i] == '%')
           {
               Uint8 digit1 = _hexCharToNumeric((Str[++i]));
               Uint8 digit2 = _hexCharToNumeric((Str[++i]));
               Uint8 digit3 = _hexCharToNumeric((Str[++i]));
               Uint8 digit4 = _hexCharToNumeric((Str[++i]));
   
           Uint16 decodedChar = (digit1<<12) + (digit2<<8) +
                                    (digit3<< 4) + (digit4);
   
               utf16Chars.append(decodedChar);
           }
           else
           {
               utf16Chars.append((Uint16)Str[i]);
           }
       }
   
       // If there was a string to decode...
       if (Str.size() > 0)
       {
           utf16Chars.append('\0');
           return String((Char16 *)utf16Chars.getData());
       }
       else
       {
           return String();
       }
   }
   
   #ifdef PEGASUS_HAS_ICU
   
   Boolean InitializeICU::_initAttempted = false;
   Boolean InitializeICU::_initSuccessful = false;
   Mutex InitializeICU::_initMutex;
   
   Boolean InitializeICU::initICUSuccessful()
   {
       if (!_initAttempted)
       {
           {
               AutoMutex lock(_initMutex);
   
               if (!_initAttempted)
               {
                   UErrorCode _status = U_ZERO_ERROR;
   
                   // Initialize ICU
                   u_init(&_status);
   
                   if (U_FAILURE(_status))
                   {
                       _initSuccessful = false;
                       Logger::put (Logger::STANDARD_LOG , System::CIMSERVER,
                                    Logger::WARNING,
                                    "ICU initialization failed with error: $0.",
                                    _status);
                   }
                   else
                   {
                       _initSuccessful = true;
                   }
                   _initAttempted = true;
               }
           }
       }
   
       return _initSuccessful;
   }
   
   #endif
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.19

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2