Separate rjp format flags into multiple for slightly more control over output formatting

This commit is contained in:
rexy712 2020-04-06 12:35:47 -07:00
parent e6950db87c
commit 7b643ff5c6
9 changed files with 159 additions and 187 deletions

View File

@ -61,7 +61,11 @@ extern "C"{
typedef enum RJP_format_flag{
RJP_FORMAT_NONE = 0,
RJP_FORMAT_PRETTY = 1
RJP_FORMAT_KEY_SPACES = 1,
RJP_FORMAT_NEWLINES = 2,
RJP_FORMAT_TABBED_LINES = RJP_FORMAT_NEWLINES | 4,
RJP_FORMAT_COMMA_SPACES = 8,
RJP_FORMAT_PRETTY = RJP_FORMAT_KEY_SPACES | RJP_FORMAT_NEWLINES | RJP_FORMAT_TABBED_LINES
}RJP_format_flag;
typedef enum RJP_parse_flag{

View File

@ -33,6 +33,6 @@ typedef struct RJP_array{
void irjp_add_element(RJP_array* j);
void irjp_copy_array(RJP_value* dest, const RJP_value* src);
RJP_index rjp_dump_array(const RJP_value* arr, char* dest);
RJP_index irjp_dump_array(const RJP_value* arr, char* dest, const int flags, int depth);
#endif

View File

@ -26,6 +26,6 @@
void irjp_copy_object(RJP_value* dest, const RJP_value* src);
void irjp_delete_object(RJP_value* obj);
RJP_index rjp_dump_object(const RJP_value* root, char* dest);
RJP_index irjp_dump_object(const RJP_value* root, char* dest, const int flags, int depth);
#endif

View File

@ -23,10 +23,9 @@
int irjp_is_whitespace(char c);
char* irjp_convert_string(const char* str, RJP_index length, RJP_index* newlen);
RJP_index irjp_array_strlen(const RJP_value* arr);
RJP_index irjp_object_strlen(const RJP_value* root);
RJP_index irjp_value_strlen(const RJP_value* root);
RJP_index irjp_value_strlen_pretty(const RJP_value* root, int depth);
RJP_index irjp_array_strlen(const RJP_value* arr, const int flags, int depth);
RJP_index irjp_object_strlen(const RJP_value* root, const int flags, int depth);
RJP_index irjp_value_strlen(const RJP_value* root, const int flags, int depth);
void irjp_strcpy(RJP_string* dest, const RJP_string* src);
#endif

View File

@ -158,7 +158,7 @@ int run_test(int (*fun)(const char*,RJP_parse_flag)){
}
}
fprintf(stderr, "\n");
printf("Running %d tests that should fail...\n", should_fail_cnt);
fprintf(stderr, "Running %d tests that should fail...\n", should_fail_cnt);
for(unsigned i = 0;i < sizeof(should_fail_strings)/sizeof(should_fail_strings[0]);++i){
fprintf(stderr, "%8d) ", i+1);
if(fun(should_fail_strings[i].str, should_fail_strings[i].flags)){

View File

@ -152,7 +152,7 @@ RJP_value* rjp_set_array(RJP_value* v){
return v;
}
static RJP_index irjp_write_value(char* dest, const RJP_value* val){
static RJP_index irjp_write_value(char* dest, const RJP_value* val, const int flags, int depth){
RJP_index ret;
switch(val->type){
case rjp_json_integer:
@ -171,11 +171,11 @@ static RJP_index irjp_write_value(char* dest, const RJP_value* val){
ret = sprintf(dest, "\"%s\"", val->string.value);
break;
case rjp_json_array:
ret = rjp_dump_array(val, dest);
ret = irjp_dump_array(val, dest, flags, depth);
break;
case rjp_json_object:
case rjp_json_ordered_object:
ret = rjp_dump_object(val, dest);
ret = irjp_dump_object(val, dest, flags, depth);
break;
default:
ret = 0;
@ -183,11 +183,11 @@ static RJP_index irjp_write_value(char* dest, const RJP_value* val){
};
return ret;
}
static RJP_index irjp_write_value_pretty(char* dest, const RJP_value* val, int depth);
static RJP_index irjp_dump_array_pretty(const RJP_value* arr, char* dest, int depth){
RJP_index irjp_dump_array(const RJP_value* arr, char* dest, const int flags, int depth){
RJP_index pos = 0;
RJP_array_iterator it;
rjp_init_array_iterator(&it, arr);
RJP_index pos = 0;
RJP_value* current = rjp_array_iterator_current(&it);
if(!current){
@ -195,136 +195,87 @@ static RJP_index irjp_dump_array_pretty(const RJP_value* arr, char* dest, int de
rjp_delete_array_iterator(&it);
return pos;
}
pos += sprintf(dest+pos, "[\n");
dest[pos++] = '[';
if(flags & RJP_FORMAT_NEWLINES)
dest[pos++] = '\n';
for(;current;current = rjp_array_iterator_next(&it)){
for(int i = 0;i < (depth+1);++i)
pos += sprintf(dest+pos, "\t");
pos += irjp_write_value_pretty(dest+pos, current, depth+1);
if(flags & RJP_FORMAT_TABBED_LINES)
for(int i = 0;i < (depth+1);++i)
dest[pos++] = '\t';
pos += irjp_write_value(dest+pos, current, flags, depth+1);
if(rjp_array_iterator_peek(&it))
pos += sprintf(dest+pos, ",");
pos += sprintf(dest+pos, "\n");
if(rjp_array_iterator_peek(&it)){
dest[pos++] = ',';
if(flags & RJP_FORMAT_COMMA_SPACES)
dest[pos++] = ' ';
}
if(flags & RJP_FORMAT_NEWLINES)
dest[pos++] = '\n';
}
for(int i = 0;i < depth;++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "]");
rjp_delete_array_iterator(&it);
if(flags & RJP_FORMAT_TABBED_LINES)
for(int i = 0;i < depth;++i)
dest[pos++] = '\t';
dest[pos++] = ']';
dest[pos] = 0;
return pos;
}
static RJP_index irjp_dump_object_pretty(const RJP_value* root, char* dest, int depth){
RJP_index irjp_dump_object(const RJP_value* root, char* dest, const int flags, int depth){
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
RJP_index pos = 0;
RJP_value* current = rjp_object_iterator_current(&it);
if(!current){
pos += sprintf(dest+pos, "{}");
pos += sprintf(dest, "{}");
rjp_delete_object_iterator(&it);
return pos;
}
pos += sprintf(dest, "{\n");
dest[pos++] = '{';
if(flags & RJP_FORMAT_NEWLINES)
dest[pos++] = '\n';
for(;current;current = rjp_object_iterator_next(&it)){
for(int i = 0;i < (depth+1);++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "\"%s\": ", rjp_member_key(current)->value);
pos += irjp_write_value_pretty(dest+pos, current, depth+1);
if(rjp_object_iterator_peek(&it))
pos += sprintf(dest+pos, ",");
pos += sprintf(dest+pos, "\n");
}
for(int i = 0;i < depth;++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "}");
rjp_delete_object_iterator(&it);
return pos;
}
static RJP_index irjp_write_value_pretty(char* dest, const RJP_value* val, int depth){
RJP_index ret;
switch(val->type){
case rjp_json_integer:
ret = sprintf(dest, "%" PRId64, val->integer);
break;
case rjp_json_dfloat:
ret = sprintf(dest, "%lf", val->dfloat);
break;
case rjp_json_boolean:
ret = sprintf(dest, val->boolean ? "true" : "false");
break;
case rjp_json_null:
ret = sprintf(dest, "null");
break;
case rjp_json_string:;
ret = sprintf(dest, "\"%s\"", val->string.value);
break;
case rjp_json_array:
ret = irjp_dump_array_pretty(val, dest, depth);
break;
case rjp_json_object:
case rjp_json_ordered_object:
ret = irjp_dump_object_pretty(val, dest, depth);
break;
default:
ret = 0;
break;
};
return ret;
}
RJP_index rjp_dump_array(const RJP_value* arr, char* dest){
RJP_array_iterator it;
rjp_init_array_iterator(&it, arr);
RJP_index pos = 1;
sprintf(dest, "[");
for(RJP_value* current = rjp_array_iterator_current(&it);current;current = rjp_array_iterator_next(&it)){
pos += irjp_write_value(dest+pos, current);
if(rjp_array_iterator_peek(&it))
pos += sprintf(dest+pos, ",");
else
break;
}
pos += sprintf(dest+pos, "]");
rjp_delete_array_iterator(&it);
return pos;
}
RJP_index rjp_dump_object(const RJP_value* root, char* dest){
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
RJP_index pos = 1;
sprintf(dest, "{");
for(RJP_value* current = rjp_object_iterator_current(&it);current;current = rjp_object_iterator_next(&it)){
if(flags & RJP_FORMAT_TABBED_LINES)
for(int i = 0;i < (depth+1);++i)
dest[pos++] = '\t';
pos += sprintf(dest+pos, "\"%s\":", rjp_member_key(current)->value);
pos += irjp_write_value(dest+pos, current);
if(flags & RJP_FORMAT_KEY_SPACES)
dest[pos++] = ' ';
pos += irjp_write_value(dest+pos, current, flags, depth+1);
if(rjp_object_iterator_peek(&it))
pos += sprintf(dest+pos, ",");
else
break;
if(rjp_object_iterator_peek(&it)){
dest[pos++] = ',';
if(flags & RJP_FORMAT_COMMA_SPACES)
dest[pos++] = ' ';
}
if(flags & RJP_FORMAT_NEWLINES)
dest[pos++] = '\n';
}
pos += sprintf(dest+pos, "}");
rjp_delete_object_iterator(&it);
if(flags & RJP_FORMAT_TABBED_LINES)
for(int i = 0;i < depth;++i)
dest[pos++] = '\t';
dest[pos++] = '}';
dest[pos] = 0;
return pos;
}
char* rjp_to_json(const RJP_value* root, int pretty){
char* rjp_to_json(const RJP_value* root, const int flags){
if(!root)
return NULL;
RJP_index len = pretty ? irjp_value_strlen_pretty(root, 0) : irjp_value_strlen(root);
RJP_index len = irjp_value_strlen(root, flags, 0);
if(!len)
return NULL;
char* tmp = rjp_alloc(len + 1);
tmp[len] = 0;
if(pretty)
irjp_write_value_pretty(tmp, root, 0);
else
irjp_write_value(tmp, root);
irjp_write_value(tmp, root, flags, 0);
return tmp;
}

View File

@ -297,78 +297,63 @@ RJP_string rjp_escape(const char* src){
rjp_escape_strcpy(dest, src);
return (RJP_string){.value = dest, .length = esclen};
}
RJP_index irjp_array_strlen(const RJP_value* arr){
RJP_index irjp_array_strlen(const RJP_value* arr, const int flags, int depth){
RJP_index count = 2; //[]
RJP_array_iterator it;
rjp_init_array_iterator(&it, arr);
for(RJP_value* current = rjp_array_iterator_current(&it);current;current = rjp_array_iterator_next(&it)){
count += irjp_value_strlen(current);
if(rjp_array_iterator_peek(&it))
++count; //,
}
return count;
}
RJP_index irjp_array_strlen_pretty(const RJP_value* arr, int depth){
RJP_index count = 3 + depth; //[\n\t]
if(flags & RJP_FORMAT_NEWLINES)
++count;
if(flags & RJP_FORMAT_TABBED_LINES)
count += depth;
++depth;
RJP_array_iterator it;
rjp_init_array_iterator(&it, arr);
for(RJP_value* current = rjp_array_iterator_current(&it);current;current = rjp_array_iterator_next(&it)){
count += irjp_value_strlen_pretty(current, depth);
count += depth; //tabs
++count; //newline
if(rjp_array_iterator_peek(&it))
count += irjp_value_strlen(current, flags, depth);
if(flags & RJP_FORMAT_NEWLINES)
++count;
if(flags & RJP_FORMAT_TABBED_LINES)
count += depth;
if(rjp_array_iterator_peek(&it)){
++count; //,
if(flags & RJP_FORMAT_COMMA_SPACES)
++count; //space
}
}
return count;
}
RJP_index irjp_object_strlen(const RJP_value* root){
RJP_index irjp_object_strlen(const RJP_value* root, const int flags, int depth){
RJP_index count = 2; //{}
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
RJP_value* current = rjp_object_iterator_current(&it);
while(current){
RJP_index namelen = rjp_member_key(current)->length;
const char* name = rjp_member_key(current)->value;
if(namelen == 0 || name[0] == 0){
rjp_delete_object_iterator(&it);
return 0;
}
count += namelen + 3; //"":
count += irjp_value_strlen(current);
if((current = rjp_object_iterator_next(&it)))
++count; //,
}
rjp_delete_object_iterator(&it);
return count;
}
RJP_index irjp_object_strlen_pretty(const RJP_value* root, int depth){
RJP_index count = 3 + depth; //{\n\t}
if(flags & RJP_FORMAT_NEWLINES)
++count;
if(flags & RJP_FORMAT_TABBED_LINES)
count += depth;
++depth;
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
RJP_value* current = rjp_object_iterator_current(&it);
while(current){
RJP_index namelen = rjp_member_key(current)->length;
const char* name = rjp_member_key(current)->value;
if(namelen == 0 || name[0] == 0){
rjp_delete_object_iterator(&it);
return 0;
}
count += namelen + 4; //"":space
count += irjp_value_strlen_pretty(current, depth);
count += depth; //tabs
++count; //newline
if((current = rjp_object_iterator_next(&it)))
count += namelen + 3; //"":
if(flags & RJP_FORMAT_KEY_SPACES)
++count;
count += irjp_value_strlen(current, flags, depth);
if(flags & RJP_FORMAT_NEWLINES)
++count;
if(flags & RJP_FORMAT_TABBED_LINES)
count += depth;
if((current = rjp_object_iterator_next(&it))){
++count; //,
if(flags & RJP_FORMAT_COMMA_SPACES)
++count; //space
}
}
rjp_delete_object_iterator(&it);
return count;
}
RJP_index irjp_value_strlen(const RJP_value* root){
RJP_index irjp_value_strlen(const RJP_value* root, const int flags, int depth){
switch(root->type){
case rjp_json_integer:
return snprintf(NULL, 0, "%" PRId64, root->integer);
@ -379,33 +364,12 @@ RJP_index irjp_value_strlen(const RJP_value* root){
case rjp_json_null:
return 4;
case rjp_json_string:
return rjp_escape_strlen(root->string.value) + 2; //"";
return rjp_escape_strlen(root->string.value) + 2; //""
case rjp_json_array:
return irjp_array_strlen(root);
return irjp_array_strlen(root, flags, depth);
case rjp_json_object:
case rjp_json_ordered_object:
return irjp_object_strlen(root);
default:
return 0;
};
}
RJP_index irjp_value_strlen_pretty(const RJP_value* root, int depth){
switch(root->type){
case rjp_json_integer:
return snprintf(NULL, 0, "%" PRId64, root->integer);
case rjp_json_dfloat:
return snprintf(NULL, 0, "%lf", root->dfloat);
case rjp_json_boolean:
return root->boolean ? 4 : 5; //true, false
case rjp_json_null:
return 4;
case rjp_json_string:
return rjp_escape_strlen(root->string.value) + 2; //"";
case rjp_json_array:
return irjp_array_strlen_pretty(root, depth);
case rjp_json_object:
case rjp_json_ordered_object:
return irjp_object_strlen_pretty(root, depth);
return irjp_object_strlen(root, flags, depth);
default:
return 0;
};

View File

@ -237,6 +237,60 @@ static test_pair tests[] = {
{case_24, "{\"key\":{\"subkey\":false,\"subkey2\":true}}", RJP_FORMAT_NONE},
{case_25, "{\"key\":{\"subkey2\":true,\"subkey\":false}}", RJP_FORMAT_NONE},
{case_8, "{\"key\":7}", RJP_FORMAT_COMMA_SPACES},
{case_10, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_11, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_12, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_13, "{\"key\":{\"subkey2\":true, \"subkey\":false}}", RJP_FORMAT_COMMA_SPACES},
{case_14, "[5]", RJP_FORMAT_COMMA_SPACES},
{case_16, "[[false, true]]", RJP_FORMAT_COMMA_SPACES},
{case_17, "[5, [false, true]]", RJP_FORMAT_COMMA_SPACES},
{case_18, "[5, {\"key\":[false]}]", RJP_FORMAT_COMMA_SPACES},
{case_19, "[5, {\"key0\":true, \"key1\":false, \"key2\":true, \"key3\":false, \"key4\":true, \"key5\":false, \"key6\":true, \"key7\":false, \"key8\":true, \"key9\":false}]", RJP_FORMAT_COMMA_SPACES},
{case_20, "[5, {\"key9\":true, \"key8\":false, \"key7\":true, \"key6\":false, \"key5\":true, \"key4\":false, \"key3\":true, \"key2\":false, \"key1\":true, \"key0\":false}]", RJP_FORMAT_COMMA_SPACES},
{case_21, "{\"arr\":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}", RJP_FORMAT_COMMA_SPACES},
{case_22, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_23, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_24, "{\"key\":{\"subkey\":false, \"subkey2\":true}}", RJP_FORMAT_COMMA_SPACES},
{case_25, "{\"key\":{\"subkey2\":true, \"subkey\":false}}", RJP_FORMAT_COMMA_SPACES},
{case_8, "{\"key\": 7}", RJP_FORMAT_KEY_SPACES},
{case_9, "{\"key\": {\"subkey\": false}}", RJP_FORMAT_KEY_SPACES},
{case_10, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_11, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_12, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_13, "{\"key\": {\"subkey2\": true,\"subkey\": false}}", RJP_FORMAT_KEY_SPACES},
{case_18, "[5,{\"key\": [false]}]", RJP_FORMAT_KEY_SPACES},
{case_19, "[5,{\"key0\": true,\"key1\": false,\"key2\": true,\"key3\": false,\"key4\": true,\"key5\": false,\"key6\": true,\"key7\": false,\"key8\": true,\"key9\": false}]", RJP_FORMAT_KEY_SPACES},
{case_20, "[5,{\"key9\": true,\"key8\": false,\"key7\": true,\"key6\": false,\"key5\": true,\"key4\": false,\"key3\": true,\"key2\": false,\"key1\": true,\"key0\": false}]", RJP_FORMAT_KEY_SPACES},
{case_21, "{\"arr\": [0,1,2,3,4,5,6,7,8,9]}", RJP_FORMAT_KEY_SPACES},
{case_22, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_23, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_24, "{\"key\": {\"subkey\": false,\"subkey2\": true}}", RJP_FORMAT_KEY_SPACES},
{case_25, "{\"key\": {\"subkey2\": true,\"subkey\": false}}", RJP_FORMAT_KEY_SPACES},
{case_5, "{}", RJP_FORMAT_TABBED_LINES},
{case_6, "[]", RJP_FORMAT_TABBED_LINES},
{case_7, "{}", RJP_FORMAT_TABBED_LINES},
{case_8, "{\n\t\"key\":7\n}", RJP_FORMAT_TABBED_LINES},
{case_9, "{\n\t\"key\":{\n\t\t\"subkey\":false\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_10, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_11, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_12, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_13, "{\n\t\"key\":{\n\t\t\"subkey2\":true,\n\t\t\"subkey\":false\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_14, "[\n\t5\n]", RJP_FORMAT_TABBED_LINES},
{case_15, "[\n\t[\n\t\tfalse\n\t]\n]", RJP_FORMAT_TABBED_LINES},
{case_16, "[\n\t[\n\t\tfalse,\n\t\ttrue\n\t]\n]", RJP_FORMAT_TABBED_LINES},
{case_17, "[\n\t5,\n\t[\n\t\tfalse,\n\t\ttrue\n\t]\n]", RJP_FORMAT_TABBED_LINES},
{case_18, "[\n\t5,\n\t{\n\t\t\"key\":[\n\t\t\tfalse\n\t\t]\n\t}\n]", RJP_FORMAT_TABBED_LINES},
{case_19, "[\n\t5,\n\t{\n\t\t\"key0\":true,\n\t\t\"key1\":false,\n\t\t\"key2\":true,\n\t\t\"key3\":false,\n\t\t\"key4\":true,\n\t\t\"key5\":false,\n\t\t\"key6\":true,\n\t\t\"key7\":false,\n\t\t\"key8\":true,\n\t\t\"key9\":false\n\t}\n]", RJP_FORMAT_TABBED_LINES},
{case_20, "[\n\t5,\n\t{\n\t\t\"key9\":true,\n\t\t\"key8\":false,\n\t\t\"key7\":true,\n\t\t\"key6\":false,\n\t\t\"key5\":true,\n\t\t\"key4\":false,\n\t\t\"key3\":true,\n\t\t\"key2\":false,\n\t\t\"key1\":true,\n\t\t\"key0\":false\n\t}\n]", RJP_FORMAT_TABBED_LINES},
{case_21, "{\n\t\"arr\":[\n\t\t0,\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4,\n\t\t5,\n\t\t6,\n\t\t7,\n\t\t8,\n\t\t9\n\t]\n}", RJP_FORMAT_TABBED_LINES},
{case_22, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_23, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_24, "{\n\t\"key\":{\n\t\t\"subkey\":false,\n\t\t\"subkey2\":true\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_25, "{\n\t\"key\":{\n\t\t\"subkey2\":true,\n\t\t\"subkey\":false\n\t}\n}", RJP_FORMAT_TABBED_LINES},
{case_1, "null", RJP_FORMAT_PRETTY},
{case_2, "5", RJP_FORMAT_PRETTY},
{case_3, "true", RJP_FORMAT_PRETTY},

View File

@ -183,7 +183,7 @@ int run_test(int (*fun)(const char*,RJP_parse_flag)){
}
}
fprintf(stderr, "\n");
printf("Running %d tests that should fail...\n", should_fail_cnt);
fprintf(stderr, "Running %d tests that should fail...\n", should_fail_cnt);
for(unsigned i = 0;i < sizeof(should_fail_strings)/sizeof(should_fail_strings[0]);++i){
fprintf(stderr, "%8d) ", i+1);
if(fun(should_fail_strings[i].str, should_fail_strings[i].flags)){