ds 0.10.0
A C library to safely yet efficiently work with UTF-8–encoded, growable dynamic strings.
char.h File Reference

Declaration of the char type, related constants and functions. More...

#include <limits.h>
#include <stdbool.h>
#include "ds/usize.h"
Include dependency graph for char.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DS_CHAR_BYTES   ((ds_usize_t)sizeof (ds_char_t))
 The size of char in bytes. More...
 
#define DS_CHAR_MIN   ((ds_char_t)CHAR_MIN)
 The smallest value that can be represented by char. More...
 
#define DS_CHAR_MAX   ((ds_char_t)CHAR_MAX)
 The largest value that can be represented by char. More...
 
#define DS_CHAR_NUL   ((ds_char_t)0x00)
 The null character. More...
 
#define DS_CHAR_BEL   ((ds_char_t)0x07)
 The bell character. More...
 
#define DS_CHAR_BS   ((ds_char_t)0x08)
 The backspace character. More...
 
#define DS_CHAR_HT   ((ds_char_t)0x09)
 The horizontal-tab character. More...
 
#define DS_CHAR_LF   ((ds_char_t)0x0A)
 The line-feed character. More...
 
#define DS_CHAR_VT   ((ds_char_t)0x0B)
 The vertical-tab character. More...
 
#define DS_CHAR_FF   ((ds_char_t)0x0C)
 The form-feed character. More...
 
#define DS_CHAR_CR   ((ds_char_t)0x0D)
 The carriage-return character. More...
 
#define DS_CHAR_ESC   ((ds_char_t)0x1B)
 The escape character. More...
 
#define DS_CHAR_US   ((ds_char_t)0x1F)
 The unit-separator character. More...
 
#define DS_CHAR_DEL   ((ds_char_t)0x7F)
 The delete character. More...
 
#define DS_SCN_CHAR   "c"
 char notation. Can be used in scanf to parse and read char values. More...
 
#define DS_PRI_CHAR   "c"
 char notation. Can be used in printf to format and write char values. More...
 

Typedefs

typedef char ds_char_t
 A character type. More...
 
typedef bool(* ds_predicate_char_t) (ds_char_t)
 A function pointer type for char predicate functions that return true or false depending on the passed char argument. More...
 

Functions

ds_char_t ds_char_to_ascii_uppercase (ds_char_t self)
 Makes a copy of self in its ASCII upper case equivalent. More...
 
ds_char_t ds_char_to_ascii_lowercase (ds_char_t self)
 Makes a copy of self in its ASCII lower case equivalent. More...
 
bool ds_char_eq_ignore_ascii_case (ds_char_t self, ds_char_t other)
 Checks that self and other are an ASCII case-insensitive match. More...
 
bool ds_char_is_ascii_alphabetic (ds_char_t self)
 Checks if self is an ASCII alphabetic character: More...
 
bool ds_char_is_ascii_uppercase (ds_char_t self)
 Checks if self is an ASCII uppercase character: More...
 
bool ds_char_is_ascii_lowercase (ds_char_t self)
 Checks if self is an ASCII lowercase character: More...
 
bool ds_char_is_ascii_alphanumeric (ds_char_t self)
 Checks if self is an ASCII alphanumeric character: More...
 
bool ds_char_is_ascii_digit (ds_char_t self)
 Checks if self is an ASCII decimal digit: More...
 
bool ds_char_is_ascii_octdigit (ds_char_t self)
 Checks if self is an ASCII octal digit: More...
 
bool ds_char_is_ascii_hexdigit (ds_char_t self)
 Checks if self is an ASCII hexadecimal digit: More...
 
bool ds_char_is_ascii_punctuation (ds_char_t self)
 Checks if self is an ASCII punctuation character: More...
 
bool ds_char_is_ascii_graphic (ds_char_t self)
 Checks if self is an ASCII graphic character: More...
 
bool ds_char_is_ascii_whitespace (ds_char_t self)
 Checks if self is an ASCII whitespace character: More...
 
bool ds_char_is_ascii_control (ds_char_t self)
 Checks if self is an ASCII control character: More...
 

Detailed Description

Declaration of the char type, related constants and functions.

Author
Avinash Maddikonda (svass.nosp@m.saka.nosp@m.vi@gm.nosp@m.ail..nosp@m.com)
Since
0.3.0
Date
2023-07-26

Definition in file char.h.

Macro Definition Documentation

◆ DS_CHAR_BEL

#define DS_CHAR_BEL   ((ds_char_t)0x07)

The bell character.

Examples

Basic usage:

assert (DS_CHAR_BEL == '\x07');
#define DS_CHAR_BEL
The bell character.
Definition: char.h:604

Definition at line 604 of file char.h.

◆ DS_CHAR_BS

#define DS_CHAR_BS   ((ds_char_t)0x08)

The backspace character.

Examples

Basic usage:

assert (DS_CHAR_BS == '\b');
#define DS_CHAR_BS
The backspace character.
Definition: char.h:615

Definition at line 615 of file char.h.

◆ DS_CHAR_BYTES

#define DS_CHAR_BYTES   ((ds_usize_t)sizeof (ds_char_t))

The size of char in bytes.

Examples

Basic usage:

assert (DS_CHAR_BYTES == 1);
#define DS_CHAR_BYTES
The size of char in bytes.
Definition: char.h:560

Definition at line 560 of file char.h.

◆ DS_CHAR_CR

#define DS_CHAR_CR   ((ds_char_t)0x0D)

The carriage-return character.

Examples

Basic usage:

assert (DS_CHAR_CR == '\r');
#define DS_CHAR_CR
The carriage-return character.
Definition: char.h:670

Definition at line 670 of file char.h.

◆ DS_CHAR_DEL

#define DS_CHAR_DEL   ((ds_char_t)0x7F)

The delete character.

Examples

Basic usage:

assert (DS_CHAR_DEL == '\x7F');
#define DS_CHAR_DEL
The delete character.
Definition: char.h:703

Definition at line 703 of file char.h.

◆ DS_CHAR_ESC

#define DS_CHAR_ESC   ((ds_char_t)0x1B)

The escape character.

Examples

Basic usage:

assert (DS_CHAR_ESC == '\x1B');
#define DS_CHAR_ESC
The escape character.
Definition: char.h:681

Definition at line 681 of file char.h.

◆ DS_CHAR_FF

#define DS_CHAR_FF   ((ds_char_t)0x0C)

The form-feed character.

Examples

Basic usage:

assert (DS_CHAR_FF == '\f');
#define DS_CHAR_FF
The form-feed character.
Definition: char.h:659

Definition at line 659 of file char.h.

◆ DS_CHAR_HT

#define DS_CHAR_HT   ((ds_char_t)0x09)

The horizontal-tab character.

Examples

Basic usage:

assert (DS_CHAR_HT == '\t');
#define DS_CHAR_HT
The horizontal-tab character.
Definition: char.h:626

Definition at line 626 of file char.h.

◆ DS_CHAR_LF

#define DS_CHAR_LF   ((ds_char_t)0x0A)

The line-feed character.

Examples

Basic usage:

assert (DS_CHAR_LF == '\n');
#define DS_CHAR_LF
The line-feed character.
Definition: char.h:637

Definition at line 637 of file char.h.

◆ DS_CHAR_MAX

#define DS_CHAR_MAX   ((ds_char_t)CHAR_MAX)

The largest value that can be represented by char.

Examples

Basic usage:

assert (DS_CHAR_MAX == CHAR_MAX);
#define DS_CHAR_MAX
The largest value that can be represented by char.
Definition: char.h:582

Definition at line 582 of file char.h.

◆ DS_CHAR_MIN

#define DS_CHAR_MIN   ((ds_char_t)CHAR_MIN)

The smallest value that can be represented by char.

Examples

Basic usage:

assert (DS_CHAR_MIN == CHAR_MIN);
#define DS_CHAR_MIN
The smallest value that can be represented by char.
Definition: char.h:571

Definition at line 571 of file char.h.

◆ DS_CHAR_NUL

#define DS_CHAR_NUL   ((ds_char_t)0x00)

The null character.

Examples

Basic usage:

assert (DS_CHAR_NUL == '\0');
#define DS_CHAR_NUL
The null character.
Definition: char.h:593

Definition at line 593 of file char.h.

◆ DS_CHAR_US

#define DS_CHAR_US   ((ds_char_t)0x1F)

The unit-separator character.

Examples

Basic usage:

assert (DS_CHAR_US == '\x1F');
#define DS_CHAR_US
The unit-separator character.
Definition: char.h:692

Definition at line 692 of file char.h.

◆ DS_CHAR_VT

#define DS_CHAR_VT   ((ds_char_t)0x0B)

The vertical-tab character.

Examples

Basic usage:

assert (DS_CHAR_VT == '\v');
#define DS_CHAR_VT
The vertical-tab character.
Definition: char.h:648

Definition at line 648 of file char.h.

◆ DS_PRI_CHAR

#define DS_PRI_CHAR   "c"

char notation. Can be used in printf to format and write char values.

Examples

Basic usage:

printf ("%" DS_PRI_CHAR, x);
char ds_char_t
A character type.
Definition: char.h:30
#define DS_PRI_CHAR
char notation. Can be used in printf to format and write char values.
Definition: char.h:733

Definition at line 733 of file char.h.

◆ DS_SCN_CHAR

#define DS_SCN_CHAR   "c"

char notation. Can be used in scanf to parse and read char values.

Warning
It is strongly advised to use fgets instead of scanf to read input.

Examples

Basic usage:

scanf ("%" DS_SCN_CHAR, &x);
#define DS_SCN_CHAR
char notation. Can be used in scanf to parse and read char values.
Definition: char.h:720

Definition at line 720 of file char.h.

Typedef Documentation

◆ ds_char_t

typedef char ds_char_t

A character type.

The char type represents a single character.

More specifically, since ‘character’ isn’t a well-defined concept in Unicode, char will be a ‘Unicode scalar value’ in the future, when UTF-8 validation is fully supported.

Definition at line 30 of file char.h.

◆ ds_predicate_char_t

typedef bool(* ds_predicate_char_t) (ds_char_t)

A function pointer type for char predicate functions that return true or false depending on the passed char argument.

Expected function signature:

bool predicate(ds_char_t);

Examples

Basic usage:

count_only_allowed (ds_cstr_t const cstr, ds_usize_t const size,
ds_predicate_char_t const is_allowed)
{
for (ds_usize_t i = DS_USIZE_MIN; i < size; i++)
{
if (is_allowed (cstr[i]))
{
count++;
}
}
return count;
}
assert (count_only_allowed ("a1b2c3", 6, ds_char_is_ascii_digit) == 3);
bool(* ds_predicate_char_t)(ds_char_t)
A function pointer type for char predicate functions that return true or false depending on the passe...
Definition: char.h:64
bool ds_char_is_ascii_digit(ds_char_t self)
Checks if self is an ASCII decimal digit:
Definition: char.c:78
ds_char_t const * ds_cstr_t
An immutable C-string type.
Definition: cstr.h:28
#define DS_USIZE_MIN
The smallest value that can be represented by usize.
Definition: usize.h:49
size_t ds_usize_t
The pointer-sized unsigned integer type.
Definition: usize.h:26

Definition at line 64 of file char.h.

Function Documentation

◆ ds_char_eq_ignore_ascii_case()

bool ds_char_eq_ignore_ascii_case ( ds_char_t  self,
ds_char_t  other 
)

Checks that self and other are an ASCII case-insensitive match.

Equivalent to:

ds_char_t ds_char_to_ascii_lowercase(ds_char_t self)
Makes a copy of self in its ASCII lower case equivalent.
Definition: char.c:38
Parameters
selfThe first value to compare.
otherThe second value to compare.
Returns
true if self and other are an ASCII case-insensitive match, and false otherwise.

Examples

Basic usage:

ds_char_t const upper_a = 'A';
ds_char_t const lower_a = 'a';
ds_char_t const lower_z = 'z';
assert (ds_char_eq_ignore_ascii_case (upper_a, lower_a));
assert (ds_char_eq_ignore_ascii_case (upper_a, upper_a));
assert (!ds_char_eq_ignore_ascii_case (upper_a, lower_z));
bool ds_char_eq_ignore_ascii_case(ds_char_t self, ds_char_t other)
Checks that self and other are an ASCII case-insensitive match.
Definition: char.c:46

Definition at line 46 of file char.c.

Here is the call graph for this function:

◆ ds_char_is_ascii_alphabetic()

bool ds_char_is_ascii_alphabetic ( ds_char_t  self)

Checks if self is an ASCII alphabetic character:

  • U+0041 'A' ..= U+005A 'Z', or
  • U+0061 'a' ..= U+007A 'z'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII alphabetic character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (ds_char_is_ascii_alphabetic (uppercase_a));
assert (ds_char_is_ascii_alphabetic (uppercase_g));
assert (!ds_char_is_ascii_alphabetic (zero));
assert (!ds_char_is_ascii_alphabetic (percent));
assert (!ds_char_is_ascii_alphabetic (space));
bool ds_char_is_ascii_alphabetic(ds_char_t self)
Checks if self is an ASCII alphabetic character:
Definition: char.c:53

Definition at line 53 of file char.c.

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

◆ ds_char_is_ascii_alphanumeric()

bool ds_char_is_ascii_alphanumeric ( ds_char_t  self)

Checks if self is an ASCII alphanumeric character:

  • U+0041 'A' ..= U+005A 'Z', or
  • U+0061 'a' ..= U+007A 'z', or
  • U+0030 '0' ..= U+0039 '9'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII alphanumeric character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (ds_char_is_ascii_alphanumeric (uppercase_a));
assert (ds_char_is_ascii_alphanumeric (uppercase_g));
assert (!ds_char_is_ascii_alphanumeric (percent));
bool ds_char_is_ascii_alphanumeric(ds_char_t self)
Checks if self is an ASCII alphanumeric character:
Definition: char.c:72

Definition at line 72 of file char.c.

Here is the call graph for this function:

◆ ds_char_is_ascii_control()

bool ds_char_is_ascii_control ( ds_char_t  self)

Checks if self is an ASCII control character:

  • U+0000 NUL ..= U+001F UNIT SEPARATOR, or U+007F DELETE.

Note that most ASCII whitespace characters are control characters, but SPACE is not.

Parameters
selfThe value to check.
Returns
true if self is an ASCII control character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (!ds_char_is_ascii_control (uppercase_a));
assert (!ds_char_is_ascii_control (uppercase_g));
assert (!ds_char_is_ascii_control (zero));
assert (!ds_char_is_ascii_control (percent));
assert (!ds_char_is_ascii_control (space));
assert (ds_char_is_ascii_control (esc));
bool ds_char_is_ascii_control(ds_char_t self)
Checks if self is an ASCII control character:
Definition: char.c:120

Definition at line 120 of file char.c.

◆ ds_char_is_ascii_digit()

bool ds_char_is_ascii_digit ( ds_char_t  self)

Checks if self is an ASCII decimal digit:

  • U+0030 '0' ..= U+0039 '9'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII decimal digit, and false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (!ds_char_is_ascii_digit (uppercase_a));
assert (!ds_char_is_ascii_digit (uppercase_g));
assert (!ds_char_is_ascii_digit (a));
assert (!ds_char_is_ascii_digit (g));
assert (ds_char_is_ascii_digit (zero));
assert (!ds_char_is_ascii_digit (percent));
assert (!ds_char_is_ascii_digit (space));
assert (!ds_char_is_ascii_digit (lf));
assert (!ds_char_is_ascii_digit (esc));

Definition at line 78 of file char.c.

Here is the caller graph for this function:

◆ ds_char_is_ascii_graphic()

bool ds_char_is_ascii_graphic ( ds_char_t  self)

Checks if self is an ASCII graphic character:

  • U+0021 '!' ..= U+007E '~'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII graphic character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (ds_char_is_ascii_graphic (uppercase_a));
assert (ds_char_is_ascii_graphic (uppercase_g));
assert (ds_char_is_ascii_graphic (zero));
assert (ds_char_is_ascii_graphic (percent));
assert (!ds_char_is_ascii_graphic (space));
assert (!ds_char_is_ascii_graphic (lf));
assert (!ds_char_is_ascii_graphic (esc));
bool ds_char_is_ascii_graphic(ds_char_t self)
Checks if self is an ASCII graphic character:
Definition: char.c:107

Definition at line 107 of file char.c.

◆ ds_char_is_ascii_hexdigit()

bool ds_char_is_ascii_hexdigit ( ds_char_t  self)

Checks if self is an ASCII hexadecimal digit:

  • U+0030 '0' ..= U+0039 '9', or
  • U+0041 'A' ..= U+0046 'F', or
  • U+0061 'a' ..= U+0066 'f'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII hexadecimal digit, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (ds_char_is_ascii_hexdigit (uppercase_a));
assert (!ds_char_is_ascii_hexdigit (uppercase_g));
assert (ds_char_is_ascii_hexdigit (zero));
assert (!ds_char_is_ascii_hexdigit (percent));
assert (!ds_char_is_ascii_hexdigit (space));
assert (!ds_char_is_ascii_hexdigit (esc));
bool ds_char_is_ascii_hexdigit(ds_char_t self)
Checks if self is an ASCII hexadecimal digit:
Definition: char.c:90

Definition at line 90 of file char.c.

Here is the call graph for this function:

◆ ds_char_is_ascii_lowercase()

bool ds_char_is_ascii_lowercase ( ds_char_t  self)

Checks if self is an ASCII lowercase character:

  • U+0061 'a' ..= U+007A 'z'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII lowercase character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (!ds_char_is_ascii_lowercase (uppercase_a));
assert (!ds_char_is_ascii_lowercase (uppercase_g));
assert (!ds_char_is_ascii_lowercase (zero));
assert (!ds_char_is_ascii_lowercase (percent));
assert (!ds_char_is_ascii_lowercase (space));
bool ds_char_is_ascii_lowercase(ds_char_t self)
Checks if self is an ASCII lowercase character:
Definition: char.c:66

Definition at line 66 of file char.c.

Here is the caller graph for this function:

◆ ds_char_is_ascii_octdigit()

bool ds_char_is_ascii_octdigit ( ds_char_t  self)

Checks if self is an ASCII octal digit:

  • U+0030 '0' ..= U+0037 '7'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII octal digit, and false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const a = 'a';
ds_char_t const zero = '0';
ds_char_t const seven = '7';
ds_char_t const nine = '9';
ds_char_t const percent = '%';
ds_char_t const lf = DS_CHAR_LF;
assert (!ds_char_is_ascii_octdigit (uppercase_a));
assert (ds_char_is_ascii_octdigit (zero));
assert (ds_char_is_ascii_octdigit (seven));
assert (!ds_char_is_ascii_octdigit (nine));
assert (!ds_char_is_ascii_octdigit (percent));
bool ds_char_is_ascii_octdigit(ds_char_t self)
Checks if self is an ASCII octal digit:
Definition: char.c:84

Definition at line 84 of file char.c.

◆ ds_char_is_ascii_punctuation()

bool ds_char_is_ascii_punctuation ( ds_char_t  self)

Checks if self is an ASCII punctuation character:

  • U+0021 ..= U+002F ! " # $ % & ' ( ) * + , - . /, or
  • U+003A ..= U+0040 : ; < = > ? @, or
  • U+005B ..= U+0060 [ \ ] ^ _ `, or
  • U+007B ..= U+007E { | } ~
Parameters
selfThe value to check.
Returns
true if self is an ASCII punctuation character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (!ds_char_is_ascii_punctuation (uppercase_a));
assert (!ds_char_is_ascii_punctuation (uppercase_g));
assert (ds_char_is_ascii_punctuation (percent));
assert (!ds_char_is_ascii_punctuation (space));
bool ds_char_is_ascii_punctuation(ds_char_t self)
Checks if self is an ASCII punctuation character:
Definition: char.c:98

Definition at line 98 of file char.c.

◆ ds_char_is_ascii_uppercase()

bool ds_char_is_ascii_uppercase ( ds_char_t  self)

Checks if self is an ASCII uppercase character:

  • U+0041 'A' ..= U+005A 'Z'.
Parameters
selfThe value to check.
Returns
true if self is an ASCII uppercase character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (ds_char_is_ascii_uppercase (uppercase_a));
assert (ds_char_is_ascii_uppercase (uppercase_g));
assert (!ds_char_is_ascii_uppercase (zero));
assert (!ds_char_is_ascii_uppercase (percent));
assert (!ds_char_is_ascii_uppercase (space));
bool ds_char_is_ascii_uppercase(ds_char_t self)
Checks if self is an ASCII uppercase character:
Definition: char.c:60

Definition at line 60 of file char.c.

Here is the caller graph for this function:

◆ ds_char_is_ascii_whitespace()

bool ds_char_is_ascii_whitespace ( ds_char_t  self)

Checks if self is an ASCII whitespace character:

  • U+0020 SPACE,
  • U+0009 HORIZONTAL TAB,
  • U+000A LINE FEED,
  • U+000C FORM FEED, or
  • U+000D CARRIAGE RETURN.

ds uses the WhatWG Infra Standard's definition of ASCII whitespace. There are several other definitions in wide use. For instance, the POSIX locale includes U+000B VERTICAL TAB as well as all the above characters, but—from the very same specification—the default rule for "field splitting" in the Bourne shell considers only SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.

If you are writing a program that will process an existing file format, check what that format's definition of whitespace is before using this function.

Parameters
selfThe value to check.
Returns
true if self is an ASCII whitespace character, false otherwise.

Examples

Basic usage:

ds_char_t const uppercase_a = 'A';
ds_char_t const uppercase_g = 'G';
ds_char_t const a = 'a';
ds_char_t const g = 'g';
ds_char_t const zero = '0';
ds_char_t const percent = '%';
ds_char_t const space = ' ';
ds_char_t const lf = DS_CHAR_LF;
ds_char_t const esc = DS_CHAR_ESC;
assert (!ds_char_is_ascii_whitespace (uppercase_a));
assert (!ds_char_is_ascii_whitespace (uppercase_g));
assert (!ds_char_is_ascii_whitespace (zero));
assert (!ds_char_is_ascii_whitespace (percent));
assert (ds_char_is_ascii_whitespace (space));
bool ds_char_is_ascii_whitespace(ds_char_t self)
Checks if self is an ASCII whitespace character:
Definition: char.c:113

Definition at line 113 of file char.c.

◆ ds_char_to_ascii_lowercase()

ds_char_t ds_char_to_ascii_lowercase ( ds_char_t  self)

Makes a copy of self in its ASCII lower case equivalent.

ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters are unchanged.

Parameters
selfThe value to convert.
Returns
The ASCII lower case equivalent of self.

Examples

Basic usage:

ds_char_t const ascii = 'A';
ds_char_t const non_ascii = '❤';
assert ('a' == ds_char_to_ascii_lowercase (ascii));
assert ('❤' == ds_char_to_ascii_lowercase (non_ascii));

Definition at line 38 of file char.c.

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

◆ ds_char_to_ascii_uppercase()

ds_char_t ds_char_to_ascii_uppercase ( ds_char_t  self)

Makes a copy of self in its ASCII upper case equivalent.

ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters are unchanged.

Parameters
selfThe value to convert.
Returns
The ASCII upper case equivalent of self.

Examples

Basic usage:

ds_char_t const ascii = 'a';
ds_char_t const non_ascii = '❤';
assert ('A' == ds_char_to_ascii_uppercase (ascii));
assert ('❤' == ds_char_to_ascii_uppercase (non_ascii));
ds_char_t ds_char_to_ascii_uppercase(ds_char_t self)
Makes a copy of self in its ASCII upper case equivalent.
Definition: char.c:30

Definition at line 30 of file char.c.

Here is the call graph for this function: