ELinks 0.18.0
conv.c File Reference

Conversion functions. More...

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "intl/charsets.h"
#include "util/conv.h"
#include "util/error.h"
#include "util/time.h"
Include dependency graph for conv.c:

Functions

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, starting at position [*slen].
 
NONSTATIC_INLINE 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.
 
struct stringadd_string_replace (struct string *string, char *src, int len, unsigned char replaceable, unsigned char replacement)
 
struct stringadd_html_to_string (struct string *string, const char *src2, int len)
 
struct stringadd_cp_html_to_string (struct string *string, int src_codepage, const char *src, int len)
 
struct stringadd_quoted_to_string (struct string *string, const char *src, int len)
 
struct stringadd_shell_quoted_to_string (struct string *string, const char *src, int len)
 
struct stringadd_shell_safe_to_string (struct string *string, const char *cmd, int cmdlen)
 
long strtolx (char *str, char **end)
 
int month2num (const char *str)
 Return 0 if starting with jan, 11 for dec, -1 for failure.
 
void clr_spaces (char *str2)
 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.
 
int c_tolower (int c)
 
int c_toupper (int c)
 
int c_isupper (int c)
 
int c_islower (int c)
 

Detailed Description

Conversion functions.

Function Documentation

◆ add_cp_html_to_string()

struct string * add_cp_html_to_string ( struct string * string,
int src_codepage,
const char * src,
int len )
related

◆ add_html_to_string()

struct string * add_html_to_string ( struct string * string,
const char * src2,
int len )
related

◆ add_quoted_to_string()

struct string * add_quoted_to_string ( struct string * string,
const char * src,
int len )
related

◆ add_shell_quoted_to_string()

struct string * add_shell_quoted_to_string ( struct string * string,
const char * src,
int len )
related

◆ add_shell_safe_to_string()

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

◆ add_string_replace()

struct string * add_string_replace ( struct string * string,
char * src,
int len,
unsigned char replaceable,
unsigned char replacement )
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.

◆ elinks_longcat()

NONSTATIC_INLINE 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()

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, 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
const char * s
Definition general.c:869

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.

◆ 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 )