third_party/tinyxml/tinystr.cpp
void TiXmlString::append( const char* str, size_t len )
{
    char * new_string;
    size_t new_alloc, new_size, size_suffix;
	
	// don't use strlen - it can overrun the len passed in!
	const char* p = str;
	size_suffix = 0;

	while ( *p && size_suffix < (unsigned)len )
	{
		++p;
		++size_suffix;
	}
    if ( !size_suffix)
        return;

    new_size = length () + size_suffix + 1;
    // check if we need to expand
    if (new_size > allocated)
    {
        // compute new size
        new_alloc = assign_new_size (new_size);

        // allocate new buffer
        new_string = new char [new_alloc];        
        new_string [0] = 0;

        // copy the previous allocated buffer into this one
        if (allocated && cstring)
            // strcpy (new_string, cstring);
            memcpy (new_string, cstring, length ());

        // append the suffix. It does exist, otherwize we wouldn't be expanding 
        // strncat (new_string, str, len);
        memcpy (new_string + length (), 
                str,
                size_suffix);

        // return previsously allocated buffer if any
        if (allocated && cstring)
            delete [] cstring;

        // update member variables
        cstring = new_string;
        allocated = new_alloc;
    }
    else
    {
        // we know we can safely append the new string
        // strncat (cstring, str, len);
        memcpy (cstring + length (), 
                str,
                size_suffix);
    }
    current_length = new_size - 1;
    cstring [current_length] = 0;
}
// append a const char * to an existing TiXmlString
append a const char * to an existing TiXmlString
append a const char * to an existing TiXmlString
void TiXmlString::append( const char* str, size_t len )
{
    char * new_string;
    size_t new_alloc, new_size, size_suffix;
	const char* p = str;
	size_suffix = 0;
	while ( *p && size_suffix < (unsigned)len )
	{
		++p;
		++size_suffix;
	}
    if ( !size_suffix)
        return;
    new_size = length () + size_suffix + 1;
    if (new_size > allocated)
    {
        new_alloc = assign_new_size (new_size);
        new_string = new char [new_alloc];        
        new_string [0] = 0;
        if (allocated && cstring)
            memcpy (new_string, cstring, length ());
        memcpy (new_string + length (), 
                str,
                size_suffix);
        if (allocated && cstring)
            delete [] cstring;
        cstring = new_string;
        allocated = new_alloc;
    }
    else
    {
        memcpy (cstring + length (), 
                str,
                size_suffix);
    }
    current_length = new_size - 1;
    cstring [current_length] = 0;
}
void TiXmlString :: append ( const char * str , size_t len ) { char * new_string ; size_t new_alloc , new_size , size_suffix ; const char * p = str ; size_suffix = 0 ; while ( * p && size_suffix < ( unsigned ) len ) { ++ p ; ++ size_suffix ; } if ( ! size_suffix ) return ; new_size = length ( ) + size_suffix + 1 ; if ( new_size > allocated ) { new_alloc = assign_new_size ( new_size ) ; new_string = new char [ new_alloc ] ; new_string [ 0 ] = 0 ; if ( allocated && cstring ) memcpy ( new_string , cstring , length ( ) ) ; memcpy ( new_string + length ( ) , str , size_suffix ) ; if ( allocated && cstring ) delete [ ] cstring ; cstring = new_string ; allocated = new_alloc ; } else { memcpy ( cstring + length ( ) , str , size_suffix ) ; } current_length = new_size - 1 ; cstring [ current_length ] = 0 ; }
append a const char * to an existing TiXmlString
append a const char * to an existing TiXmlString
// don't use strlen - it can overrun the len passed in! // check if we need to expand // compute new size // allocate new buffer // copy the previous allocated buffer into this one // strcpy (new_string, cstring); // append the suffix. It does exist, otherwize we wouldn't be expanding  // strncat (new_string, str, len); // return previsously allocated buffer if any // update member variables // we know we can safely append the new string // strncat (cstring, str, len);