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

Diff for /pegasus/src/Pegasus/Common/String.cpp between version 1.129.2.1 and 1.135.4.1

version 1.129.2.1, 2007/11/08 09:15:06 version 1.135.4.1, 2009/10/13 13:39:24
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  // Permission is hereby granted, free of charge, to any person obtaining a
 // of this software and associated documentation files (the "Software"), to  // copy of this software and associated documentation files (the "Software"),
 // deal in the Software without restriction, including without limitation the  // to deal in the Software without restriction, including without limitation
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // sell copies of the Software, and to permit persons to whom the Software is  // and/or sell copies of the Software, and to permit persons to whom the
 // furnished to do so, subject to the following conditions:  // Software is furnished to do so, subject to the following conditions:
 // //
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // The above copyright notice and this permission notice shall be included
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // in all copies or substantial portions of the Software.
 // "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.  
 // //
 //==============================================================================  // 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.
   //
   //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/PegasusAssert.h> #include <Pegasus/Common/PegasusAssert.h>
 #include <cstring> #include <cstring>
 #include "InternalException.h" #include "InternalException.h"
 #include "CommonUTF.h"  
 #include "MessageLoader.h" #include "MessageLoader.h"
 #include "StringRep.h" #include "StringRep.h"
  
 #ifdef PEGASUS_HAS_ICU #ifdef PEGASUS_HAS_ICU
   # include <unicode/ures.h>
 #include <unicode/ustring.h> #include <unicode/ustring.h>
 #include <unicode/uchar.h> #include <unicode/uchar.h>
 #endif #endif
Line 171 
Line 169 
     return x;     return x;
 } }
  
 template<class P, class Q>  
 static void _copy(P* p, const Q* q, size_t n)  
 {  
     // The following employs loop unrolling for efficiency. Please do not  
     // eliminate.  
   
     while (n >= 8)  
     {  
         p[0] = q[0];  
         p[1] = q[1];  
         p[2] = q[2];  
         p[3] = q[3];  
         p[4] = q[4];  
         p[5] = q[5];  
         p[6] = q[6];  
         p[7] = q[7];  
         p += 8;  
         q += 8;  
         n -= 8;  
     }  
   
     while (n >= 4)  
     {  
         p[0] = q[0];  
         p[1] = q[1];  
         p[2] = q[2];  
         p[3] = q[3];  
         p += 4;  
         q += 4;  
         n -= 4;  
     }  
   
     while (n--)  
         *p++ = *q++;  
 }  
   
 static Uint16* _find(const Uint16* s, size_t n, Uint16 c) static Uint16* _find(const Uint16* s, size_t n, Uint16 c)
 { {
     // The following employs loop unrolling for efficiency. Please do not     // The following employs loop unrolling for efficiency. Please do not
Line 268 
Line 230 
     return 0;     return 0;
 } }
  
   #ifdef PEGASUS_STRING_NO_UTF8
 static int _compareNoUTF8(const Uint16* s1, const char* s2) static int _compareNoUTF8(const Uint16* s1, const char* s2)
 { {
     Uint16 c1;     Uint16 c1;
Line 285 
Line 248 
  
     return c1 - c2;     return c1 - c2;
 } }
   #endif
  
 static inline void _copy(Uint16* s1, const Uint16* s2, size_t n) static inline void _copy(Uint16* s1, const Uint16* s2, size_t n)
 { {
Line 312 
Line 276 
     throw Exception(parms);     throw Exception(parms);
 } }
  
 static size_t _copyFromUTF8(  
     Uint16* dest,  
     const char* src,  
     size_t n,  
     size_t& utf8_error_index)  
 {  
     Uint16* p = dest;  
     const Uint8* q = (const Uint8*)src;  
   
     // Process leading 7-bit ASCII characters (to avoid UTF8 overhead later).  
     // Use loop-unrolling.  
   
     while (n >=8 && ((q[0]|q[1]|q[2]|q[3]|q[4]|q[5]|q[6]|q[7]) & 0x80) == 0)  
     {  
         p[0] = q[0];  
         p[1] = q[1];  
         p[2] = q[2];  
         p[3] = q[3];  
         p[4] = q[4];  
         p[5] = q[5];  
         p[6] = q[6];  
         p[7] = q[7];  
         p += 8;  
         q += 8;  
         n -= 8;  
     }  
   
     while (n >=4 && ((q[0]|q[1]|q[2]|q[3]) & 0x80) == 0)  
     {  
         p[0] = q[0];  
         p[1] = q[1];  
         p[2] = q[2];  
         p[3] = q[3];  
         p += 4;  
         q += 4;  
         n -= 4;  
     }  
   
     switch (n)  
     {  
         case 0:  
             return p - dest;  
         case 1:  
             if (q[0] < 128)  
             {  
                 p[0] = q[0];  
                 return p + 1 - dest;  
             }  
             break;  
         case 2:  
             if (((q[0]|q[1]) & 0x80) == 0)  
             {  
                 p[0] = q[0];  
                 p[1] = q[1];  
                 return p + 2 - dest;  
             }  
             break;  
         case 3:  
             if (((q[0]|q[1]|q[2]) & 0x80) == 0)  
             {  
                 p[0] = q[0];  
                 p[1] = q[1];  
                 p[2] = q[2];  
                 return p + 3 - dest;  
             }  
             break;  
     }  
   
     // Process remaining characters.  
   
     while (n)  
     {  
         // Optimize for 7-bit ASCII case.  
   
         if (*q < 128)  
         {  
             *p++ = *q++;  
             n--;  
         }  
         else  
         {  
             Uint8 c = UTF_8_COUNT_TRAIL_BYTES(*q) + 1;  
   
             if (c > n || !isValid_U8(q, c) ||  
                 UTF8toUTF16(&q, q + c, &p, p + n) != 0)  
             {  
                 utf8_error_index = q - (const Uint8*)src;  
                 return size_t(-1);  
             }  
   
             n -= c;  
         }  
     }  
   
     return p - dest;  
 }  
   
 // Note: dest must be at least three times src (plus an extra byte for // Note: dest must be at least three times src (plus an extra byte for
 // terminator). // terminator).
 static inline size_t _copyToUTF8(char* dest, const Uint16* src, size_t n) static inline size_t _copyToUTF8(char* dest, const Uint16* src, size_t n)
Line 467 
Line 334 
     return p - (Uint8*)dest;     return p - (Uint8*)dest;
 } }
  
 static inline size_t _convert(  
     Uint16* p, const char* q, size_t n, size_t& utf8_error_index)  
 {  
 #ifdef PEGASUS_STRING_NO_UTF8  
     _copy(p, q, n);  
     return n;  
 #else  
     return _copyFromUTF8(p, q, n, utf8_error_index);  
 #endif  
 }  
   
 //============================================================================== //==============================================================================
 // //
 // class CString // class CString
Line 1330 
Line 1186 
         StringRep* rep;         StringRep* rep;
     };     };
  
     StringLayout* that = (StringLayout*)&s;      StringLayout* that = reinterpret_cast<StringLayout*>(&s);
  
     _checkNullPointer(str);     _checkNullPointer(str);
  


Legend:
Removed from v.1.129.2.1  
changed lines
  Added in v.1.135.4.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2