Some string routines for naev.
More...
#include "nstring.h"
#include "log.h"
Go to the source code of this file.
|
| char * | strnstr (const char *haystack, const char *needle, size_t size) |
| | A bounded version of strstr. Conforms to BSD semantics. More...
|
| |
| char * | strcasestr (const char *haystack, const char *needle) |
| | Finds a string inside another string case insensitively. More...
|
| |
| char * | strndup (const char *s, size_t n) |
| | Return a pointer to a new string, which is a duplicate of the string s (or, if necessary, which contains the first nn bytes of s plus a terminating null). More...
|
| |
| int | strsort (const void *p1, const void *p2) |
| | Sort function for sorting strings with qsort(). More...
|
| |
| int | strsort_reverse (const void *p1, const void *p2) |
| | Order-reversed version of strsort(). More...
|
| |
| int | vasprintf (char **strp, const char *fmt, va_list ap) |
| | Like vsprintf(), but it allocates a large-enough string and returns the pointer in the first argument. Conforms to GNU and BSD libc semantics. More...
|
| |
| int | asprintf (char **strp, const char *fmt,...) |
| | Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument. Conforms to GNU and BSD libc semantics. More...
|
| |
| int | scnprintf (char *text, size_t maxlen, const char *fmt,...) |
| | Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer. This makes it possible to chain these calls to concatenate into a buffer without introducing a potential bug every time. This call was first added to the Linux kernel by Juergen Quade. More...
|
| |
| int | num2str (char dest[NUM2STRLEN], double n, int decimals) |
| | Converts an electronic warfare value to a string. More...
|
| |
| const char * | num2strU (double n, int decimals) |
| | Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value. More...
|
| |
Some string routines for naev.
Definition in file nstring.c.
◆ asprintf()
| int asprintf |
( |
char ** |
strp, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument. Conforms to GNU and BSD libc semantics.
- Parameters
-
| [out] | strp | Used to return the allocated char* in case of success. Caller must free. In case of failure, *strp is set to NULL, but don't rely on this because the GNU version doesn't guarantee it. |
| fmt | Same as sprintf(). |
- Returns
- -1 if it failed, otherwise the number of bytes "printed".
Definition at line 161 of file nstring.c.
◆ num2str()
| int num2str |
( |
char |
dest[NUM2STRLEN], |
|
|
double |
n, |
|
|
int |
decimals |
|
) |
| |
Converts an electronic warfare value to a string.
- Parameters
-
| [out] | dest | String to write to. |
| n | Number to write. |
| decimals | Number of decimals to write. |
Definition at line 199 of file nstring.c.
◆ num2strU()
| const char * num2strU |
( |
double |
n, |
|
|
int |
decimals |
|
) |
| |
Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
- Parameters
-
| n | Number to write. |
| decimals | Number of decimals to write. |
- Returns
- Fancy string number.
Definition at line 230 of file nstring.c.
◆ scnprintf()
| int scnprintf |
( |
char * |
text, |
|
|
size_t |
maxlen, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer. This makes it possible to chain these calls to concatenate into a buffer without introducing a potential bug every time. This call was first added to the Linux kernel by Juergen Quade.
Definition at line 178 of file nstring.c.
◆ strcasestr()
| char * strcasestr |
( |
const char * |
haystack, |
|
|
const char * |
needle |
|
) |
| |
Finds a string inside another string case insensitively.
- Parameters
-
| haystack | String to look into. |
| needle | String to find. |
- Returns
- Pointer in haystack where needle was found or NULL if not found.
Definition at line 68 of file nstring.c.
◆ strndup()
| char * strndup |
( |
const char * |
s, |
|
|
size_t |
n |
|
) |
| |
Return a pointer to a new string, which is a duplicate of the string s (or, if necessary, which contains the first nn bytes of s plus a terminating null).
Taken from glibc. Conforms to POSIX.1-2008.
Definition at line 94 of file nstring.c.
◆ strnstr()
| char * strnstr |
( |
const char * |
haystack, |
|
|
const char * |
needle, |
|
|
size_t |
size |
|
) |
| |
A bounded version of strstr. Conforms to BSD semantics.
- Parameters
-
| haystack | The string to search in |
| size | The size of haystack |
| needle | The string to search for |
- Returns
- A pointer to the first occurrence of needle in haystack, or NULL
Definition at line 26 of file nstring.c.
◆ strsort()
| int strsort |
( |
const void * |
p1, |
|
|
const void * |
p2 |
|
) |
| |
Sort function for sorting strings with qsort().
Definition at line 108 of file nstring.c.
◆ strsort_reverse()
| int strsort_reverse |
( |
const void * |
p1, |
|
|
const void * |
p2 |
|
) |
| |
◆ vasprintf()
| int vasprintf |
( |
char ** |
strp, |
|
|
const char * |
fmt, |
|
|
va_list |
ap |
|
) |
| |
Like vsprintf(), but it allocates a large-enough string and returns the pointer in the first argument. Conforms to GNU and BSD libc semantics.
- Parameters
-
| [out] | strp | Used to return the allocated char* in case of success. Caller must free. In case of failure, *strp is set to NULL, but don't rely on this because the GNU version doesn't guarantee it. |
| fmt | Same as vsprintf(). |
| ap | Same as vsprintf(). |
- Returns
- -1 if it failed, otherwise the number of bytes "printed".
Definition at line 132 of file nstring.c.