VirtualBox

Changeset 26481 in vbox for trunk/include


Ignore:
Timestamp:
Feb 14, 2010 1:00:49 AM (15 years ago)
Author:
vboxsync
Message:

IPRT: Added RTStrAAppend, RTStrAAppendN, RTStrAAppendExN[V]{,1}, RTStrAlloc, RTStrAllocEx and RTStrRealloc. Fixed bug in RTStrDupN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r25014 r26481  
    181181
    182182/**
     183 * Appends a string onto an existing IPRT allocated string.
     184 *
     185 * @retval  VINF_SUCCESS
     186 * @retval  VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
     187 *          remains unchanged.
     188 *
     189 * @param   ppsz                Pointer to the string pointer.  The string
     190 *                              pointer must either be NULL or point to a string
     191 *                              returned by an IPRT string API.  (In/Out)
     192 * @param   pszAppend           The string to append.  NULL and empty strings
     193 *                              are quietly ignored.
     194 */
     195RTDECL(int) RTStrAAppend(char **ppsz, const char *pszAppend);
     196
     197/**
     198 * Appends N bytes from a strings onto an existing IPRT allocated string.
     199 *
     200 * @retval  VINF_SUCCESS
     201 * @retval  VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
     202 *          remains unchanged.
     203 *
     204 * @param   ppsz                Pointer to the string pointer.  The string
     205 *                              pointer must either be NULL or point to a string
     206 *                              returned by an IPRT string API.  (In/Out)
     207 * @param   pszAppend           The string to append.  Can be NULL if cchAppend
     208 *                              is NULL.
     209 * @param   cchAppend           The number of chars (not code points) to append
     210 *                              from pszAppend.   Must not be more than
     211 *                              @a pszAppend contains, except for the special
     212 *                              value RTSTR_MAX that can be used to indicate all
     213 *                              of @a pszAppend without having to strlen it.
     214 */
     215RTDECL(int) RTStrAAppendN(char **ppsz, const char *pszAppend, size_t cchAppend);
     216
     217/**
     218 * Appends one or more strings onto an existing IPRT allocated string.
     219 *
     220 * This is a very flexible and efficient alternative to using RTStrAPrintf to
     221 * combine several strings together.
     222 *
     223 * @retval  VINF_SUCCESS
     224 * @retval  VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
     225 *          remains unchanged.
     226 *
     227 * @param   ppsz                Pointer to the string pointer.  The string
     228 *                              pointer must either be NULL or point to a string
     229 *                              returned by an IPRT string API.  (In/Out)
     230 * @param   cPairs              The number of string / length pairs in the
     231 *                              @a va.
     232 * @param   va                  List of string (const char *) and length
     233 *                              (size_t) pairs.  The strings will be appended to
     234 *                              the string in the first argument.
     235 */
     236RTDECL(int) RTStrAAppendExNV(char **ppsz, size_t cPairs, va_list va);
     237
     238/**
     239 * Appends one or more strings onto an existing IPRT allocated string.
     240 *
     241 * This is a very flexible and efficient alternative to using RTStrAPrintf to
     242 * combine several strings together.
     243 *
     244 * @retval  VINF_SUCCESS
     245 * @retval  VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
     246 *          remains unchanged.
     247 *
     248 * @param   ppsz                Pointer to the string pointer.  The string
     249 *                              pointer must either be NULL or point to a string
     250 *                              returned by an IPRT string API.  (In/Out)
     251 * @param   cPairs              The number of string / length pairs in the
     252 *                              ellipsis.
     253 * @param   ...                 List of string (const char *) and length
     254 *                              (size_t) pairs.  The strings will be appended to
     255 *                              the string in the first argument.
     256 */
     257RTDECL(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...);
     258
     259/**
     260 * Allocates memory for string storage.
     261 *
     262 * You should normally not use this function, except if there is some very
     263 * custom string handling you need doing that isn't covered by any of the other
     264 * APIs.
     265 *
     266 * @returns Pointer to the allocated string.  The first byte is always set
     267 *          to the string terminator char, the contents of the remainder of the
     268 *          memory is undefined.  The string must be freed by calling RTStrFree.
     269 *
     270 *          NULL is returned if the allocation failed.  Please translate this to
     271 *          VERR_NO_STR_MEMORY and not VERR_NO_MEMORY.  Also consider
     272 *          RTStrAllocEx if an IPRT status code is required.
     273 *
     274 * @param   cb                  How many bytes to allocate.  If this is zero, we
     275 *                              will allocate a terminator byte anyway.
     276 */
     277RTDECL(char *) RTStrAlloc(size_t cb);
     278
     279/**
     280 * Allocates memory for string storage, with status code.
     281 *
     282 * You should normally not use this function, except if there is some very
     283 * custom string handling you need doing that isn't covered by any of the other
     284 * APIs.
     285 *
     286 * @retval  VINF_SUCCESS
     287 * @retval  VERR_NO_STR_MEMORY
     288 *
     289 * @param   ppsz                Where to return the allocated string.  This will
     290 *                              be set to NULL on failure.  On success, the
     291 *                              returned memory will always start with a
     292 *                              terminator char so that it is considered a valid
     293 *                              C string, the contents of rest of the memory is
     294 *                              undefined.
     295 * @param   cb                  How many bytes to allocate.  If this is zero, we
     296 *                              will allocate a terminator byte anyway.
     297 */
     298RTDECL(int) RTStrAllocEx(char **ppsz, size_t cb);
     299
     300/**
     301 * Reallocates the specifed string.
     302 *
     303 * You should normally not have use this function, except perhaps to truncate a
     304 * really long string you've got from some IPRT string API.
     305 *
     306 * @returns VINF_SUCCESS.
     307 * @retval  VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
     308 *          remains unchanged.
     309 *
     310 * @param   ppsz                Pointer to the string variable containing the
     311 *                              input and output string.
     312 *
     313 *                              When not freeing the string, the result will
     314 *                              always have the last byte set to the terminator
     315 *                              character so that when used for string
     316 *                              truncation the result will be a valid C string
     317 *                              (your job to keep it a valid UTF-8 string).
     318 *
     319 *                              When the input string is NULL and we're supposed
     320 *                              to reallocate, the returned string will also
     321 *                              have the first byte set to the terminator char
     322 *                              so it will be a valid C string.
     323 *
     324 * @param   cbNew               When @a cbNew is zero, we'll behave like
     325 *                              RTStrFree and @a *ppsz will be set to NULL.
     326 *
     327 *                              When not zero, this will be the new size of the
     328 *                              memory backing the string, i.e. it includes the
     329 *                              terminator char.
     330 */
     331RTDECL(int) RTStrRealloc(char **ppsz, size_t cbNew);
     332
     333/**
    183334 * Validates the UTF-8 encoding of the string.
    184335 *
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette