NetSurf
Functions
ascii.h File Reference

Helpers for ASCII string handling. More...

#include <errno.h>
#include <stdlib.h>
#include <limits.h>
Include dependency graph for ascii.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static bool ascii_is_space (char c)
 Test whether a character is a whitespace character. More...
 
static bool ascii_is_alpha_lower (char c)
 Test whether a character is lower-case alphabetical. More...
 
static bool ascii_is_alpha_upper (char c)
 Test whether a character is upper-case alphabetical. More...
 
static bool ascii_is_alpha (char c)
 Test whether a character is alphabetical (upper or lower case). More...
 
static bool ascii_is_digit (char c)
 Test whether a character is a decimal digit. More...
 
static bool ascii_is_sign (char c)
 Test whether a character is a positive/negative numerical sign. More...
 
static bool ascii_is_alphanumerical (char c)
 Test whether a character is alphanumerical (upper or lower case). More...
 
static bool ascii_is_af_lower (char c)
 Test whether a character is 'a' to 'f' (lowercase). More...
 
static bool ascii_is_hex_lower (char c)
 Test whether a character is hexadecimal (lower case). More...
 
static bool ascii_is_af_upper (char c)
 Test whether a character is 'A' to 'F' (uppercase). More...
 
static bool ascii_is_hex_upper (char c)
 Test whether a character is hexadecimal (upper case). More...
 
static bool ascii_is_hex (char c)
 Test whether a character is hexadecimal (upper or lower case). More...
 
static int ascii_hex_to_value (char c)
 Convert a hexadecimal character to its value. More...
 
static int ascii_hex_to_value_2_chars (char c1, char c2)
 Converts two hexadecimal characters to a single number. More...
 
static char ascii_to_lower (char c)
 Convert an upper case character to lower case. More...
 
static char ascii_to_upper (char c)
 Convert a lower case character to upper case. More...
 
static size_t ascii_count_alpha_lower (const char *str)
 Count consecutive lower case alphabetical characters in string. More...
 
static size_t ascii_count_alpha_upper (const char *str)
 Count consecutive upper case alphabetical characters in string. More...
 
static size_t ascii_count_alpha (const char *str)
 Count consecutive alphabetical characters in string (upper or lower case). More...
 
static size_t ascii_count_digit (const char *str)
 Count consecutive decial digit characters in string. More...
 
static size_t ascii_count_digit_or_colon (const char *str)
 Count consecutive characters either decimal digit or colon in string. More...
 
static bool ascii_strings_equal_caseless (const char *s1, const char *s2)
 Test for string equality (case insensitive). More...
 
static bool ascii_strings_equal (const char *s1, const char *s2)
 Test for string equality (case sensitive). More...
 
static size_t ascii_strings_count_equal_caseless (const char *s1, const char *s2)
 Count consecutive equal ascii characters (case insensitive). More...
 
static size_t ascii_strings_count_equal (const char *s1, const char *s2)
 Count consecutive equal ascii characters (case sensitive). More...
 
static size_t ascii_string_to_int (const char *str, int *res)
 Parse an int out of a string. More...
 

Detailed Description

Helpers for ASCII string handling.

These helpers for string parsing will have the correct effect for parsing ASCII text (as used by most web specs), regardless of system locale.

Definition in file ascii.h.

Function Documentation

◆ ascii_count_alpha()

static size_t ascii_count_alpha ( const char *  str)
inlinestatic

Count consecutive alphabetical characters in string (upper or lower case).

Parameters
[in]strString to count characters in.
Returns
number of consecutive alphabetical characters at start of str.

Definition at line 267 of file ascii.h.

References ascii_is_alpha(), and count().

Referenced by time__get_date().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_count_alpha_lower()

static size_t ascii_count_alpha_lower ( const char *  str)
inlinestatic

Count consecutive lower case alphabetical characters in string.

Parameters
[in]strString to count characters in.
Returns
number of consecutive lower case characters at start of str.

Definition at line 237 of file ascii.h.

References ascii_is_alpha_lower(), and count().

Here is the call graph for this function:

◆ ascii_count_alpha_upper()

static size_t ascii_count_alpha_upper ( const char *  str)
inlinestatic

Count consecutive upper case alphabetical characters in string.

Parameters
[in]strString to count characters in.
Returns
number of consecutive upper case characters at start of str.

Definition at line 252 of file ascii.h.

References ascii_is_alpha_upper(), and count().

Here is the call graph for this function:

◆ ascii_count_digit()

static size_t ascii_count_digit ( const char *  str)
inlinestatic

Count consecutive decial digit characters in string.

Parameters
[in]strString to count characters in.
Returns
number of consecutive decimal digit characters at start of str.

Definition at line 282 of file ascii.h.

References ascii_is_digit(), and count().

Referenced by time__get_date().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_count_digit_or_colon()

static size_t ascii_count_digit_or_colon ( const char *  str)
inlinestatic

Count consecutive characters either decimal digit or colon in string.

Parameters
[in]strString to count characters in.
Returns
number of consecutive decimal or ':' characters at start of str.

Definition at line 297 of file ascii.h.

References ascii_is_digit(), and count().

Referenced by time__parse_hh_mm_ss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_hex_to_value()

static int ascii_hex_to_value ( char  c)
inlinestatic

Convert a hexadecimal character to its value.

Parameters
[in]cCharacter to convert.
Returns
value of character (0-15), or -256 if not a hexadecimal character.

Definition at line 176 of file ascii.h.

References ascii_is_af_lower(), ascii_is_af_upper(), and ascii_is_digit().

Referenced by ascii_hex_to_value_2_chars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_hex_to_value_2_chars()

static int ascii_hex_to_value_2_chars ( char  c1,
char  c2 
)
inlinestatic

Converts two hexadecimal characters to a single number.

Parameters
[in]c1most significant hex digit.
[in]c2least significant hex digit.
Returns
the total value of the two digit hex number (0-255), or -ve if input not hex.

Definition at line 198 of file ascii.h.

References ascii_hex_to_value().

Here is the call graph for this function:

◆ ascii_is_af_lower()

static bool ascii_is_af_lower ( char  c)
inlinestatic

Test whether a character is 'a' to 'f' (lowercase).

Parameters
[in]cCharacter to test.
Returns
true iff c is 'a' to 'f' (lowercase), else false.

Definition at line 119 of file ascii.h.

Referenced by ascii_hex_to_value(), ascii_is_hex(), and ascii_is_hex_lower().

Here is the caller graph for this function:

◆ ascii_is_af_upper()

static bool ascii_is_af_upper ( char  c)
inlinestatic

Test whether a character is 'A' to 'F' (uppercase).

Parameters
[in]cCharacter to test.
Returns
true iff c is 'A' to 'F' (uppercase), else false.

Definition at line 141 of file ascii.h.

Referenced by ascii_hex_to_value(), ascii_is_hex(), and ascii_is_hex_upper().

Here is the caller graph for this function:

◆ ascii_is_alpha()

static bool ascii_is_alpha ( char  c)
inlinestatic

Test whether a character is alphabetical (upper or lower case).

Parameters
[in]cCharacter to test.
Returns
true iff c is alphabetical, else false.

Definition at line 75 of file ascii.h.

References ascii_is_alpha_lower(), and ascii_is_alpha_upper().

Referenced by ascii_count_alpha(), ascii_is_alphanumerical(), time__get_date(), and urldb_get_search_tree_direct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_is_alpha_lower()

static bool ascii_is_alpha_lower ( char  c)
inlinestatic

Test whether a character is lower-case alphabetical.

Parameters
[in]cCharacter to test.
Returns
true iff c is lower-case alphabetical, else false.

Definition at line 53 of file ascii.h.

Referenced by ascii_count_alpha_lower(), ascii_is_alpha(), and ascii_to_upper().

Here is the caller graph for this function:

◆ ascii_is_alpha_upper()

static bool ascii_is_alpha_upper ( char  c)
inlinestatic

Test whether a character is upper-case alphabetical.

Parameters
[in]cCharacter to test.
Returns
true iff c is upper-case alphabetical, else false.

Definition at line 64 of file ascii.h.

Referenced by ascii_count_alpha_upper(), ascii_is_alpha(), and ascii_to_lower().

Here is the caller graph for this function:

◆ ascii_is_alphanumerical()

static bool ascii_is_alphanumerical ( char  c)
inlinestatic

Test whether a character is alphanumerical (upper or lower case).

Parameters
[in]cCharacter to test.
Returns
true iff c is alphanumerical, else false.

Definition at line 108 of file ascii.h.

References ascii_is_alpha(), and ascii_is_digit().

Here is the call graph for this function:

◆ ascii_is_digit()

static bool ascii_is_digit ( char  c)
inlinestatic

Test whether a character is a decimal digit.

Parameters
[in]cCharacter to test.
Returns
true iff c is a decimal digit, else false.

Definition at line 86 of file ascii.h.

Referenced by ascii_count_digit(), ascii_count_digit_or_colon(), ascii_hex_to_value(), ascii_is_alphanumerical(), ascii_is_hex(), ascii_is_hex_lower(), ascii_is_hex_upper(), time__get_date(), and urldb_parse_avpair().

Here is the caller graph for this function:

◆ ascii_is_hex()

static bool ascii_is_hex ( char  c)
inlinestatic

Test whether a character is hexadecimal (upper or lower case).

Parameters
[in]cCharacter to test.
Returns
true iff c is hexadecimal, else false.

Definition at line 163 of file ascii.h.

References ascii_is_af_lower(), ascii_is_af_upper(), and ascii_is_digit().

Referenced by url_unescape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_is_hex_lower()

static bool ascii_is_hex_lower ( char  c)
inlinestatic

Test whether a character is hexadecimal (lower case).

Parameters
[in]cCharacter to test.
Returns
true iff c is hexadecimal, else false.

Definition at line 130 of file ascii.h.

References ascii_is_af_lower(), and ascii_is_digit().

Here is the call graph for this function:

◆ ascii_is_hex_upper()

static bool ascii_is_hex_upper ( char  c)
inlinestatic

Test whether a character is hexadecimal (upper case).

Parameters
[in]cCharacter to test.
Returns
true iff c is hexadecimal, else false.

Definition at line 152 of file ascii.h.

References ascii_is_af_upper(), and ascii_is_digit().

Here is the call graph for this function:

◆ ascii_is_sign()

static bool ascii_is_sign ( char  c)
inlinestatic

Test whether a character is a positive/negative numerical sign.

Parameters
[in]cCharacter to test.
Returns
true iff c is a sign, else false.

Definition at line 97 of file ascii.h.

Referenced by time__parse_number().

Here is the caller graph for this function:

◆ ascii_is_space()

static bool ascii_is_space ( char  c)
inlinestatic

Test whether a character is a whitespace character.

Parameters
[in]cCharacter to test.
Returns
true iff c is whitespace, else false.

Definition at line 40 of file ascii.h.

Referenced by box_extract_link(), box_parse_multi_lengths(), box_text_transform(), form_acceptable_charset(), gtk_fetch_filetype_init(), html_process_inserted_meta(), and monkey_fetch_filetype_init().

Here is the caller graph for this function:

◆ ascii_string_to_int()

static size_t ascii_string_to_int ( const char *  str,
int *  res 
)
inlinestatic

Parse an int out of a string.

Parameters
[in]strString to parse integer out of.
[out]resReturns parsed integer.
Returns
The number of characters consumed in str. Returning 0 indicates failure to parse an integer out of the string.

Definition at line 397 of file ascii.h.

References strtoll().

Referenced by time__parse_number().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_strings_count_equal()

static size_t ascii_strings_count_equal ( const char *  s1,
const char *  s2 
)
inlinestatic

Count consecutive equal ascii characters (case sensitive).

Parameters
[in]s1First string to compare.
[in]s2Second string to compare.
Returns
number of equal characters.

Definition at line 375 of file ascii.h.

◆ ascii_strings_count_equal_caseless()

static size_t ascii_strings_count_equal_caseless ( const char *  s1,
const char *  s2 
)
inlinestatic

Count consecutive equal ascii characters (case insensitive).

Parameters
[in]s1First string to compare.
[in]s2Second string to compare.
Returns
number of equivalent characters.

Definition at line 354 of file ascii.h.

References ascii_to_lower().

Referenced by time__parse_month(), time__parse_timezone(), and time__parse_weekday().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_strings_equal()

static bool ascii_strings_equal ( const char *  s1,
const char *  s2 
)
inlinestatic

Test for string equality (case sensitive).

Parameters
[in]s1First string to compare.
[in]s2Second string to compare.
Returns
true iff strings are equal, else false.

Definition at line 334 of file ascii.h.

◆ ascii_strings_equal_caseless()

static bool ascii_strings_equal_caseless ( const char *  s1,
const char *  s2 
)
inlinestatic

Test for string equality (case insensitive).

Parameters
[in]s1First string to compare.
[in]s2Second string to compare.
Returns
true iff strings are equivalent, else false.

Definition at line 314 of file ascii.h.

References ascii_to_lower().

Here is the call graph for this function:

◆ ascii_to_lower()

static char ascii_to_lower ( char  c)
inlinestatic

Convert an upper case character to lower case.

If the given character is not upper case alphabetical, it is returned unchanged.

Parameters
[in]cCharacter to convert.
Returns
lower case conversion of c else c.

Definition at line 212 of file ascii.h.

References ascii_is_alpha_upper().

Referenced by ascii_strings_count_equal_caseless(), ascii_strings_equal_caseless(), box_text_transform(), fetch_filetype(), monkey_fetch_filetype(), save_complete_rewrite_stylesheet_urls(), and urldb_get_search_tree_direct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ascii_to_upper()

static char ascii_to_upper ( char  c)
inlinestatic

Convert a lower case character to upper case.

If the given character is not lower case alphabetical, it is returned unchanged.

Parameters
[in]cCharacter to convert.
Returns
upper case conversion of c else c.

Definition at line 226 of file ascii.h.

References ascii_is_alpha_lower().

Referenced by box_text_transform(), content_textsearch_find_pattern(), and form_acceptable_charset().

Here is the call graph for this function:
Here is the caller graph for this function: