ministring.cpp revision 5ff36a93b0416312ccf2ed0f05043fdd030d2100
/* $Id$ */
/** @file
* IPRT - Mini C++ string class.
*
* This is a base for both Utf8Str and other places where IPRT may want to use
* a lean C++ string class.
*/
/*
* Copyright (C) 2007-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Allocation block alignment used when appending bytes to a string. */
#define IPRT_MINISTRING_APPEND_ALIGNMENT 64
{
return *this;
}
/**
* Callback used with RTStrFormatV by RTCString::printfV.
*
* @returns The number of bytes added (not used).
*
* @param pvArg The string object.
* @param pachChars The characters to append.
* @param cbChars The number of characters. 0 on the final callback.
*/
{
if (cbChars)
{
{
/* Double the buffer size, if it's less that _4M. Align sizes like
for append. */
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
}
return cbChars;
}
{
cleanup();
return *this;
}
{
if (cchThat)
{
if (cchBoth >= m_cbAllocated)
{
// calls realloc(cchBoth + 1) and sets m_cbAllocated; may throw bad_alloc.
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
}
return *this;
}
{
if (cchThat)
{
if (cchBoth >= m_cbAllocated)
{
// calls realloc(cchBoth + 1) and sets m_cbAllocated; may throw bad_alloc.
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
}
return *this;
}
{
if (ch)
{
// allocate in chunks of 20 in case this gets called several times
{
// calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc.
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
}
return *this;
}
{
/*
* Single byte encoding.
*/
if (uc < 0x80)
/*
* Multibyte encoding.
* Assume max encoding length when resizing the string, that's simpler.
*/
{
// calls realloc(cbBoth) and sets m_cbAllocated; may throw bad_alloc.
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
*pszNext = '\0';
return *this;
}
{
const char *pszThis, *p;
)
return p - pszThis;
return npos;
}
{
{
char *p = &m_psz[i];
if (*p == cFind)
*p = cReplace;
}
}
{
if (n)
{
const char *psz;
{
// walk the UTF-8 characters until where the caller wants to start
while (*psz && i--)
return ret; // return empty string on bad encoding
if (n == npos)
// all the rest:
else
{
i = n;
while (*psz && i--)
return ret; // return empty string on bad encoding
if (cbCopy)
{
#ifndef RT_EXCEPTIONS_ENABLED
#endif
}
}
}
}
return ret;
}
{
if (l1 == 0)
return false;
return false;
/** @todo r=bird: If l2 is 0, then m_psz can be NULL and we will crash. See
* also handling of l2 == in startsWith. */
if (cs == CaseSensitive)
}
{
if (l1 == 0 || l2 == 0) /** @todo r=bird: this differs from endsWith, and I think other IPRT code. If l2 == 0, it matches anything. */
return false;
return false;
if (cs == CaseSensitive)
}
{
/** @todo r-bird: Not checking for NULL strings like startsWith does (and
* endsWith only does half way). */
if (cs == CaseSensitive)
}
{
if (!m_psz)
return VERR_NO_DIGITS;
}
{
if (!m_psz)
return VERR_NO_DIGITS;
}
{
if (!m_psz)
return strRet;
{
return strRet;
}
while (cch > 0)
{
if (!pszNext)
{
break;
}
if ( cchNext > 0
|| mode == KeepEmptyParts)
}
return strRet;
}
/* static */
{
{
/* calc the required size */
/* do the appending. */
{
}
}
/* special case: one list item. */
return strRet;
}
{
return strRet;
}
{
return strRet;
}
{
return strRet;
}