strextra.h File Reference

String manipulation APIs. More...


Functions

char * strdupf (const char *fmt,...)
 Produces output into a dynamically-allocated character string buffer according to a format specification string and an appropriate number of arguments.
char * strcombine (char *basestr, char *appendstr, int free_args)
 Appends a string to a base string, freeing the appended string, if requested.
char * strndup (const char *str, size_t count)
 Allocates sufficient memory for a copy of a string, up to the maximum number of characters specified.
char * strlower (char *str, int inplace)
 Converts a string to lower case.
char * strupper (char *str, int inplace)
 Converts a strng to upper case.
char * strsep_quoted (char **search_string, const char *delimiter, const char *quotes)
 Identical to strsep(3), but takes care of quoted segments.
char * strsep_escaped (register char **stringp, register const char *delim)
 An escaped version of strsep(3).
size_t snprintf_safe (char *out, size_t outsize, const char *fmt,...)
 Safe form of snprintf(3) that returns the number of characters written, rather than the number of characters that would have been written.
char * snstrprintable (char *outbuf, size_t outlen, const char *buf, size_t len)
 Converts string buffer to printable form.
static char * strprintable (const char *buf, size_t len)
 Converts string buffer to printable form.
static char * stroffset (char *big, const char *little)
 Given a string and a substring, finds the next character after the substring in the string.
static int streq (const char *red, const char *blue)
 Given two strings, return true if they are the same.


Detailed Description

String manipulation APIs.


Function Documentation

size_t snprintf_safe char *  out,
size_t  outsize,
const char *  fmt,
  ...
 

Safe form of snprintf(3) that returns the number of characters written, rather than the number of characters that would have been written.

Parameters:
[out] out Pointer to the output buffer
[in] outsize Size of the output buffer, in bytes
[in] fmt Format string (see sprintf(3) for a description of the format)
[in] ... Arguments sufficient to satisfy the format string
Returns:
The number of characters written to the output buffer.

char* snstrprintable char *  outbuf,
size_t  outlen,
const char *  buf,
size_t  len
 

Converts string buffer to printable form.

The result will be placed in outbuf and returned.

Parameters:
[out] outbuf Pointer to the output buffer
[out] outlen Size of the output buffer, in bytes
[in] buf Pointer to the string buffer
[in] len Number of characters in the string buffer
Returns:
A pointer to the output buffer on success, NULL on error (errno will be set accordingly.)

char* strcombine char *  basestr,
char *  appendstr,
int  free_args
 

Appends a string to a base string, freeing the appended string, if requested.

If free_args is non-zero, appendstr is freed. Otherwise, it's not. If the memory space pointed by basestr is sufficient for both basestr and appendstr, no new memory allocated and basestr is returned. Otherwise, a new memory is allocaged. If that is successful, the address of new memory is returned and baseptr is freed. Otherwise, NULL is returned and baseptr is not freed.

Parameters:
[in] basestr Base string to append to, it has to point to allocated memory if the current memory space is not sufficent for both basestr and appendstr.
[in] appendstr String to be appended to basestr
[in] free_args Indicator as to whether or not the arguments are allowed to be freed.
Returns:
The combined string on success, NULL on failure.

char* strdupf const char *  fmt,
  ...
 

Produces output into a dynamically-allocated character string buffer according to a format specification string and an appropriate number of arguments.

Parameters:
[in] fmt Format string (see sprintf(3) for a description of the format)
[in] ... Arguments sufficient to satisfy the format string
Returns:
A pointer to the resultant string.

static int streq const char *  red,
const char *  blue
[inline, static]
 

Given two strings, return true if they are the same.

Tests the first characters for equality before calling strcmp.

Parameters:
[in] red,blue The strings to be compared
Returns:
Nonzero (true) if the strings are the same.

char* strlower char *  str,
int  inplace
 

Converts a string to lower case.

Parameters:
[in] str String to convert to lower case.
[in] inplace If 0, allocate space for the lower case string. Otherwise, do the conversion in-place.
Returns:
The string in lower case form. If inplace is 0, this string is dynamically-allocated and should be used as an argument to the function free(3) when no longer neeeded.
See also:
strupper()

char* strndup const char *  str,
size_t  count
 

Allocates sufficient memory for a copy of a string, up to the maximum number of characters specified.

Parameters:
[in] str String to duplicate
[in] count Maximum number of characters to copy
Returns:
A duplicate string of up to count characters of str.

static char* stroffset char *  big,
const char *  little
[inline, static]
 

Given a string and a substring, finds the next character after the substring in the string.

Example: stroffset("the fox ran", "fox ") => "ran"

Parameters:
[in] big String to search
[in] little Substring to match
Returns:
A pointer to the first character after the substring little as found in big, NULL otherwise

static char* strprintable const char *  buf,
size_t  len
[inline, static]
 

Converts string buffer to printable form.

Parameters:
[in] buf Pointer to the string buffer
[in] len Number of characters in the string buffer
Returns:
A pointer to the converted string on success, NULL on error (errno will be set accordingly.)

char* strsep_escaped register char **  stringp,
register const char *  delim
 

An escaped version of strsep(3).

This function locates the first occurrence of any character in the delimiter string. It allows for characters in delim to be escaped in the target string. For example, if delim is set to "xyz", the characters x, y, and z would be ignored when parsing the string "abcd...\x\y\z", but not when parsing the string "abcd...xyz".

Parameters:
[in,out] stringp Pointer to string to search. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) will be stored in the location pointed to by this variable upon return.
[in] delim Delimiters. A string containing the characters to search for in stringp.
Returns:
The original value of *stringp. NULL if *stringp is NULL.

char* strsep_quoted char **  search_string,
const char *  delimiter,
const char *  quotes
 

Identical to strsep(3), but takes care of quoted segments.

Quoted segments of the string are skipped when searching for a delimiter. A quoted segment is enclosed in a pair of one of the characters given in the quotes string.

Parameters:
[in,out] search_string Pointer to the string to search
[in] delimiter Characters to use as delimiters
[in] quotes Characters to use as 'quotes'
Returns:
The location of the next character after the delimiter; NULL if the end of search_string is reached; If *search_string is NULL, strsep_quoted returns NULL.

char* strupper char *  str,
int  inplace
 

Converts a strng to upper case.

Parameters:
[in] str String to convert to upper case.
[in] inplace If 0, allocate space for the upper case string. Otherwise, do the conversion in-place.
Returns:
The string in upper case form. If inplace is 0, this string is dynamically-allocated and should be used as an argument to the function free(3) when no longer neeeded.
See also:
strlower()


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:24:32 2010 for libjuniper by Doxygen 1.4.5