(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.138.2.1 and 1.138.2.2

version 1.138.2.1, 2013/06/03 22:35:13 version 1.138.2.2, 2014/06/14 22:08:13
Line 34 
Line 34 
 #include "InternalException.h" #include "InternalException.h"
 #include "MessageLoader.h" #include "MessageLoader.h"
 #include "StringRep.h" #include "StringRep.h"
   #include <Pegasus/Common/Pegasus_inl.h>
   #include <cstdarg>
  
 #ifdef PEGASUS_HAS_ICU #ifdef PEGASUS_HAS_ICU
 # include <unicode/ures.h> # include <unicode/ures.h>
Line 380 
Line 382 
     return p - (Uint8*)dest;     return p - (Uint8*)dest;
 } }
  
   //  Function to return a formatted char*  from a va_list.
   //  Allocates space for the returned char* and repeats the
   //  build process until the allocated space is large enough
   //  to hold the result.  This is internal only and the core function
   //  used by stringPrintf and stringVPrintf
   
   static char* _charVPrintf(const char* format, va_list ap)
   {
       // Iniitial allocation size.  This is a guess assuming that
       // most printfs are one or two lines long
       int allocSize = 256;
   
       int rtnSize;
       char *p;
   
       // initial allocate for output
       if ((p = (char*)malloc(allocSize)) == NULL)
       {
           return 0;
       }
   
       // repeat formatting  with increased realloc until it works.
       do
       {
           rtnSize = vsnprintf(p, allocSize, format, ap);
   
           // return if successful if not negative and
           // returns less than allocated size.
           if (rtnSize > -1 && rtnSize < allocSize)
           {
               return p;
           }
   
           // increment alloc size. Assumes that positive return is
           // expected size and negative is error.
           allocSize = (rtnSize > -1)? (rtnSize + 1) : allocSize * 2;
   
       } while((p = (char*)peg_inln_realloc(p, allocSize)) != NULL);
   
       // return error code if realloc failed
       return 0;
   }
   
 //============================================================================== //==============================================================================
 // //
 // class CString // class CString
Line 1141 
Line 1186 
                 s1._rep->size * sizeof(Uint16)) == 0);                 s1._rep->size * sizeof(Uint16)) == 0);
 } }
  
   void String::appendPrintf(const char* format, ...)
   {
       va_list ap;
       va_start(ap, format);
   
       // Format into allocated memory
       ////char* rtnCharPtr = _charVPrintf(format, ap);
   
       // Iniitial allocation size.  This is a guess assuming that
       // most printfs are one or two lines long
       int allocSize = 256;
       int rtnSize;
       char *p;
   
       // initial allocate for output
       if ((p = (char*)malloc(allocSize)) == NULL)
       {
           return;
       }
   
       // repeat formatting  with increased realloc until it works.
       do
       {
           rtnSize = vsnprintf(p, allocSize, format, ap);
   
           // return if successful; i.e. if not negative and
           // returns less than allocated size.
           if (rtnSize > -1 && rtnSize < allocSize)
           {
               break;
           }
   
           // increment alloc size. Positive return is
           // expected size and negative is error.
           allocSize = (rtnSize > -1)? (rtnSize + 1) : allocSize * 2;
   
       } while((p = (char*)peg_inln_realloc(p, allocSize)) != NULL);
   
       // get here only with error in malloc.
   
       va_end(ap);
   
       // Free allocated memory append printf output to current string
       append(p, rtnSize);
       free(p);
   }
   
 Boolean String::equal(const String& s1, const char* s2) Boolean String::equal(const String& s1, const char* s2)
 { {
 #ifdef PEGASUS_STRING_NO_UTF8 #ifdef PEGASUS_STRING_NO_UTF8


Legend:
Removed from v.1.138.2.1  
changed lines
  Added in v.1.138.2.2

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2