mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 22:11:07 +01: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));
|
||||
}
|
||||
|
||||
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);
|
||||
bxs_free(result);
|
||||
return NULL;
|
||||
|
@ -41,6 +41,8 @@
|
||||
|
||||
static pcre2_code *eol_pattern = NULL;
|
||||
|
||||
static pcre2_code *semver_pattern = NULL;
|
||||
|
||||
|
||||
|
||||
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;
|
||||
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.");
|
||||
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)
|
||||
{
|
||||
pcre2_code *version_pattern /* CHECK cache compiled pattern to speed up config file parsing */
|
||||
= compile_pattern("^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:[+-][a-zA-Z0-9\\.+-]+)?$");
|
||||
int result = regex_match(version_pattern, version);
|
||||
pcre2_code_free(version_pattern);
|
||||
return result;
|
||||
if (semver_pattern == NULL) {
|
||||
/* Not a strict semver, "1" or "1.0" are accepted. */
|
||||
semver_pattern = compile_pattern(
|
||||
"^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:[+-][a-zA-Z0-9\\.+-]+)?$");
|
||||
}
|
||||
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)
|
||||
/*
|
||||
* 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
|
||||
* 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')) {
|
||||
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) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
pcre2_code *pattern = get_pattern_ascii_id(1);
|
||||
return regex_match(pattern, tag);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user