Added ASCII special sign enum and conversion from rune.

This commit is contained in:
Eric-Paul Ickhorn 2023-12-31 08:37:50 +01:00
parent 6e156438c1
commit e901acfdb4
Signed by: epickh
GPG Key ID: F5EBBE013924D95F
6 changed files with 150 additions and 0 deletions

View File

@ -6,6 +6,7 @@ GCC_ARGUMENTS="-std=c11 -Wall"
MODULES=( MODULES=(
"core" "core"
"json"
) )
# Arguments: # Arguments:

View File

@ -4,6 +4,45 @@
#include <librr/types.h> #include <librr/types.h>
typedef enum
{
RR_ASCII_EXCLAMATION_MARK,
RR_ASCII_DOUBLE_QUOTATION_MARK,
RR_ASCII_HASH_SIGN,
RR_ASCII_DOLLAR_SIGN,
RR_ASCII_PERCENT_SIGN,
RR_ASCII_AMPERSAND,
RR_ASCII_SINGLE_QUOTATION_MARK,
RR_ASCII_OPENING_PARENTHESIS,
RR_ASCII_CLOSING_PARENTHESIS,
RR_ASCII_ASTERISK,
RR_ASCII_PLUS,
RR_ASCII_COMMA,
RR_ASCII_MINUS,
RR_ASCII_POINT,
RR_ASCII_SLASH,
RR_ASCII_COLON,
RR_ASCII_SEMICOLON,
RR_ASCII_SMALLER_THAN,
RR_ASCII_EQUALS_SIGN,
RR_ASCII_BIGGER_THAN,
RR_ASCII_QUESTION_MARK,
RR_ASCII_AT_SIGN,
RR_ASCII_OPENING_SQUARE_BRACKET,
RR_ASCII_BACKSLASH,
RR_ASCII_CLOSING_SQUARE_BRACKET,
RR_ASCII_CIRCUMFLEX,
RR_ASCII_UNDERSCORE,
RR_ASCII_TICK,
RR_ASCII_OPENING_CURLY_BRACE,
RR_ASCII_VERTICAL_BAR,
RR_ASCII_CLOSING_CURLY_BRACE,
RR_ASCII_TILDE,
RR_ASCII_NOT_A_SIGN
} rr_ascii_sign_e;
/// @brief Extracts an UTF-8 rune at a given offset in a string and ADDS the length /// @brief Extracts an UTF-8 rune at a given offset in a string and ADDS the length
/// of the rune to the number pointed to by 'increase'. /// of the rune to the number pointed to by 'increase'.
/// @param string The string to get the data from. For safety reasons, this should be null-terminated. /// @param string The string to get the data from. For safety reasons, this should be null-terminated.
@ -49,4 +88,6 @@ bool_t rr_rune_is_digit(rune_t rune);
/// @return Whether the rune is of one of the four ASCII sign ranges. /// @return Whether the rune is of one of the four ASCII sign ranges.
bool_t rr_rune_is_ascii_special(rune_t rune); bool_t rr_rune_is_ascii_special(rune_t rune);
rr_ascii_sign_e rr_rune_to_ascii_sign(rune_t rune);
#endif // LIBRR_RUNES_H #endif // LIBRR_RUNES_H

View File

@ -171,3 +171,43 @@ bool_t rr_rune_is_ascii_special(rune_t rune)
if(rr_rune_is_in_ascii_special_block_4(rune)) return TRUE; if(rr_rune_is_in_ascii_special_block_4(rune)) return TRUE;
return FALSE; return FALSE;
} }
rr_ascii_sign_e rr_rune_to_ascii_sign(rune_t rune)
{
switch(rune)
{
case '!': return RR_ASCII_EXCLAMATION_MARK;
case '"': return RR_ASCII_DOUBLE_QUOTATION_MARK;
case '#': return RR_ASCII_HASH_SIGN;
case '$': return RR_ASCII_DOLLAR_SIGN;
case '%': return RR_ASCII_PERCENT_SIGN;
case '&': return RR_ASCII_AMPERSAND;
case '\'': return RR_ASCII_SINGLE_QUOTATION_MARK;
case '(': return RR_ASCII_OPENING_PARENTHESIS;
case ')': return RR_ASCII_CLOSING_PARENTHESIS;
case '*': return RR_ASCII_ASTERISK;
case '+': return RR_ASCII_PLUS;
case ',': return RR_ASCII_COMMA;
case '-': return RR_ASCII_MINUS;
case '.': return RR_ASCII_POINT;
case '/': return RR_ASCII_SLASH;
case ':': return RR_ASCII_COLON;
case ';': return RR_ASCII_SEMICOLON;
case '<': return RR_ASCII_SMALLER_THAN;
case '=': return RR_ASCII_EQUALS_SIGN;
case '>': return RR_ASCII_BIGGER_THAN;
case '?': return RR_ASCII_QUESTION_MARK;
case '@': return RR_ASCII_AT_SIGN;
case '[': return RR_ASCII_OPENING_SQUARE_BRACKET;
case '\\': return RR_ASCII_BACKSLASH;
case ']': return RR_ASCII_CLOSING_SQUARE_BRACKET;
case '^': return RR_ASCII_CIRCUMFLEX;
case '_': return RR_ASCII_UNDERSCORE;
case '`': return RR_ASCII_TICK;
case '{': return RR_ASCII_OPENING_CURLY_BRACE;
case '|': return RR_ASCII_VERTICAL_BAR;
case '}': return RR_ASCII_CLOSING_CURLY_BRACE;
case '~': return RR_ASCII_TILDE;
}
return RR_ASCII_NOT_A_SIGN;
}

62
ini/inc/parser.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef RR_INI_PARSER_H
#define RR_INI_PARSER_H
#include <librr/types.h>
typedef struct rr_ini_section rr_ini_section_s;
typedef struct rr_ini_field rr_ini_field_s;
typedef enum
{
RR_INI_VALUE_INVALID,
RR_INI_VALUE_REAL,
RR_INI_VALUE_NUMBER,
RR_INI_VALUE_STRING,
RR_INI_VALUE_IPV4,
RR_INI_VALUE_IPV6,
RR_INI_VALUE_ARBITRARY
} rr_ini_value_e;
struct rr_ini_section
{
/// @brief The last part of the name of this section. If this is a subsection, this only is the name
/// of the subsection, not including the name of the section this section is contained in.
char *last_name;
usz_t num_fields;
rr_ini_field_s *fields;
};
struct rr_ini_value
{
rr_ini_value_e type;
union rr_ini_value_specifics
{
double real;
long number;
char *string;
struct rr_ini_ipv4_value
{
u8_t values[4];
} ipv4;
struct rr_ini_ipv4_value
{
u8_t values[16];
} ipv6;
struct rr_ini_arbitrary_value
{
char *
} arbitrary;
} specifics;
};
struct rr_ini_field
{
char *name;
};
#endif // RR_INI_PARSER

3
ini/src-c/parser.c Normal file
View File

@ -0,0 +1,3 @@
#include <parser.h>

3
ini/src-c/tokenizer.c Normal file
View File

@ -0,0 +1,3 @@
#include <parser.h>