mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-20 09:48:12 +02:00
Implement some of the things marked as to-do
This commit is contained in:
parent
771f78874e
commit
b7e3549d15
@ -110,7 +110,7 @@ bxstr_t *bxs_from_unicode(uint32_t *pInput)
|
|||||||
result->visible_char = (size_t *) realloc(result->visible_char, map_size * sizeof(size_t));
|
result->visible_char = (size_t *) realloc(result->visible_char, map_size * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_allowed_anywhere(c)) { /* CHECK currently used for config only, reconsider when using on input data */
|
if (!is_allowed_anywhere(c)) { /* currently used for config only, reconsider when using on input data */
|
||||||
bx_fprintf(stderr, "%s: illegal character '%lc' (%#010x) encountered in string\n", PROJECT, c, (int) c);
|
bx_fprintf(stderr, "%s: illegal character '%lc' (%#010x) encountered in string\n", PROJECT, c, (int) c);
|
||||||
bxs_free(result);
|
bxs_free(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
|
|
||||||
static pcre2_code *eol_pattern = NULL;
|
static pcre2_code *eol_pattern = NULL;
|
||||||
|
|
||||||
|
static pcre2_code *semver_pattern = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int check_sizes(pass_to_bison *bison_args)
|
static int check_sizes(pass_to_bison *bison_args)
|
||||||
@ -714,7 +716,7 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
|
|||||||
|
|
||||||
p = design_primary_name;
|
p = design_primary_name;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p < 32 || *p > 126) { // CHECK this check may be unnecessary due to lexer's ASCII_ID
|
if (*p < 32 || *p > 126) { /* CHECK this check may be unnecessary due to lexer's ASCII_ID */
|
||||||
yyerror(bison_args, "box design name must consist of printable standard ASCII characters.");
|
yyerror(bison_args, "box design name must consist of printable standard ASCII characters.");
|
||||||
return RC_ERROR;
|
return RC_ERROR;
|
||||||
}
|
}
|
||||||
@ -752,11 +754,12 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
|
|||||||
|
|
||||||
static int is_semantic_version(char *version)
|
static int is_semantic_version(char *version)
|
||||||
{
|
{
|
||||||
pcre2_code *version_pattern /* CHECK cache compiled pattern to speed up config file parsing */
|
if (semver_pattern == NULL) {
|
||||||
= compile_pattern("^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:[+-][a-zA-Z0-9\\.+-]+)?$");
|
/* Not a strict semver, "1" or "1.0" are accepted. */
|
||||||
int result = regex_match(version_pattern, version);
|
semver_pattern = compile_pattern(
|
||||||
pcre2_code_free(version_pattern);
|
"^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:[+-][a-zA-Z0-9\\.+-]+)?$");
|
||||||
return result;
|
}
|
||||||
|
return regex_match(semver_pattern, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
19
src/tools.c
19
src/tools.c
@ -369,7 +369,7 @@ void btrim(char *text, size_t *len)
|
|||||||
void btrim32(uint32_t *text, size_t *len)
|
void btrim32(uint32_t *text, size_t *len)
|
||||||
/*
|
/*
|
||||||
* Remove trailing whitespace from line (unicode and escape sequence enabled version).
|
* Remove trailing whitespace from line (unicode and escape sequence enabled version).
|
||||||
* TODO replace by bxs_rtrim() from bxstring module
|
* CHECK replace by bxs_rtrim() from bxstring module
|
||||||
*
|
*
|
||||||
* text string to trim
|
* text string to trim
|
||||||
* len pointer to the length of the string in characters
|
* len pointer to the length of the string in characters
|
||||||
@ -783,7 +783,7 @@ size_t array_count0(char **array)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *trimdup(char *s, char *e) // TODO consider removing, as we have bxs_trimdup()
|
char *trimdup(char *s, char *e)
|
||||||
{
|
{
|
||||||
if (s > e || (s == e && *s == '\0')) {
|
if (s > e || (s == e && *s == '\0')) {
|
||||||
return strdup("");
|
return strdup("");
|
||||||
@ -799,19 +799,10 @@ char *trimdup(char *s, char *e) // TODO consider removing, as we have bxs_trimd
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int tag_is_valid(char *tag) // TODO replace with is_ascii_id(strict)
|
int tag_is_valid(char *tag)
|
||||||
{
|
{
|
||||||
if (tag == NULL) {
|
pcre2_code *pattern = get_pattern_ascii_id(1);
|
||||||
return 0;
|
return regex_match(pattern, tag);
|
||||||
}
|
|
||||||
|
|
||||||
const size_t len = strlen(tag);
|
|
||||||
return len > 0
|
|
||||||
&& strspn(tag, "abcdefghijklmnopqrstuvwxyz-0123456789") == len
|
|
||||||
&& strchr("abcdefghijklmnopqrstuvwxyz", tag[0]) != NULL
|
|
||||||
&& tag[len - 1] != '-'
|
|
||||||
&& strstr(tag, "--") == NULL
|
|
||||||
&& strcmp(tag, "none") != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user