ELinks 0.18.0
conv.h File Reference
#include "util/string.h"
#include "util/time.h"
Include dependency graph for conv.h:

Macros

#define ulongcat(s, slen, number, width, fillchar)
 unsigned long to decimal string
 
#define longcat(s, slen, number, width, fillchar)
 signed long to decimal string
 
#define ulonghexcat(s, slen, number, width, fillchar, upper)
 unsigned long to hexadecimal string
 

Functions

static int is_safe_in_shell (unsigned char c)
 
long strtolx (char *, char **)
 
static unsigned char hx (int a)
 Convert a decimal number to hexadecimal (lowercase) (0 <= a <= 15).
 
static unsigned char Hx (int a)
 Convert a decimal number to hexadecimal (uppercase) (0 <= a <= 15).
 
static int unhx (unsigned char a)
 Convert an hexadecimal char ([0-9][a-z][A-Z]) to its decimal value (0 <= result <= 15).
 
struct stringadd_long_to_string (struct string *string, long long number)
 
struct stringadd_knum_to_string (struct string *string, long long number)
 
struct stringadd_xnum_to_string (struct string *string, long long number)
 
struct stringadd_duration_to_string (struct string *string, long seconds)
 
struct stringadd_timeval_to_string (struct string *string, timeval_T *timeval)
 
int elinks_ulongcat (char *s, unsigned int *slen, unsigned long long number, unsigned int width, unsigned char fillchar, unsigned int base, unsigned int upper)
 This function takes string s and stores the number (of a result width width) in string format there, starting at position [*slen].
 
int elinks_longcat (char *s, unsigned int *slen, long long number, unsigned int width, unsigned char fillchar, unsigned int base, unsigned int upper)
 Similar to elinks_ulongcat() but for long number.
 
int month2num (const char *month)
 Return 0 if starting with jan, 11 for dec, -1 for failure.
 
static char * trim_chars (char *s, unsigned char c, int *len)
 Trim starting and ending chars equal to c in string s.
 
int c_tolower (int c)
 
int c_toupper (int c)
 
int c_islower (int c)
 
int c_isupper (int c)
 
static void convert_to_lowercase (char *string, int length)
 Convert uppercase letters in string with the given length to lowercase.
 
static void convert_to_lowercase_locale_indep (char *string, int length)
 
void clr_spaces (char *str)
 This function drops control chars, nbsp char and limit the number of consecutive space chars to one.
 
void sanitize_title (char *title)
 Replace invalid chars in title with ' ' and trim all starting/ending spaces.
 
int sanitize_url (char *url)
 Returns 0 if url contains invalid chars, 1 if ok.
 

Encoders:

They encode and add to the string.

This way we don't need to first allocate and encode a temporary string, add it and then free it. Can be used as backends for encoder.

struct stringadd_shell_safe_to_string (struct string *string, const char *cmd, int cmdlen)
 

Macro Definition Documentation

◆ longcat

#define longcat ( s,
slen,
number,
width,
fillchar )
Value:
elinks_longcat((char *) (s), \
(unsigned int *) (slen), \
(long long) (number), \
(unsigned int) (width), \
(unsigned char) (fillchar), \
(unsigned int) 10, \
(unsigned int) 0)
int elinks_longcat(char *s, unsigned int *slen, long long number, unsigned int width, unsigned char fillchar, unsigned int base, unsigned int upper)
Similar to elinks_ulongcat() but for long number.
Definition conv.c:110
const char * s
Definition general.c:869

signed long to decimal string

◆ ulongcat

#define ulongcat ( s,
slen,
number,
width,
fillchar )
Value:
elinks_ulongcat((char *) (s), \
(unsigned int *) (slen), \
(unsigned long long) (number), \
(unsigned int) (width), \
(unsigned char) (fillchar), \
(unsigned int) 10, \
(unsigned int) 0)
int elinks_ulongcat(char *s, unsigned int *slen, unsigned long long number, unsigned int width, unsigned char fillchar, unsigned int base, unsigned int upper)
This function takes string s and stores the number (of a result width width) in string format there,...
Definition conv.c:52

unsigned long to decimal string

◆ ulonghexcat

#define ulonghexcat ( s,
slen,
number,
width,
fillchar,
upper )
Value:
elinks_ulongcat((char *) (s), \
(unsigned int *) (slen), \
(unsigned long long) (number), \
(unsigned int) (width), \
(unsigned char) (fillchar), \
(unsigned int) 16, \
(unsigned int) (upper))

unsigned long to hexadecimal string

Function Documentation

◆ add_duration_to_string()

struct string * add_duration_to_string ( struct string * string,
long seconds )
related

◆ add_knum_to_string()

struct string * add_knum_to_string ( struct string * string,
long long number )
related

◆ add_long_to_string()

struct string * add_long_to_string ( struct string * string,
long long number )
related

◆ add_shell_safe_to_string()

struct string * add_shell_safe_to_string ( struct string * string,
const char * cmd,
int cmdlen )

◆ add_timeval_to_string()

struct string * add_timeval_to_string ( struct string * string,
timeval_T * timeval )
related

◆ add_xnum_to_string()

struct string * add_xnum_to_string ( struct string * string,
long long number )
related

◆ c_islower()

int c_islower ( int c)

◆ c_isupper()

int c_isupper ( int c)

◆ c_tolower()

int c_tolower ( int c)

◆ c_toupper()

int c_toupper ( int c)

◆ clr_spaces()

void clr_spaces ( char * str2)

This function drops control chars, nbsp char and limit the number of consecutive space chars to one.

It modifies its argument.

◆ convert_to_lowercase()

static void convert_to_lowercase ( char * string,
int length )
inlinestatic

Convert uppercase letters in string with the given length to lowercase.

◆ convert_to_lowercase_locale_indep()

static void convert_to_lowercase_locale_indep ( char * string,
int length )
inlinestatic

◆ elinks_longcat()

int elinks_longcat ( char * s,
unsigned int * slen,
long long number,
unsigned int width,
unsigned char fillchar,
unsigned int base,
unsigned int upper )

Similar to elinks_ulongcat() but for long number.

◆ elinks_ulongcat()

int elinks_ulongcat ( char * s,
unsigned int * slen,
unsigned long long number,
unsigned int width,
unsigned char fillchar,
unsigned int base,
unsigned int upper )

This function takes string s and stores the number (of a result width width) in string format there, starting at position [*slen].

If the number would take more space than width, it is truncated and only the last digits of it are inserted to the string. If the number takes less space than width, it is padded by fillchar from left. base defined which base should be used (10, 16, 8, 2, ...) upper selects either hexa uppercased chars or lowercased chars.

A NUL char is always added at the end of the string. s must point to a sufficiently large memory space, at least *slen + width + 1.

Examples:

elinks_ulongcat(s, NULL, 12345, 4, 0, 10, 0) : s = "2345"
elinks_ulongcat(s, NULL, 255, 4, '*', 16, 1) : s = "**FF"
elinks_ulongcat(s, NULL, 123, 5, '0', 10, 0) : s = "00123"
NONSTATIC_INLINE int elinks_ulongcat(char *s, unsigned int *slen, unsigned long long number, unsigned int width, unsigned char fillchar, unsigned int base, unsigned int upper)
This function takes string s and stores the number (of a result width width) in string format there,...
Definition conv.c:52
#define NULL
Definition explodename.c:35

Note that this function exists to provide a fast and efficient, however still quite powerful alternative to sprintf(). It is optimized for speed and is MUCH faster than sprintf(). If you can use it, use it ;-). But do not get too enthusiastic, do not use it in cases where it would break i18n.

Returns
0 if OK or width needed for the whole number to fit there, if it had to be truncated. A negative value signs an error.

◆ Hx()

static unsigned char Hx ( int a)
inlinestatic

Convert a decimal number to hexadecimal (uppercase) (0 <= a <= 15).

◆ hx()

static unsigned char hx ( int a)
inlinestatic

Convert a decimal number to hexadecimal (lowercase) (0 <= a <= 15).

◆ is_safe_in_shell()

static int is_safe_in_shell ( unsigned char c)
inlinestatic

◆ month2num()

int month2num ( const char * month)

Return 0 if starting with jan, 11 for dec, -1 for failure.

month must be a lowercased string.

◆ sanitize_title()

void sanitize_title ( char * title)

Replace invalid chars in title with ' ' and trim all starting/ending spaces.

update_bookmark() assumes this function does not switch translation tables.

◆ sanitize_url()

int sanitize_url ( char * url)

Returns 0 if url contains invalid chars, 1 if ok.

It trims starting/ending spaces.

◆ strtolx()

long strtolx ( char * str,
char ** end )

◆ trim_chars()

static char * trim_chars ( char * s,
unsigned char c,
int * len )
inlinestatic

Trim starting and ending chars equal to c in string s.

If len != NULL, it stores new string length in pointed integer. It returns s for convenience.

◆ unhx()

static int unhx ( unsigned char a)
inlinestatic

Convert an hexadecimal char ([0-9][a-z][A-Z]) to its decimal value (0 <= result <= 15).

Returns -1 if parameter is not an hexadecimal char.