char
Overview
Module with functions and types to work with single char values.
Types and Definitions
c_check_char
typedef int ( *c_check_char )( int c );
c_check_char is the signature of a function to check a char value. The signature uses int values instead of bool and char to match the classify functions in ctype.h.
Functions
overall
char_c_
#define char_c_( Value )
Macro function that casts the Value as char.
cmp_char_c
int cmp_char_c( char a, char b );
Compares two char values and returns the three possible results:
- <0
-
means that a is less compared to b
- 0
-
means that a and b are equal
- >0
-
means that a is greater compared to b
#include "clingo/lang/expect.h" #include "clingo/type/char.h" int main( void ) { init_tap_c_(); expect_lt_c_( cmp_char_c( '6', 'N' ) ); expect_eq_c_( cmp_char_c( 'N', 'N' ) ); expect_gt_c_( cmp_char_c( 'n', 'N' ) ); return finish_tap_c_(); }
interpret
dec_char_value_c
int8_t dec_char_value_c( char c );
Converts a char that represents a valid decimal value into a int8_t value. The function return -1 if the char does not represent a valid decimal value.
#include "clingo/lang/expect.h" #include "clingo/type/char.h" int main( void ) { init_tap_c_(); expect_c_( dec_char_value_c( '0' ) == 0 ); expect_c_( dec_char_value_c( '5' ) == 5 ); expect_c_( dec_char_value_c( '9' ) == 9 ); expect_c_( dec_char_value_c( 'x' ) == -1 ); expect_c_( dec_char_value_c( 'A' ) == -1 ); return finish_tap_c_(); }
hex_char_value_c
int8_t hex_char_value_c( char c );
Converts a char that represents a valid hex value into a int8_t value. The function return -1 if the char does not represent a valid hex value.
#include "clingo/lang/expect.h" #include "clingo/type/char.h" int main( void ) { init_tap_c_(); expect_c_( hex_char_value_c( '0' ) == 0 ); expect_c_( hex_char_value_c( 'F' ) == 15 ); expect_c_( hex_char_value_c( 'f' ) == 15 ); expect_c_( hex_char_value_c( 'x' ) == -1 ); expect_c_( hex_char_value_c( 'g' ) == -1 ); return finish_tap_c_(); }
oct_char_value_c
int8_t oct_char_value_c( char c );
Converts a char that represents a valid octal value into a int8_t value. The function return -1 if the char does not represent a valid octal value.
#include "clingo/lang/expect.h" #include "clingo/type/char.h" int main( void ) { init_tap_c_(); expect_c_( oct_char_value_c( '0' ) == 0 ); expect_c_( oct_char_value_c( '4' ) == 4 ); expect_c_( oct_char_value_c( '7' ) == 7 ); expect_c_( oct_char_value_c( '8' ) == -1 ); expect_c_( oct_char_value_c( '!' ) == -1 ); return finish_tap_c_(); }