diff --git a/src/discovery.c b/src/discovery.c index 29cccab..ad6b740 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -208,7 +208,7 @@ static char *locate_config_common(int *error_printed) } #ifdef DISCOVERY_DEBUG - fprintf(stderr, "locate_config_common() - exit -> [%s]\n", result); + fprintf(stderr, "locate_config_common() - exit -> [%s]\n", result != NULL ? result : "(null)"); #endif return result; } diff --git a/src/list.c b/src/list.c index 0ed00f9..dee046d 100644 --- a/src/list.c +++ b/src/list.c @@ -166,15 +166,17 @@ static void print_tags(tagstats_t *tagstats, size_t num_tags) -static bxstr_t *escape(const bxstr_t *org, const int pLength) +static bxstr_t *escape(bxstr_t *org) { const ucs4_t char_backslash = to_utf32('\\'); const ucs4_t char_quote = to_utf32('"'); uint32_t *temp = (uint32_t *) calloc(2 * org->num_chars + 1, sizeof(uint32_t)); - int orgIdx, resultIdx; - for (orgIdx = 0, resultIdx = 0; orgIdx < pLength; ++orgIdx, ++resultIdx) { - if (is_char_at(org->memory, orgIdx, char_backslash) || is_char_at(org->memory, orgIdx, char_quote)) { + size_t orgIdx, resultIdx; + for (orgIdx = 0, resultIdx = 0; orgIdx < org->num_chars; ++orgIdx, ++resultIdx) { + if ((is_char_at(org->memory, orgIdx, char_backslash) || is_char_at(org->memory, orgIdx, char_quote)) + && bxs_is_visible_char(org, orgIdx)) + { set_char_at(temp, resultIdx++, char_backslash); } set_char_at(temp, resultIdx, org->memory[orgIdx]); @@ -336,7 +338,7 @@ static void print_design_details(design_t *d) continue; } for (size_t w = 0; w < d->shape[i].height; ++w) { - bxstr_t *escaped_line = escape(d->shape[i].mbcs[w], d->shape[i].width); + bxstr_t *escaped_line = escape(d->shape[i].mbcs[w]); fprintf(opt.outfile, "%-24s%3s%c \"%s\"%c%s", (first_shape == 1 && w == 0 ? "Defined Shapes:" : ""), (w == 0 ? shape_name[i] : ""), (w == 0 ? ':' : ' '), diff --git a/test/175_utf8_happy_design_info.cfg b/test/175_utf8_happy_design_info.cfg new file mode 100644 index 0000000..c38d2ae --- /dev/null +++ b/test/175_utf8_happy_design_info.cfg @@ -0,0 +1,49 @@ +# This config contains UTF-8-encoded elements used correctly, and a simple colored box design. + +BOX designA + +author "ๆฒๅฎธ" # in a value + +designer "John Doe" + +๐•‚๐•–๐•ช๐•จ๐• ๐•ฃ๐•• "value" # in a keyword +Mix๐•–๐•• "value" + +sample + โ”โ” ๆฒๅฎธ ่‹ฅๆฑ โ”โ”“ + โ”ƒ โงน + โ”ƒ โ•ฑ + โ”—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”› +ends + +# Monochrome sample (with UTF-8): +# โ”โ” ๆฒๅฎธ ่‹ฅๆฑ โ”โ”“ +# โ”ƒ โงน +# โ”ƒ โ•ฑ +# โ”—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”› + +shapes { + n (" ๆฒๅฎธ ่‹ฅๆฑ ") + nw ("โ”") + nnw ("โ”") + nne ("โ”") + ne ("โ”“") + e ("โ”ƒ") + w ("โงน", "โ•ฑ") + se ("โ”—") + s ("โ”") + sw ("โ”›") +} + +elastic ( + nnw, nne, e, w, s +) + +padding { + horiz 1 +} + +replace "รค" with "รถ" +reverse "รถ" to "รค" + +END designA diff --git a/test/175_utf8_happy_design_info.txt b/test/175_utf8_happy_design_info.txt new file mode 100644 index 0000000..693d147 --- /dev/null +++ b/test/175_utf8_happy_design_info.txt @@ -0,0 +1,33 @@ +:ARGS +-f 175_utf8_happy_design_info.cfg -d designA -l +:INPUT +:OUTPUT-FILTER +:EXPECTED +Complete Design Information for "designA": +------------------------------------------ +Alias Names: none +Author: ๆฒๅฎธ +Original Designer: John Doe +Creation Date: (unknown) +Current Revision: (unknown) +Configuration File: 175_utf8_happy_design_info.cfg +Indentation Mode: box (indent box) +Replacement Rules: 1. (glob) "รค" WITH "รถ" +Reversion Rules: 1. (glob) "รถ" TO "รค" +Minimum Box Dimensions: 15 x 4 (width x height) +Default Padding: left 1, right 1 +Default Killblank: yes +Tags: none +Elastic Shapes: NNW, NNE, E, S, W +Defined Shapes: NW: "โ”" + NNW: "โ”" + N: " ๆฒๅฎธ ่‹ฅๆฑ " + NNE: "โ”" + NE: "โ”“" + E: "โ”ƒ" + SE: "โ”—" + S: "โ”" + SW: "โ”›" + W: "โงน", + "โ•ฑ" +:EOF