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.
|
| 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).
|
| int | strsort (const void *p1, const void *p2) |
| | Sort function for sorting strings with qsort().
|
| int | strsort_reverse (const void *p1, const void *p2) |
| | Order-reversed version of strsort().
|
| 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.
|
| int | num2str (char dest[NUM2STRLEN], double n, int decimals) |
| | Converts a numeric value to a string.
|
| const char * | num2strU (double n, int decimals) |
| | Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
|
| void | print_with_line_numbers (const char *str) |
| | Prints to stderr with line numbers.
|
Some string routines for naev.
Definition in file nstring.c.
◆ num2str()
| int num2str |
( |
char | dest[NUM2STRLEN], |
|
|
double | n, |
|
|
int | decimals ) |
Converts a numeric value to a string.
- Parameters
-
| [out] | dest | String to write to. |
| n | Number to write. |
| decimals | Number of decimals to write. |
Definition at line 123 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 163 of file nstring.c.
◆ print_with_line_numbers()
| void print_with_line_numbers |
( |
const char * | str | ) |
|
Prints to stderr with line numbers.
- Parameters
-
Definition at line 175 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 102 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 69 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 83 of file nstring.c.
◆ strsort_reverse()
| int strsort_reverse |
( |
const void * | p1, |
|
|
const void * | p2 ) |