cScanner
Overview
Type and Definitions
cScanner
struct cScanner
{
int64_t pos;
int64_t space;
void const* mem;
int err;
};
typedef struct cScanner cScanner;
cScanner allows to extract data from a memory block. The mem pointer points to the next byte that will be scanned. The pos value shows how much bytes are allready scanned. The space value tells how much bytes in the memory block are not scanned. The err value can be set to indicate the type of error that occurred.
Functions
init
cstr_scanner_c_
#define cstr_scanner_c_( Cstr )
Creates a scanner to scan the Cstr. The '\0' at the end of the string will not be scanned.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "scan a string" );
cChars chars = unscanned_chars_c_( sca );
expect_c_( chars_is_c( chars, "scan a string" ) );
return finish_tap_c_();
}
make_scanner_c_
#define make_scanner_c_( Size, Memory )
Creates a scanner to scan the assigned memory.
null_scanner_c_
#define null_scanner_c_()
Creates a scanner where all attributes are set to 0 and NULL.
scanner_copy_c_
#define scanner_copy_c_( Sca )
Copies the scanner state without the error value.
sub_scanner_c_
#define sub_scanner_c_( Sca, MaxSize )
Returns a scanner to scan the leftmost unscanned bytes of Sca. If maxSize is greater or equal the space value of Sca, contains the sub-scanner all unscanned bytes from Sca.
move
move_scanner_c
bool move_scanner_c( cScanner sca[static 1], int64_t offset );
Moves the scanner forward or backward. The function blocks attempts to move the scanner out of range and returns in this cases false.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_( Sca, Left, Right ) \
{ \
expect_c_( chars_is_c( scanned_chars_c_( Sca ), (Left) ) ); \
expect_c_( chars_is_c( unscanned_chars_c_( Sca ), (Right) ) ); \
}
int main( void )
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "abcdefghijklmnopqrstuvwxyz" );
expect_( sca, "", "abcdefghijklmnopqrstuvwxyz" );
move_scanner_c( sca, 6 );
expect_( sca, "abcdef", "ghijklmnopqrstuvwxyz" );
move_scanner_c( sca, 5 );
expect_( sca, "abcdefghijk", "lmnopqrstuvwxyz" );
move_scanner_c( sca, -3 );
expect_( sca, "abcdefgh", "ijklmnopqrstuvwxyz" );
return finish_tap_c_();
}
move_scanner_to_c
bool move_scanner_to_c( cScanner sca[static 1], int64_t pos );
Moves the scanner to the position pos in the memory. If the pos value is out of range will the scanner not be moved and the function returns false.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_( Sca, Left, Right ) \
{ \
expect_c_( chars_is_c( scanned_chars_c_( Sca ), (Left) ) ); \
expect_c_( chars_is_c( unscanned_chars_c_( Sca ), (Right) ) ); \
}
int main()
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "abcdefghijklmnopqrstuvwxyz" );
expect_( sca, "", "abcdefghijklmnopqrstuvwxyz" );
move_scanner_to_c( sca, 6 );
expect_( sca, "abcdef", "ghijklmnopqrstuvwxyz" );
move_scanner_to_c( sca, 11 );
expect_( sca, "abcdefghijk", "lmnopqrstuvwxyz" );
move_scanner_to_c( sca, 8 );
expect_( sca, "abcdefgh", "ijklmnopqrstuvwxyz" );
return finish_tap_c_();
}
reset_scanner_c
void reset_scanner_c( cScanner sca[static 1] );
Resets the scanner to the beginning of the memory.
move if
move_if_byte_c
bool move_if_byte_c( cScanner sca[static 1], cByte b );
Moves the scanner one byte value forward if the current value in the memory equals b. Returns true if the scanner was moved, otherwise false.
move_if_byte_match_c(
bool move_if_byte_match_c( cScanner sca[static 1], c_check_byte check );
Moves the scanner one byte value forward if the current value in the memory passes the check. Returns true if the scanner was moved, otherwise false.
move_if_bytes_c
bool move_if_bytes_c( cScanner sca[static 1], cBytes slice );
Moves the scanner the length of the slice forward if the current memory matches the slice values. Returns true if the scanner was moved, otherwise false.
move_if_any_char_c
#define move_if_any_char_c_( Sca, Cstr ) \
move_if_any_char_c( (Sca), c_c( Cstr ) )
bool move_if_any_char_c( cScanner sca[static 1], cChars set );
Moves the scanner one char value forward if the current value in the memory equals any of the char values in set. Returns true if the scanner was moved, otherwise false.
move_if_char_c
bool move_if_char_c( cScanner sca[static 1], char c );
Moves the scanner one char value forward if the current value in the memory equals c. Returns true if the scanner was moved, otherwise false.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_( Sca, Left, Right ) \
{ \
expect_c_( chars_is_c( scanned_chars_c_( Sca ), (Left) ) ); \
expect_c_( chars_is_c( unscanned_chars_c_( Sca ), (Right) ) ); \
}
int main( void )
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "anne" );
// ---------------------------------------------- move if it matches the char
expect_c_( move_if_char_c( sca, 'a' ) );
expect_( sca, "a", "nne" );
expect_c_( not move_if_char_c( sca, 'x' ) );
expect_( sca, "a", "nne" );
// -------------------------------------------- the function is case sensitve
expect_c_( not move_if_char_c( sca, 'N' ) );
expect_( sca, "a", "nne" );
// ------------------------------------------------------- moves just on char
expect_c_( move_if_char_c( sca, 'n' ) );
expect_( sca, "an", "ne" );
return finish_tap_c_();
}
move_if_char_match_c(
bool move_if_char_match_c( cScanner sca[static 1], c_check_char check );
Moves the scanner one char value forward if the current value in the memory passes the check. Returns true if the scanner was moved, otherwise false.
move_if_any_chars_c
#define move_if_any_chars_c_( Sca, ... ) \
move_if_any_chars_c( (Sca), cs_c_( __VA_ARGS__ ) )
bool move_if_any_chars_c( cScanner sca[static 1], cCharsSlice slice );
Moves the scanner the length of the value forward that matches with the current memory. Returns true if the scanner was moved, otherwise false.
move_if_chars_c
#define move_if_chars_c_( Sca, Cstr ) \
move_if_chars_c( (Sca), c_c( Cstr ) )
bool move_if_chars_c( cScanner sca[static 1], cChars chars );
Moves the scanner the length of the chars forward if the current memory matches the chars. Returns true if the scanner was moved, otherwise false.
move_if_any_rune_c
#define move_if_any_rune_c_( Sca, Cstr ) \
move_if_any_rune_c( (Sca), c_c( Cstr ) )
bool move_if_any_rune_c( cScanner sca[static 1], cChars set );
Moves the scanner one rune value forward if the current value in the memory equals any of the rune values in set. Returns true if the scanner was moved, otherwise false.
move_if_rune_c
bool move_if_rune_c( cScanner sca[static 1], cRune r );
Moves the scanner one rune value forward if the current value in the memory equals r. Returns true if the scanner was moved, otherwise false.
move_if_rune_match_c
bool move_if_rune_match_c( cScanner sca[static 1], c_check_rune check );
Moves the scanner one rune value forward if the current value in the memory passes the check. Returns true if the scanner was moved, otherwise false.
move_if_in_range_c
bool move_if_in_range_c( cScanner sca[static 1], cRuneRange range );
Moves the scanner one rune value forward if the current value in the memory is in the rune range. Returns true if the scanner was moved, otherwise false.
move to
move_to_byte_c
bool move_to_byte_c( cScanner sca[static 1], cByte b );
Moves the scanner to the first byte value in the memory that matches with b. The function does not move the scanner if no value matches with b. Returns true if a match was found, otherwise false.
move_to_byte_match_c
bool move_to_byte_match_c( cScanner sca[static 1], c_check_byte check );
Moves the scanner to the first byte value in the memory that passes the check. The function does not move the scanner if no value checks true. Returns true if a match was found, otherwise false.
move_to_bytes_c
bool move_to_bytes_c( cScanner sca[static 1], cBytes slice );
Moves the scanner to the first occurrence a of the slice values. The function does not move the scanner if the slice does not occur in the memory. Returns true if a match was found, otherwise false.
move_to_any_char_c
#define move_to_any_char_c_( Sca, Cstr ) \
move_to_any_char_c( (Sca), c_c( Cstr ) )
bool move_to_any_char_c( cScanner sca[static 1], cChars set );
Moves the scanner to the first char value in the memory that matches any of the char values in set. Returns true if a match was found, otherwise false.
move_to_char_c
bool move_to_char_c( cScanner sca[static 1], char c );
Moves the scanner to the first char value in the memory that matches with c. The function does not move the scanner if no value matches with c. Returns true if a match was found, otherwise false.
move_to_char_match_c
bool move_to_char_match_c( cScanner sca[static 1], c_check_char check );
Moves the scanner to the first char value in the memory that passes the check. The function does not move the scanner if no value checks true. Returns true if a match was found, otherwise false.
#include <ctype.h>
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_( Sca, Left, Right ) \
{ \
expect_c_( chars_is_c( scanned_chars_c_( Sca ), (Left) ) ); \
expect_c_( chars_is_c( unscanned_chars_c_( Sca ), (Right) ) ); \
}
int main()
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "458 sad213XyZ" );
expect_c_( move_to_char_match_c( sca, isdigit ) );
expect_( sca, "", "458 sad213XyZ" );
reset_scanner_c( sca );
expect_c_( move_to_char_match_c( sca, isspace ) );
expect_( sca, "458", " sad213XyZ" );
reset_scanner_c( sca );
expect_c_( move_to_char_match_c( sca, isalpha ) );
expect_( sca, "458 ", "sad213XyZ" );
reset_scanner_c( sca );
expect_c_( move_to_char_match_c( sca, isupper ) );
expect_( sca, "458 sad213", "XyZ" );
reset_scanner_c( sca );
expect_c_( not move_to_char_match_c( sca, ispunct ) );
expect_( sca, "", "458 sad213XyZ" );
return finish_tap_c_();
}
move_to_any_chars_c
#define move_to_any_chars_c_( Sca, ... ) \
move_to_any_chars_c( (Sca), cs_c_( __VA_ARGS__ ) )
bool move_to_any_chars_c( cScanner sca[static 1], cCharsSlice slice );
Moves the scanner to the first occurrence of any of the chars from the slice. The function does not move the scanner if the chars does not occur in the memory. Returns true if a match was found, otherwise false.
move_to_chars_c
#define move_to_chars_c_( Sca, Cstr ) \
move_to_chars_c( (Sca), c_c( Cstr ) )
bool move_to_chars_c( cScanner sca[static 1], cChars chars );
Moves the scanner to the first occurrence of the chars. The function does not move the scanner if the chars does not occur in the memory. Returns true if a match was found, otherwise false.
move_to_any_rune_c
#define move_to_any_rune_c_( Sca, Cstr ) \
move_to_any_rune_c( (Sca), c_c( CStr ) )
bool move_to_any_rune_c( cScanner sca[static 1], cChars set );
Moves the scanner to the first rune value in the memory that matches any of the rune values in set. Returns true if a match was found, otherwise false.
move_to_rune_c
bool move_to_rune_c( cScanner sca[static 1], cRune r );
Moves the scanner to the first rune value in the memory that matches with r. The function does not move the scanner if no value matches with r. Returns true if a match was found, otherwise false.
move_to_rune_match_c
bool move_to_rune_match_c( cScanner sca[static 1], c_check_rune check );
Moves the scanner to the first rune value in the memory that matches the check. The function does not move the scanner if no value checks true. Returns true if a match was found, otherwise false.
move_to_in_range_c
bool move_to_in_range_c( cScanner sca[static 1], cRuneRange range );
Moves the scanner to the first rune value in the memory thats in the rune range. The function does not move the scanner if no value checks true. Returns true if a match was found, otherwise false.
move while
move_while_byte_c
bool move_while_byte_c( cScanner sca[static 1], cByte b );
Moves the scanner to the first byte value in the memory that does not match with b. Returns true if the scanner was moved, otherwise false.
move_while_byte_match_c
bool move_while_byte_match_c( cScanner sca[static 1], c_check_byte check );
Moves the scanner to the first byte value in the memory that does not pass the check. The function does not move the scanner if no value passes the check. Returns true if the scanner was moved, otherwise false.
move_while_any_char_c
#define move_while_any_char_c_( Sca, Cstr ) \
move_while_any_char_c( (Sca), c_c( Cstr ) )
bool move_while_any_char_c( cScanner sca[static 1], cChars set );
Moves the scanner to the first char value in the memory that does not match any of the char values in set. Returns true if the scanner was moved, otherwise false.
move_while_char_c
bool move_while_char_c( cScanner sca[static 1], char c );
Moves the scanner to the first char value in the memory that does not match with c. Returns true if the scanner was moved, otherwise false.
move_while_char_match_c
bool move_while_char_match_c( cScanner sca[static 1], c_check_char check );
Moves the scanner to the first char value in the memory that does not pass the check. The function does not move the scanner if no value passes the check. Returns true if the scanner was moved, otherwise false.
#include <ctype.h>
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_( Sca, Left, Right ) \
{ \
expect_c_( chars_is_c( scanned_chars_c_( Sca ), (Left) ) ); \
expect_c_( chars_is_c( unscanned_chars_c_( Sca ), (Right) ) ); \
}
int main()
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "458 sad213XyZ" );
// ------------------------------------------------
expect_c_( move_while_char_match_c( sca, isdigit ) );
expect_( sca, "458", " sad213XyZ" );
expect_c_( not move_while_char_match_c( sca, ispunct ) );
expect_( sca, "458", " sad213XyZ" );
expect_c_( move_while_char_match_c( sca, isspace ) );
expect_( sca, "458 ", "sad213XyZ" );
expect_c_( move_while_char_match_c( sca, isalpha ) );
expect_( sca, "458 sad", "213XyZ" );
expect_c_( move_while_char_match_c( sca, isalnum ) );
expect_( sca, "458 sad213XyZ", "" );
return finish_tap_c_();
}
move_while_any_rune_c
#define move_while_any_run_c_( Sca, Cstr ) \
move_while_any_rune_c( (Sca), c_c( Cstr ) )
bool move_while_any_rune_c( cScanner sca[static 1], cChars set );
Moves the scanner to the first rune value in the memory that does not match any of the rune values in set. Returns true if the scanner was moved, otherwise false.
move_while_rune_c
bool move_while_rune_c( cScanner sca[static 1], cRune r );
Moves the scanner to the first rune value in the memory that does not match with r. Returns true if the scanner was moved, otherwise false.
move_while_rune_match_c
bool move_while_rune_match_c( cScanner sca[static 1], c_check_rune check );
Moves the scanner to the first rune value in the memory that does not pass the check. The function does not move the scanner if no value passes the check. Returns true if the scanner was moved, otherwise false.
move_while_in_rune_range_c
bool move_while_in_range_c( cScanner sca[static 1], cRuneRange range );
Moves the scanner to the first rune value in the memory that is not in the rune range. The function does not move the scanner if no value passes the check. Returns true if the scanner was moved, otherwise false.
error
scan_error_c
bool scan_error_c( cScanner sca[static 1], int err );
Sets the err value on the scanner and returns allways false.
access
scanned_bytes_c
#define scanned_bytes_c_( Sca ) \
scanned_bytes_c( (Sca), (Sca)->pos )
cBytes scanned_bytes_c( cScanner const sca[static 1], int64_t size );
Util function to access the scanned block of the memory as byte slice. Returns an empty slice if size is greater as the number of bytes that are scanned.
scanned_chars_c
#define scanned_chars_c_( Sca ) \
scanned_chars_c( (Sca), (Sca)->pos )
cChars scanned_chars_c( cScanner const sca[static 1], int64_t size );
Util function to access the scanned block of the memory as chars. Returns an empty slice if size is greater as the number of chars that are scanned.
unscanned_bytes_c
#define unscanned_bytes_c_( Sca ) \
unscanned_bytes_c( (Sca), (Sca)->space )
cBytes unscanned_bytes_c( cScanner const sca[static 1], int64_t size );
Util function to access the unscanned block of the memory as byte slice. Returns an empty slice if size is greater as the number of bytes that are unscanned.
unscanned_chars_c
#define unscanned_chars_c_( Sca ) \
unscanned_chars_c( (Sca), (Sca)->space )
cChars unscanned_chars_c( cScanner const sca[static 1], int64_t size );
Util function to access the unscanned block of the memory as chars. Returns an empty slice if size is greater as the number of chars that are unscanned.
unscanned_is_c
bool unscanned_is_c( cScanner const sca[static 1], char const cstr[static 1] );
Util function to check the whole unscanned chars.
on
on_byte_c
bool on_byte_c( cScanner sca[static 1], cByte b );
Returns true if the current value in the memory equals b, otherwise false.
on_bytes_c
bool on_bytes_c( cScanner sca[static 1], cBytes slice );
Returns true if the current memory matches the slice values, otherwise false.
on_any_char_c
#define on_any_char_c_( Sca, Cstr ) \
on_any_char_c( (Sca), c_c( Cstr ) )
bool on_any_char_c( cScanner sca[static 1], cChars set );
Returns true if the current value in the memory equals any of the char values in set, otherwise false.
on_char_c
bool on_char_c( cScanner sca[static 1], char c );
Returns true if the current value in the memory equals c, otherwise false.
on_chars_c
bool on_chars_c( cScanner sca[static 1], cChars chars );
Returns true if the current memory matches the chars, otherwise false.
on_rune_c
bool on_rune_c( cScanner sca[static 1], cRune r );
Returns true if the current value in the memory equals r, otherwise false.
view
view_bytes_c
cBytes view_bytes_c( cScanner sca[static 1], int64_t size );
Returns cBytes to view the memory of the scanner from the current position and moves sca forward. The function returns a empty slice if the scanner has not enough space to fill the slice.
view_chars_c
cChars view_chars_c( cScanner sca[static 1], int64_t size );
Returns chars to view the memory of the scanner from the current position and moves sca forward. The function returns a empty slice if the scanner has not enough space to fill the slice.
view_cstr_c
char const* view_cstr_c( cScanner sca[static 1] );
Moves the scanner forward to the position after the next '\0' char value and returns a pointer to the memory position before the call. If no '\0' char exist in the remaining memory returns the function a NULL pointer.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
#define expect_mem_( Slice, ... ) \
expect_eq_c_( \
cmp_bytes_c( \
(Slice), \
(cBytes){ (Slice).s, (cByte[]){ __VA_ARGS__ } } \
) \
)
int main()
{
init_tap_c_();
cChars data = slice_c_( char,
'a', 'b', 'c', '\0', '\0', 'd', 'e', 'f', '\0'
);
cScanner* sca = &make_scanner_c_( data.s, data.v );
// ----------------------------------------------------------------- view abc
char const* cstr = view_cstr_c( sca );
expect_c_( cstr[ 0 ] == 'a' );
expect_c_( sca->pos == 4 );
expect_c_( sca->space == 5 );
cBytes scanned = scanned_bytes_c_( sca );
expect_mem_( scanned, 'a', 'b', 'c', '\0' );
// -------------------------------------------------------- view empty string
cstr = view_cstr_c( sca );
expect_c_( cstr[ 0 ] == '\0' );
expect_c_( sca->pos == 5 );
expect_c_( sca->space == 4 );
scanned = scanned_bytes_c_( sca );
expect_mem_( scanned, 'a', 'b', 'c', '\0', '\0' );
// ----------------------------------------------------------------- view def
cstr = view_cstr_c( sca );
expect_c_( cstr[ 0 ] == 'd' );
expect_c_( sca->pos == 9 );
expect_c_( sca->space == 0 );
scanned = scanned_bytes_c_( sca );
expect_mem_( scanned, 'a', 'b', 'c', '\0', '\0', 'd', 'e', 'f', '\0' );
// ------------------------------------------------------ try to view outside
cstr = view_cstr_c( sca );
expect_c_( cstr == NULL );
return finish_tap_c_();
}
view_pad_c
cChars view_pad_c( cScanner sca[static 1], char c );
Returns a cChars where all char values have the same value as c.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
// ------------------------------------------------------------- init scanner
cScanner* sca = &cstr_scanner_c_( "---abba---" );
expect_c_( sca->pos == 0 );
expect_c_( sca->space == 10 );
expect_c_( is_empty_c_( scanned_bytes_c_( sca ) ) );
// ----------------------------------------------------------------- view pad
cChars pad = view_pad_c( sca, '-' );
expect_c_( chars_is_c( pad, "---" ) );
expect_c_( sca->pos == 3 );
expect_c_( sca->space == 7 );
pad = view_pad_c( sca, 'a' );
expect_c_( chars_is_c( pad, "a" ) );
pad = view_pad_c( sca, 'b' );
expect_c_( chars_is_c( pad, "bb" ) );
expect_c_( sca->pos == 6 );
expect_c_( sca->space == 4 );
// --------------------------------------------- try to view not existing pad
pad = view_pad_c( sca, 'X' );
expect_c_( is_empty_c_( pad ) );
expect_c_( sca->pos == 6 );
expect_c_( sca->space == 4 );
// ----------------------------------------------------------- view rest data
pad = view_pad_c( sca, 'a' );
expect_c_( chars_is_c( pad, "a" ) );
pad = view_pad_c( sca, '-' );
expect_c_( chars_is_c( pad, "---" ) );
expect_c_( sca->pos == 10 );
expect_c_( sca->space == 0 );
// -------------------------------------------------- try to view pad outside
pad = view_pad_c( sca, '-' );
expect_c_( is_empty_c_( pad ) );
return finish_tap_c_();
}
view_runes_c
cChars view_runes_c( cScanner sca[static 1], int64_t size );
Returns chars to view the memory of the scanner from the current position and moves sca forward. The function returns a empty slice if the scanner has not enough runes in the space to fill the slice.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cScanner* sca = &cstr_scanner_c_( "a 🥛🔑📊" );
// ------------------------------------------------------------- view 4 runes
cChars runes = view_runes_c( sca, 4 );
expect_c_( chars_is_c( runes,"a 🥛🔑" ) );
expect_c_( sca->pos == 10 );
expect_c_( sca->space == 4 );
// ------------------------------------------------------ try to view outside
runes = view_runes_c( sca, 2 );
expect_c_( is_empty_c_( runes ) );
expect_c_( sca->pos == 10 );
expect_c_( sca->space == 4 );
return finish_tap_c_();
}
scan
scan_byte_c
bool scan_byte_c( cScanner sca[static 1], cByte b[static 1] );
Scans a byte from the memory of the scanner. Returns true if the byte value can be written, otherwise false.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main()
{
init_tap_c_();
// ------------------------------------------------------------- init scanner
cBytes data = slice_c_( cByte, 0xab, 0xcd, 0xef );
cScanner* sca = &make_scanner_c_( data.s, data.v );
expect_c_( sca->pos == 0 );
expect_c_( sca->space == 3 );
expect_c_( is_empty_c_( scanned_bytes_c_( sca ) ) );
// --------------------------------------------------------------- scan bytes
cByte byte = 0x00;
int64_t len = 0;
len += scan_byte_c( sca, &byte );
expect_c_( byte == 0xab );
len += scan_byte_c( sca, &byte );
expect_c_( byte == 0xcd );
len += scan_byte_c( sca, &byte );
expect_c_( byte == 0xef );
expect_c_( len == 3 );
expect_c_( sca->pos == 3 );
expect_c_( sca->space == 0 );
// ------------------------------------------------- try to scan byte outside
len = scan_byte_c( sca, &byte );
expect_c_( len == 0 );
return finish_tap_c_();
}
scan_char_c
bool scan_char_c( cScanner sca[static 1], char c[static 1] );
Scans a char from the memory of the scanner. Returns true if the char value can be written, otherwise false.
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
// ------------------------------------------------------------- init scanner
cScanner* sca = &cstr_scanner_c_( "abcd" );
expect_c_( sca->pos == 0 );
expect_c_( sca->space == 4 );
expect_c_( is_empty_c_( scanned_bytes_c_( sca ) ) );
// --------------------------------------------------------------- scan chars
char c = ' ';
int64_t len = 0;
len += scan_char_c( sca, &c );
expect_c_( c == 'a' );
len += scan_char_c( sca, &c );
expect_c_( c == 'b' );
len += scan_char_c( sca, &c );
expect_c_( c == 'c' );
len += scan_char_c( sca, &c );
expect_c_( c == 'd' );
expect_c_( len == 4 );
expect_c_( sca->pos == 4 );
expect_c_( sca->space == 0 );
// ------------------------------------------------- try to scan char outside
len = scan_char_c( sca, &c );
expect_c_( len == 0 );
return finish_tap_c_();
}
scan_rune_c
bool scan_rune_c( cScanner sca[static 1], cRune r[static 1] );
Scans a rune from the memory of the scanner. Returns true if the rune value can be written, otherwise false.
#include "clingo/io/cRecorder.h"
#include "clingo/io/cScanner.h"
#include "clingo/lang/expect.h"
int main( void )
{
init_tap_c_();
cChars txt = c_c( "a ☀, no ☂" );
cRecorder* rec = &recorder_c_( 128 );
{
cScanner* sca = &make_scanner_c_( txt.s, txt.v );
int64_t count = 0;
cRune rune;
while ( scan_rune_c( sca, &rune ) )
{
++count;
record_rune_c( rec, rune );
}
expect_c_( count == 9 );
expect_c_( recorded_is_c( rec, "a ☀, no ☂" ) );
reset_recorder_c( rec );
}
{
// last rune not complete in slice
cScanner* sca = &make_scanner_c_( txt.s-1, txt.v );
int64_t count = 0;
cRune rune;
while ( scan_rune_c( sca, &rune ) )
{
++count;
record_rune_c( rec, rune );
}
expect_c_( count == 8 );
expect_c_( recorded_is_c( rec, "a ☀, no " ) );
reset_recorder_c( rec );
}
return finish_tap_c_();
}
scan_int8_c
bool scan_int8_c( cScanner sca[static 1], int8_t i8[static 1] );
Scans a int8_t from the memory of the scanner. Returns true if the int8_t value can be written, otherwise false.
scan_int16_c
bool scan_int16_c( cScanner sca[static 1], int16_t i16[static 1] );
Scans a int16_t from the memory of the scanner. Returns true if the int16_t value can be written, otherwise false.
scan_int32_c
bool scan_int32_c( cScanner sca[static 1], int32_t i32[static 1] );
Scans a int32_t from the memory of the scanner. Returns true if the int32_t value can be written, otherwise false.
scan_int64_c
bool scan_int64_c( cScanner sca[static 1], int64_t i64[static 1] );
Scans a int64_t from the memory of the scanner. Returns true if the int64_t value can be written, otherwise false.
scan_uint8_c
bool scan_uint8_c( cScanner sca[static 1], uint8_t u8[static 1] );
Scans a uint8_t from the memory of the scanner. Returns true if the uint8_t value can be written, otherwise false.
scan_uint16_c
bool scan_uint16_c( cScanner sca[static 1], uint16_t u16[static 1] );
Scans a uint16_t from the memory of the scanner. Returns true if the uint16_t value can be written, otherwise false.
scan_uint32_c
bool scan_uint32_c( cScanner sca[static 1], uint32_t u32[static 1] );
Scans a uint32_t from the memory of the scanner. Returns true if the uint32_t value can be written, otherwise false.
scan_uint64_c
bool scan_uint64_c( cScanner sca[static 1], uint64_t u64[static 1] );
Scans a uint64_t from the memory of the scanner. Returns true if the uint64_t value can be written, otherwise false.
scan_float_c
bool scan_float_c( cScanner sca[static 1], float f[static 1] );
Scans a float from the memory of the scanner. Returns true if the float value can be written, otherwise false.
scan_double_c
bool scan_double_c( cScanner sca[static 1], double d[static 1] );
Scans a double from the memory of the scanner. Returns true if the double value can be written, otherwise false.