(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.111.6.15 and 1.116.2.1

version 1.111.6.15, 2005/10/14 14:09:29 version 1.116.2.1, 2006/02/10 16:09:38
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // 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 32 
Line 34 
 // Modified By: // Modified By:
 //     Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) //     Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 //     Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3297 //     Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3297
 //     David Dillard, VERITAS Software Corp. (david.dillard@veritas.com)  //     David Dillard, Symantec Corp. (david_dillard@symantec.com)
 //     Mike Brasher (mike-brasher@austin.rr.com) //     Mike Brasher (mike-brasher@austin.rr.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <cassert>  #include <Pegasus/Common/PegasusAssert.h>
   #include <cstring>
 #include "InternalException.h" #include "InternalException.h"
 #include "CommonUTF.h" #include "CommonUTF.h"
 #include "MessageLoader.h" #include "MessageLoader.h"
Line 297 
Line 300 
     return c1 - c2;     return c1 - c2;
 } }
  
 static int _compare(const Uint16* s1, const Uint16* s2, size_t n)  
 {  
     // This should only be called when s1 and s2 have the same length.  
   
     while (n-- && (*s1++ - *s2++) == 0)  
         ;  
   
     return s1[-1] - s2[-1];  
 }  
   
 static inline void _copy(Uint16* s1, const Uint16* s2, size_t n) static inline void _copy(Uint16* s1, const Uint16* s2, size_t n)
 { {
     memcpy(s1, s2, n * sizeof(Uint16));     memcpy(s1, s2, n * sizeof(Uint16));
Line 319 
Line 312 
  
 inline void _checkNullPointer(const void* ptr) inline void _checkNullPointer(const void* ptr)
 { {
 #ifdef PEGASUS_STRING_NO_THROW  #ifndef PEGASUS_STRING_NO_THROW
  
     if (!ptr)     if (!ptr)
         throw NullPointer();         throw NullPointer();
Line 568 
Line 561 
  
 static inline void _reserve(StringRep*& rep, Uint32 cap) static inline void _reserve(StringRep*& rep, Uint32 cap)
 { {
     if (cap > rep->cap || rep->refs.value() != 1)      if (cap > rep->cap || rep->refs.get() != 1)
     {     {
         size_t n = _roundUpToPow2(cap);         size_t n = _roundUpToPow2(cap);
         StringRep* newRep = StringRep::alloc(n);         StringRep* newRep = StringRep::alloc(n);
Line 748 
Line 741 
 { {
     _checkNullPointer(str);     _checkNullPointer(str);
  
     if (n > _rep->cap || _rep->refs.value() != 1)      if (n > _rep->cap || _rep->refs.get() != 1)
     {     {
         StringRep::unref(_rep);         StringRep::unref(_rep);
         _rep = StringRep::alloc(n);         _rep = StringRep::alloc(n);
Line 765 
Line 758 
 { {
     _checkNullPointer(str);     _checkNullPointer(str);
  
     if (n > _rep->cap || _rep->refs.value() != 1)      if (n > _rep->cap || _rep->refs.get() != 1)
     {     {
         StringRep::unref(_rep);         StringRep::unref(_rep);
         _rep = StringRep::alloc(n);         _rep = StringRep::alloc(n);
Line 792 
Line 785 
 { {
     if (_rep->size)     if (_rep->size)
     {     {
         if (_rep->refs.value() == 1)          if (_rep->refs.get() == 1)
         {         {
             _rep->size = 0;             _rep->size = 0;
             _rep->data[0] = '\0';             _rep->data[0] = '\0';
Line 887 
Line 880 
  
     _checkBounds(index + n, _rep->size);     _checkBounds(index + n, _rep->size);
  
     if (_rep->refs.value() != 1)      if (_rep->refs.get() != 1)
         _rep = StringRep::copyOnWrite(_rep);         _rep = StringRep::copyOnWrite(_rep);
  
     assert(index + n <= _rep->size);      PEGASUS_ASSERT(index + n <= _rep->size);
  
     size_t rem = _rep->size - (index + n);     size_t rem = _rep->size - (index + n);
     Uint16* data = _rep->data;     Uint16* data = _rep->data;
Line 923 
Line 916 
     Uint16* p = (Uint16*)_find(_rep->data, _rep->size, c);     Uint16* p = (Uint16*)_find(_rep->data, _rep->size, c);
  
     if (p)     if (p)
         return p - _rep->data;          return static_cast<Uint32>(p - _rep->data);
  
     return PEG_NOT_FOUND;     return PEG_NOT_FOUND;
 } }
Line 938 
Line 931 
     Uint16* p = (Uint16*)_find(_rep->data + index, _rep->size - index, c);     Uint16* p = (Uint16*)_find(_rep->data + index, _rep->size - index, c);
  
     if (p)     if (p)
         return p - _rep->data;          return static_cast<Uint32>(p - _rep->data);
  
     return PEG_NOT_FOUND;     return PEG_NOT_FOUND;
 } }
Line 959 
Line 952 
             break;             break;
  
         if (memcmp(p, s, n * sizeof(Uint16)) == 0)         if (memcmp(p, s, n * sizeof(Uint16)) == 0)
             return p - _rep->data;              return static_cast<Uint32>(p - _rep->data);
  
         p++;         p++;
         rem -= p - data;         rem -= p - data;
Line 987 
Line 980 
     while (q != p)     while (q != p)
     {     {
         if (*--q == x)         if (*--q == x)
             return q - p;              return static_cast<Uint32>(q - p);
     }     }
  
     return PEG_NOT_FOUND;     return PEG_NOT_FOUND;
Line 999 
Line 992 
  
     if (InitializeICU::initICUSuccessful())     if (InitializeICU::initICUSuccessful())
     {     {
         if (_rep->refs.value() != 1)          if (_rep->refs.get() != 1)
             _rep = StringRep::copyOnWrite(_rep);             _rep = StringRep::copyOnWrite(_rep);
  
         // This will do a locale-insensitive, but context-sensitive convert.         // This will do a locale-insensitive, but context-sensitive convert.
Line 1034 
Line 1027 
  
 #endif /* PEGASUS_HAS_ICU */ #endif /* PEGASUS_HAS_ICU */
  
     if (_rep->refs.value() != 1)      if (_rep->refs.get() != 1)
         _rep = StringRep::copyOnWrite(_rep);         _rep = StringRep::copyOnWrite(_rep);
  
     Uint16* p = _rep->data;     Uint16* p = _rep->data;
Line 1053 
Line 1046 
  
     if (InitializeICU::initICUSuccessful())     if (InitializeICU::initICUSuccessful())
     {     {
         if (_rep->refs.value() != 1)          if (_rep->refs.get() != 1)
             _rep = StringRep::copyOnWrite(_rep);             _rep = StringRep::copyOnWrite(_rep);
  
         // This will do a locale-insensitive, but context-sensitive convert.         // This will do a locale-insensitive, but context-sensitive convert.
Line 1089 
Line 1082 
  
 #endif /* PEGASUS_HAS_ICU */ #endif /* PEGASUS_HAS_ICU */
  
     if (_rep->refs.value() != 1)      if (_rep->refs.get() != 1)
         _rep = StringRep::copyOnWrite(_rep);         _rep = StringRep::copyOnWrite(_rep);
  
     Uint16* p = _rep->data;     Uint16* p = _rep->data;
Line 1101 
Line 1094 
  
 int String::compare(const String& s1, const String& s2, Uint32 n) int String::compare(const String& s1, const String& s2, Uint32 n)
 { {
     assert(n <= s1._rep->size);      const Uint16* p1 = s1._rep->data;
     assert(n <= s2._rep->size);      const Uint16* p2 = s2._rep->data;
  
     // Ignoring error in which n is greater than s1.size() or s2.size()      while (n--)
     return _compare(s1._rep->data, s2._rep->data, n);      {
           int r = *p1++ - *p2++;
           if (r)
           {
               return r;
           }
           else if (!p1[-1])
           {
               // We must have encountered a null terminator in both s1 and s2
               return 0;
           }
       }
       return 0;
 } }
  
 int String::compare(const String& s1, const String& s2) int String::compare(const String& s1, const String& s2)
Line 1515 
Line 1520 
  
     (+) [DONE] Look at PEP223 for coding security guidelines.     (+) [DONE] Look at PEP223 for coding security guidelines.
  
     (+) [DONE] Use old AtomicInt for now (split new AtomicInt into another      (+) [DONE] Use old AtomicInt for now (new AtomicInt part of bug #4250).
         bug.  
  
     (+) [DONE] Removed appendASCII() and the ASCII form of the constructor.     (+) [DONE] Removed appendASCII() and the ASCII form of the constructor.
  
     -----------      (+) DOC++ String.h - will open new bug?
  
     (+) DOC++ String.h      (+) Added PEGASUS_DISABLE_INTERNAL_INLINES macro (to permit suppression
           on certain platforms).
  
 ================================================================================ ================================================================================
 */ */


Legend:
Removed from v.1.111.6.15  
changed lines
  Added in v.1.116.2.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2