| 1 |
|
| /* |
| 2 |
|
| * eshu_java.h — Java language indentation scanner |
| 3 |
|
| * |
| 4 |
|
| * Tracks {} nesting depth while skipping strings, text blocks, |
| 5 |
|
| * char literals, and comments. Handles switch case labels (both |
| 6 |
|
| * classic 'case X:' and arrow 'case X ->'). |
| 7 |
|
| * |
| 8 |
|
| * Pure C, no Perl dependencies, header-only. |
| 9 |
|
| */ |
| 10 |
|
| |
| 11 |
|
| #ifndef ESHU_JAVA_H |
| 12 |
|
| #define ESHU_JAVA_H |
| 13 |
|
| |
| 14 |
|
| #include "eshu.h" |
| 15 |
|
| |
| 16 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 17 |
|
| * Helpers — line classification |
| 18 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 19 |
|
| |
| 20 |
861 |
| static int eshu_java_is_closing(char c) { |
| 21 |
861 |
| return c == '}'; |
| 22 |
|
| } |
| 23 |
|
| |
| 24 |
|
| /* Returns 1 if the trimmed content is a switch case label. |
| 25 |
|
| * Recognises both "case X:" and "case X ->" (arrow switch), |
| 26 |
|
| * as well as "default:" and "default ->". */ |
| 27 |
616 |
| static int eshu_java_is_case_label(const char *content, int len) { |
| 28 |
|
| const char *p, *end; |
| 29 |
616 |
| int saw_arrow = 0; |
| 30 |
616 |
| int is_case = 0; |
| 31 |
|
| |
| 32 |
616 |
▶ | if (len < 2) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 2) return 0; |
0 |
616 |
616 |
|
| 33 |
|
| |
| 34 |
616 |
▶ | if (len >= 5 && strncmp(content, "case ", 5) == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (len >= 5 && strncmp(content, "case ", 5) == 0) |
615 |
1 |
616 |
| if (len >= 5 && strncmp(content, "case ", 5) == 0) |
11 |
604 |
615 |
|
| 35 |
11 |
| is_case = 1; |
| 36 |
605 |
▶ | else if (len >= 7 && strncmp(content, "default", 7) == 0 && |
Branch: 3 branches
| Branch | True | False | Total |
| else if (len >= 7 && strncmp(content, "default", 7) == 0 && |
592 |
13 |
605 |
| else if (len >= 7 && strncmp(content, "default", 7) == 0 && |
9 |
583 |
592 |
| else if (len >= 7 && strncmp(content, "default", 7) == 0 && |
9 |
0 |
9 |
|
| 37 |
9 |
▶ | (len == 7 || content[7] == ':' || content[7] == ' ' || |
Branch: 2 branches
| Branch | True | False | Total |
| (len == 7 || content[7] == ':' || content[7] == ' ' || |
6 |
3 |
9 |
| (len == 7 || content[7] == ':' || content[7] == ' ' || |
0 |
6 |
6 |
|
| 38 |
0 |
▶ | content[7] == '\t' || content[7] == '-' || content[7] == '/')) |
Branch: 3 branches
| Branch | True | False | Total |
| content[7] == '\t' || content[7] == '-' || content[7] == '/')) |
0 |
0 |
0 |
| content[7] == '\t' || content[7] == '-' || content[7] == '/')) |
0 |
0 |
0 |
| content[7] == '\t' || content[7] == '-' || content[7] == '/')) |
0 |
0 |
0 |
|
| 39 |
9 |
| is_case = 1; |
| 40 |
|
| |
| 41 |
616 |
▶ | if (!is_case) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_case) return 0; |
596 |
20 |
616 |
|
| 42 |
|
| |
| 43 |
20 |
| p = content; |
| 44 |
20 |
| end = content + len; |
| 45 |
|
| |
| 46 |
446 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
426 |
20 |
446 |
|
| 47 |
426 |
▶ | if (*p == '/' && p + 1 < end && *(p + 1) == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*p == '/' && p + 1 < end && *(p + 1) == '/') { |
0 |
426 |
426 |
| if (*p == '/' && p + 1 < end && *(p + 1) == '/') { |
0 |
0 |
0 |
| if (*p == '/' && p + 1 < end && *(p + 1) == '/') { |
0 |
0 |
0 |
|
| 48 |
0 |
| end = p; break; |
| 49 |
|
| } |
| 50 |
426 |
▶ | if (*p == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '"') { |
2 |
424 |
426 |
|
| 51 |
2 |
| p++; |
| 52 |
22 |
▶ | while (p < end && *p != '"') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '"') { |
22 |
0 |
22 |
| while (p < end && *p != '"') { |
20 |
2 |
22 |
|
| 53 |
20 |
▶ | if (*p == '\\') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\\') p++; |
0 |
20 |
20 |
|
| 54 |
20 |
| p++; |
| 55 |
|
| } |
| 56 |
424 |
▶ | } else if (*p == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (*p == '\'') { |
0 |
424 |
424 |
|
| 57 |
0 |
| p++; |
| 58 |
0 |
▶ | while (p < end && *p != '\'') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\'') { |
0 |
0 |
0 |
| while (p < end && *p != '\'') { |
0 |
0 |
0 |
|
| 59 |
0 |
▶ | if (*p == '\\') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\\') p++; |
0 |
0 |
0 |
|
| 60 |
0 |
| p++; |
| 61 |
|
| } |
| 62 |
424 |
▶ | } else if (*p == '-' && p + 1 < end && *(p + 1) == '>') { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (*p == '-' && p + 1 < end && *(p + 1) == '>') { |
9 |
415 |
424 |
| } else if (*p == '-' && p + 1 < end && *(p + 1) == '>') { |
9 |
0 |
9 |
| } else if (*p == '-' && p + 1 < end && *(p + 1) == '>') { |
9 |
0 |
9 |
|
| 63 |
9 |
| saw_arrow = 1; |
| 64 |
|
| } |
| 65 |
426 |
| p++; |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
20 |
▶ | while (end > content && (*(end - 1) == ' ' || *(end - 1) == '\t')) end--; |
Branch: 3 branches
| Branch | True | False | Total |
| while (end > content && (*(end - 1) == ' ' || *(end - 1) == '\t')) end--; |
20 |
0 |
20 |
| while (end > content && (*(end - 1) == ' ' || *(end - 1) == '\t')) end--; |
0 |
20 |
20 |
| while (end > content && (*(end - 1) == ' ' || *(end - 1) == '\t')) end--; |
0 |
20 |
20 |
|
| 69 |
20 |
▶ | if (end <= content) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (end <= content) return 0; |
0 |
20 |
20 |
|
| 70 |
|
| |
| 71 |
20 |
▶ | if (*(end - 1) == ':') return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(end - 1) == ':') return 1; |
8 |
12 |
20 |
|
| 72 |
12 |
▶ | if (saw_arrow) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (saw_arrow) return 1; |
9 |
3 |
12 |
|
| 73 |
|
| |
| 74 |
3 |
| return 0; |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 78 |
|
| * Scan a line — update ctx state and depth for the next line |
| 79 |
|
| * |
| 80 |
|
| * Called AFTER the line has been emitted. |
| 81 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 82 |
|
| |
| 83 |
876 |
| static void eshu_java_scan_line(eshu_java_ctx_t *ctx, |
| 84 |
|
| const char *p, const char *end) { |
| 85 |
18518 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
17644 |
874 |
18518 |
|
| 86 |
17644 |
| char c = *p; |
| 87 |
|
| |
| 88 |
17644 |
| switch (ctx->state) { |
| 89 |
17295 |
| case ESHU_CODE: |
| 90 |
17295 |
▶ | if (c == '{') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '{') { |
270 |
17025 |
17295 |
|
| 91 |
270 |
| ctx->depth++; |
| 92 |
17025 |
▶ | } else if (c == '}') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '}') { |
270 |
16755 |
17025 |
|
| 93 |
270 |
| ctx->depth--; |
| 94 |
270 |
▶ | if (ctx->depth < 0) ctx->depth = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->depth < 0) ctx->depth = 0; |
0 |
270 |
270 |
|
| 95 |
16755 |
▶ | } else if (c == '(') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '(') { |
501 |
16254 |
16755 |
|
| 96 |
501 |
| ctx->paren_depth++; |
| 97 |
16254 |
▶ | } else if (c == ')') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == ')') { |
501 |
15753 |
16254 |
|
| 98 |
501 |
▶ | if (ctx->paren_depth > 0) ctx->paren_depth--; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->paren_depth > 0) ctx->paren_depth--; |
501 |
0 |
501 |
|
| 99 |
15753 |
▶ | } else if (c == '[') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '[') { |
64 |
15689 |
15753 |
|
| 100 |
64 |
| ctx->bracket_depth++; |
| 101 |
15689 |
▶ | } else if (c == ']') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == ']') { |
64 |
15625 |
15689 |
|
| 102 |
64 |
▶ | if (ctx->bracket_depth > 0) ctx->bracket_depth--; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->bracket_depth > 0) ctx->bracket_depth--; |
64 |
0 |
64 |
|
| 103 |
15625 |
▶ | } else if (c == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '"') { |
32 |
15593 |
15625 |
|
| 104 |
32 |
▶ | if (p + 2 < end && *(p + 1) == '"' && *(p + 2) == '"') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p + 2 < end && *(p + 1) == '"' && *(p + 2) == '"') { |
32 |
0 |
32 |
| if (p + 2 < end && *(p + 1) == '"' && *(p + 2) == '"') { |
6 |
26 |
32 |
| if (p + 2 < end && *(p + 1) == '"' && *(p + 2) == '"') { |
5 |
1 |
6 |
|
| 105 |
5 |
| ctx->state = ESHU_JAVA_TEXT_BLOCK; |
| 106 |
5 |
| p += 2; |
| 107 |
|
| } else { |
| 108 |
27 |
| ctx->state = ESHU_STRING_DQ; |
| 109 |
|
| } |
| 110 |
15593 |
▶ | } else if (c == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '\'') { |
5 |
15588 |
15593 |
|
| 111 |
5 |
| ctx->state = ESHU_JAVA_CHAR; |
| 112 |
15588 |
▶ | } else if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
4 |
15584 |
15588 |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
4 |
0 |
4 |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
2 |
2 |
4 |
|
| 113 |
2 |
| return; /* line comment — skip rest */ |
| 114 |
15586 |
▶ | } else if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
2 |
15584 |
15586 |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
2 |
0 |
2 |
| } else if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
0 |
2 |
2 |
|
| 115 |
0 |
| ctx->state = ESHU_COMMENT_BLOCK; |
| 116 |
0 |
| p++; |
| 117 |
|
| } |
| 118 |
17293 |
| break; |
| 119 |
|
| |
| 120 |
266 |
| case ESHU_STRING_DQ: |
| 121 |
266 |
▶ | if (c == '\\' && p + 1 < end) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '\\' && p + 1 < end) { |
1 |
265 |
266 |
| if (c == '\\' && p + 1 < end) { |
1 |
0 |
1 |
|
| 122 |
1 |
| p++; |
| 123 |
265 |
▶ | } else if (c == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '"') { |
27 |
238 |
265 |
|
| 124 |
27 |
| ctx->state = ESHU_CODE; |
| 125 |
|
| } |
| 126 |
266 |
| break; |
| 127 |
|
| |
| 128 |
10 |
| case ESHU_JAVA_CHAR: |
| 129 |
10 |
▶ | if (c == '\\' && p + 1 < end) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '\\' && p + 1 < end) { |
1 |
9 |
10 |
| if (c == '\\' && p + 1 < end) { |
1 |
0 |
1 |
|
| 130 |
1 |
| p++; |
| 131 |
9 |
▶ | } else if (c == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (c == '\'') { |
5 |
4 |
9 |
|
| 132 |
5 |
| ctx->state = ESHU_CODE; |
| 133 |
|
| } |
| 134 |
10 |
| break; |
| 135 |
|
| |
| 136 |
73 |
| case ESHU_JAVA_TEXT_BLOCK: |
| 137 |
73 |
▶ | if (c == '"' && p + 2 <= end && |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '"' && p + 2 <= end && |
9 |
64 |
73 |
| if (c == '"' && p + 2 <= end && |
8 |
1 |
9 |
|
| 138 |
8 |
▶ | p + 1 < end && *(p + 1) == '"' && |
Branch: 2 branches
| Branch | True | False | Total |
| p + 1 < end && *(p + 1) == '"' && |
8 |
0 |
8 |
| p + 1 < end && *(p + 1) == '"' && |
5 |
3 |
8 |
|
| 139 |
5 |
▶ | p + 2 < end && *(p + 2) == '"') { |
Branch: 2 branches
| Branch | True | False | Total |
| p + 2 < end && *(p + 2) == '"') { |
5 |
0 |
5 |
| p + 2 < end && *(p + 2) == '"') { |
5 |
0 |
5 |
|
| 140 |
5 |
| ctx->state = ESHU_CODE; |
| 141 |
5 |
| p += 2; |
| 142 |
|
| } |
| 143 |
73 |
| break; |
| 144 |
|
| |
| 145 |
0 |
| case ESHU_COMMENT_BLOCK: |
| 146 |
0 |
▶ | if (c == '*' && p + 1 < end && *(p + 1) == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '*' && p + 1 < end && *(p + 1) == '/') { |
0 |
0 |
0 |
| if (c == '*' && p + 1 < end && *(p + 1) == '/') { |
0 |
0 |
0 |
| if (c == '*' && p + 1 < end && *(p + 1) == '/') { |
0 |
0 |
0 |
|
| 147 |
0 |
| ctx->state = ESHU_CODE; |
| 148 |
0 |
| p++; |
| 149 |
|
| } |
| 150 |
0 |
| break; |
| 151 |
|
| |
| 152 |
0 |
| default: |
| 153 |
0 |
| break; |
| 154 |
|
| } |
| 155 |
17642 |
| p++; |
| 156 |
|
| } |
| 157 |
|
| } |
| 158 |
|
| |
| 159 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 160 |
|
| * Process a single line — decide indent, emit, scan |
| 161 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 162 |
|
| |
| 163 |
920 |
| static void eshu_java_process_line(eshu_java_ctx_t *ctx, eshu_buf_t *out, |
| 164 |
|
| const char *line_start, const char *eol) { |
| 165 |
920 |
| const char *content = eshu_skip_leading_ws(line_start); |
| 166 |
|
| int line_len; |
| 167 |
|
| int indent_depth; |
| 168 |
|
| |
| 169 |
|
| /* empty line — preserve */ |
| 170 |
920 |
▶ | if (content >= eol) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (content >= eol) { |
44 |
876 |
920 |
|
| 171 |
44 |
| eshu_buf_putc(out, '\n'); |
| 172 |
44 |
| return; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
876 |
| line_len = (int)(eol - content); |
| 176 |
|
| |
| 177 |
|
| /* block comment continuation: indent at current depth */ |
| 178 |
876 |
▶ | if (ctx->state == ESHU_COMMENT_BLOCK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->state == ESHU_COMMENT_BLOCK) { |
0 |
876 |
876 |
|
| 179 |
0 |
| eshu_emit_indent(out, ctx->depth, &ctx->cfg); |
| 180 |
0 |
| eshu_buf_write_trimmed(out, content, line_len); |
| 181 |
0 |
| eshu_buf_putc(out, '\n'); |
| 182 |
0 |
| eshu_java_scan_line(ctx, content, eol); |
| 183 |
0 |
| return; |
| 184 |
|
| } |
| 185 |
|
| |
| 186 |
|
| /* text block content: emit verbatim (significant whitespace) */ |
| 187 |
876 |
▶ | if (ctx->state == ESHU_JAVA_TEXT_BLOCK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->state == ESHU_JAVA_TEXT_BLOCK) { |
15 |
861 |
876 |
|
| 188 |
15 |
| eshu_buf_write(out, line_start, (size_t)(eol - line_start)); |
| 189 |
15 |
| eshu_buf_putc(out, '\n'); |
| 190 |
15 |
| eshu_java_scan_line(ctx, content, eol); |
| 191 |
15 |
| return; |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
|
| /* normal code */ |
| 195 |
861 |
| indent_depth = ctx->depth; |
| 196 |
|
| |
| 197 |
|
| /* clear case_extra once depth drops below case_depth */ |
| 198 |
861 |
▶ | if (ctx->case_extra && ctx->depth < ctx->case_depth) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->case_extra && ctx->depth < ctx->case_depth) |
41 |
820 |
861 |
| if (ctx->case_extra && ctx->depth < ctx->case_depth) |
5 |
36 |
41 |
|
| 199 |
5 |
| ctx->case_extra = 0; |
| 200 |
|
| |
| 201 |
861 |
▶ | if (eshu_java_is_closing(*content)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_java_is_closing(*content)) { |
245 |
616 |
861 |
|
| 202 |
245 |
| indent_depth--; |
| 203 |
245 |
▶ | if (indent_depth < 0) indent_depth = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (indent_depth < 0) indent_depth = 0; |
0 |
245 |
245 |
|
| 204 |
245 |
▶ | if (ctx->case_extra && ctx->depth > ctx->case_depth) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->case_extra && ctx->depth > ctx->case_depth) |
8 |
237 |
245 |
| if (ctx->case_extra && ctx->depth > ctx->case_depth) |
2 |
6 |
8 |
|
| 205 |
2 |
| indent_depth++; |
| 206 |
616 |
▶ | } else if (eshu_java_is_case_label(content, line_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (eshu_java_is_case_label(content, line_len)) { |
17 |
599 |
616 |
|
| 207 |
17 |
| ctx->case_depth = ctx->depth; |
| 208 |
17 |
| ctx->case_extra = 1; |
| 209 |
599 |
▶ | } else if (ctx->case_extra && ctx->depth >= ctx->case_depth) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (ctx->case_extra && ctx->depth >= ctx->case_depth) { |
17 |
582 |
599 |
| } else if (ctx->case_extra && ctx->depth >= ctx->case_depth) { |
17 |
0 |
17 |
|
| 210 |
17 |
| indent_depth++; |
| 211 |
|
| } |
| 212 |
|
| |
| 213 |
861 |
| eshu_emit_indent(out, indent_depth, &ctx->cfg); |
| 214 |
861 |
| eshu_buf_write_trimmed(out, content, line_len); |
| 215 |
861 |
| eshu_buf_putc(out, '\n'); |
| 216 |
|
| |
| 217 |
861 |
| eshu_java_scan_line(ctx, content, eol); |
| 218 |
|
| } |
| 219 |
|
| |
| 220 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 221 |
|
| * Public API — indent a Java source string |
| 222 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 223 |
|
| |
| 224 |
90 |
| static char *eshu_indent_java(const char *src, size_t src_len, |
| 225 |
|
| const eshu_config_t *cfg, size_t *out_len) { |
| 226 |
|
| eshu_java_ctx_t ctx; |
| 227 |
|
| eshu_buf_t out; |
| 228 |
90 |
| const char *p = src; |
| 229 |
90 |
| const char *end = src + src_len; |
| 230 |
|
| char *result; |
| 231 |
|
| |
| 232 |
90 |
| memset(&ctx, 0, sizeof(ctx)); |
| 233 |
90 |
| ctx.state = ESHU_CODE; |
| 234 |
90 |
| ctx.cfg = *cfg; |
| 235 |
|
| |
| 236 |
90 |
| eshu_buf_init(&out, src_len + 256); |
| 237 |
|
| |
| 238 |
|
| { |
| 239 |
90 |
| int line_num = 1; |
| 240 |
1010 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
920 |
90 |
1010 |
|
| 241 |
920 |
| const char *eol = eshu_find_eol(p); |
| 242 |
|
| |
| 243 |
920 |
▶ | if (eshu_in_range(cfg, line_num)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_in_range(cfg, line_num)) { |
920 |
0 |
920 |
|
| 244 |
920 |
| eshu_java_process_line(&ctx, &out, p, eol); |
| 245 |
|
| } else { |
| 246 |
0 |
| size_t saved = out.len; |
| 247 |
0 |
| eshu_java_process_line(&ctx, &out, p, eol); |
| 248 |
0 |
| out.len = saved; |
| 249 |
0 |
| eshu_buf_write_trimmed(&out, p, (int)(eol - p)); |
| 250 |
0 |
| eshu_buf_putc(&out, '\n'); |
| 251 |
|
| } |
| 252 |
|
| |
| 253 |
920 |
| p = eol; |
| 254 |
920 |
▶ | if (*p == '\n') p++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\n') p++; |
918 |
2 |
920 |
|
| 255 |
920 |
| line_num++; |
| 256 |
|
| } |
| 257 |
|
| } |
| 258 |
|
| |
| 259 |
90 |
| eshu_buf_putc(&out, '\0'); |
| 260 |
90 |
| out.len--; |
| 261 |
90 |
| *out_len = out.len; |
| 262 |
90 |
| result = out.data; |
| 263 |
90 |
| return result; |
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
|
| |
| 267 |
|
| #include "eshu_hl_util.h" |
| 268 |
|
| |
| 269 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 270 |
|
| * Java keyword and builtin lists |
| 271 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 272 |
|
| |
| 273 |
|
| static const char * const eshu_hl_java_kw[] = { |
| 274 |
|
| "abstract", "assert", "boolean", "break", "byte", |
| 275 |
|
| "case", "catch", "char", "class", "const", |
| 276 |
|
| "continue", "default", "do", "double", "else", |
| 277 |
|
| "enum", "extends", "final", "finally", "float", |
| 278 |
|
| "for", "goto", "if", "implements", "import", |
| 279 |
|
| "instanceof", "int", "interface", "long", "native", |
| 280 |
|
| "new", "package", "private", "protected", "public", |
| 281 |
|
| "record", "return", "sealed", "short", "static", |
| 282 |
|
| "strictfp", "super", "switch", "synchronized", |
| 283 |
|
| "this", "throw", "throws", "transient", "try", |
| 284 |
|
| "var", "void", "volatile", "while", "yield", |
| 285 |
|
| "false", "null", "true", |
| 286 |
|
| "permits", "when", |
| 287 |
|
| NULL |
| 288 |
|
| }; |
| 289 |
|
| |
| 290 |
|
| static const char * const eshu_hl_java_bi[] = { |
| 291 |
|
| "Object", "String", "Integer", "Long", "Double", "Float", |
| 292 |
|
| "Boolean", "Character", "Byte", "Short", |
| 293 |
|
| "System", "Math", "StringBuilder", "StringBuffer", |
| 294 |
|
| "Exception", "RuntimeException", "Error", "Throwable", |
| 295 |
|
| "Iterable", "Iterator", "Comparable", "Cloneable", |
| 296 |
|
| "Class", "ClassLoader", |
| 297 |
|
| "Thread", "Runnable", |
| 298 |
|
| "Override", "Deprecated", "SuppressWarnings", "FunctionalInterface", |
| 299 |
|
| NULL |
| 300 |
|
| }; |
| 301 |
|
| |
| 302 |
|
| /* ══════════════════════════════════════════════════════════════════ |
| 303 |
|
| * Java highlighter |
| 304 |
|
| * ══════════════════════════════════════════════════════════════════ */ |
| 305 |
|
| |
| 306 |
52 |
| static char *eshu_highlight_java(const char *src, size_t src_len, size_t *out_len) { |
| 307 |
|
| eshu_buf_t out; |
| 308 |
52 |
| const char *p = src; |
| 309 |
52 |
| const char *end = src + src_len; |
| 310 |
52 |
| const char *plain = p; |
| 311 |
52 |
| int in_text_block = 0; |
| 312 |
|
| |
| 313 |
52 |
| eshu_buf_init(&out, src_len * 2 + 64); |
| 314 |
|
| |
| 315 |
|
| #define JAVA_SPAN(cls, ts, te) do { \ |
| 316 |
|
| eshu_hl_flush(&out, plain, (ts)); \ |
| 317 |
|
| eshu_hl_span(&out, (cls), (ts), (te)); \ |
| 318 |
|
| p = (te); plain = p; \ |
| 319 |
|
| } while(0) |
| 320 |
|
| |
| 321 |
642 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
590 |
52 |
642 |
|
| 322 |
590 |
| char c = *p; |
| 323 |
|
| |
| 324 |
|
| /* text block content: pass through until closing """ */ |
| 325 |
590 |
▶ | if (in_text_block) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_text_block) { |
0 |
590 |
590 |
|
| 326 |
0 |
▶ | if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
Branch: 4 branches
| Branch | True | False | Total |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
0 |
0 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
0 |
0 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
0 |
0 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
0 |
0 |
|
| 327 |
0 |
| const char *te = p + 3; |
| 328 |
0 |
| JAVA_SPAN("esh-s", plain, te); |
| 329 |
0 |
| in_text_block = 0; |
| 330 |
|
| } else { |
| 331 |
0 |
| p++; |
| 332 |
|
| } |
| 333 |
0 |
| continue; |
| 334 |
|
| } |
| 335 |
|
| |
| 336 |
|
| /* annotation @Name */ |
| 337 |
590 |
▶ | if (c == '@') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '@') { |
4 |
586 |
590 |
|
| 338 |
4 |
| const char *ts = p++; |
| 339 |
57 |
▶ | while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; |
56 |
1 |
57 |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; |
53 |
3 |
56 |
| while (p < end && (isalnum((unsigned char)*p) || *p == '_')) p++; |
0 |
3 |
3 |
|
| 340 |
4 |
| JAVA_SPAN("esh-p", ts, p); |
| 341 |
4 |
| continue; |
| 342 |
|
| } |
| 343 |
|
| |
| 344 |
|
| /* line comment */ |
| 345 |
586 |
▶ | if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
3 |
583 |
586 |
| if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
3 |
0 |
3 |
| if (c == '/' && p + 1 < end && *(p + 1) == '/') { |
1 |
2 |
3 |
|
| 346 |
1 |
| const char *ts = p; |
| 347 |
1 |
| p += 2; |
| 348 |
19 |
▶ | while (p < end && *p != '\n') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\n') p++; |
18 |
1 |
19 |
| while (p < end && *p != '\n') p++; |
18 |
0 |
18 |
|
| 349 |
1 |
| JAVA_SPAN("esh-c", ts, p); |
| 350 |
1 |
| continue; |
| 351 |
|
| } |
| 352 |
|
| |
| 353 |
|
| /* block comment (including javadoc) */ |
| 354 |
585 |
▶ | if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
2 |
583 |
585 |
| if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
2 |
0 |
2 |
| if (c == '/' && p + 1 < end && *(p + 1) == '*') { |
2 |
0 |
2 |
|
| 355 |
2 |
| const char *ts = p; |
| 356 |
2 |
| p += 2; |
| 357 |
27 |
▶ | while (p + 1 < end && !(*p == '*' && *(p + 1) == '/')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p + 1 < end && !(*p == '*' && *(p + 1) == '/')) p++; |
27 |
0 |
27 |
| while (p + 1 < end && !(*p == '*' && *(p + 1) == '/')) p++; |
24 |
3 |
27 |
| while (p + 1 < end && !(*p == '*' && *(p + 1) == '/')) p++; |
1 |
2 |
3 |
|
| 358 |
2 |
▶ | if (p + 1 < end) p += 2; |
Branch: 1 branch
| Branch | True | False | Total |
| if (p + 1 < end) p += 2; |
2 |
0 |
2 |
|
| 359 |
2 |
| JAVA_SPAN("esh-c", ts, p); |
| 360 |
2 |
| continue; |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
|
| /* text block """ */ |
| 364 |
583 |
▶ | if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
Branch: 4 branches
| Branch | True | False | Total |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
9 |
574 |
583 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
9 |
0 |
9 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
9 |
9 |
| if (c == '"' && p + 2 < end && *(p+1) == '"' && *(p+2) == '"') { |
0 |
0 |
0 |
|
| 365 |
0 |
| eshu_hl_flush(&out, plain, p); |
| 366 |
0 |
| plain = p; |
| 367 |
0 |
| in_text_block = 1; |
| 368 |
0 |
| p += 3; |
| 369 |
0 |
| continue; |
| 370 |
|
| } |
| 371 |
|
| |
| 372 |
|
| /* string "..." */ |
| 373 |
583 |
▶ | if (c == '"') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '"') { |
9 |
574 |
583 |
|
| 374 |
9 |
| const char *ts = p++; |
| 375 |
61 |
▶ | while (p < end && *p != '"') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '"') { |
61 |
0 |
61 |
| while (p < end && *p != '"') { |
52 |
9 |
61 |
|
| 376 |
52 |
▶ | if (*p == '\\') { p++; if (p < end) p++; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\') { p++; if (p < end) p++; continue; } |
2 |
50 |
52 |
| if (*p == '\\') { p++; if (p < end) p++; continue; } |
2 |
0 |
2 |
|
| 377 |
50 |
▶ | if (*p == '\n') break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\n') break; |
0 |
50 |
50 |
|
| 378 |
50 |
| p++; |
| 379 |
|
| } |
| 380 |
9 |
▶ | if (p < end && *p == '"') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '"') p++; |
9 |
0 |
9 |
| if (p < end && *p == '"') p++; |
9 |
0 |
9 |
|
| 381 |
9 |
| JAVA_SPAN("esh-s", ts, p); |
| 382 |
9 |
| continue; |
| 383 |
|
| } |
| 384 |
|
| |
| 385 |
|
| /* char literal '.' */ |
| 386 |
574 |
▶ | if (c == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '\'') { |
2 |
572 |
574 |
|
| 387 |
2 |
| const char *ts = p++; |
| 388 |
4 |
▶ | while (p < end && *p != '\'') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\'') { |
4 |
0 |
4 |
| while (p < end && *p != '\'') { |
2 |
2 |
4 |
|
| 389 |
2 |
▶ | if (*p == '\\') { p++; if (p < end) p++; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p == '\\') { p++; if (p < end) p++; continue; } |
0 |
2 |
2 |
| if (*p == '\\') { p++; if (p < end) p++; continue; } |
0 |
0 |
0 |
|
| 390 |
2 |
▶ | if (*p == '\n') break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p == '\n') break; |
0 |
2 |
2 |
|
| 391 |
2 |
| p++; |
| 392 |
|
| } |
| 393 |
2 |
▶ | if (p < end && *p == '\'') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '\'') p++; |
2 |
0 |
2 |
| if (p < end && *p == '\'') p++; |
2 |
0 |
2 |
|
| 394 |
2 |
| JAVA_SPAN("esh-s", ts, p); |
| 395 |
2 |
| continue; |
| 396 |
|
| } |
| 397 |
|
| |
| 398 |
|
| /* number: 0x hex, 0b binary, decimal, float */ |
| 399 |
572 |
▶ | if (isdigit((unsigned char)c)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isdigit((unsigned char)c)) { |
18 |
554 |
572 |
|
| 400 |
18 |
| const char *ts = p; |
| 401 |
27 |
▶ | if (c == '0' && p + 1 < end) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '0' && p + 1 < end) { |
9 |
9 |
18 |
| if (c == '0' && p + 1 < end) { |
9 |
0 |
9 |
|
| 402 |
9 |
| char nx = *(p + 1); |
| 403 |
9 |
▶ | if (nx == 'x' || nx == 'X') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (nx == 'x' || nx == 'X') { |
8 |
1 |
9 |
| if (nx == 'x' || nx == 'X') { |
0 |
8 |
8 |
|
| 404 |
1 |
| p += 2; |
| 405 |
3 |
▶ | while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; |
3 |
0 |
3 |
| while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; |
2 |
1 |
3 |
| while (p < end && (isxdigit((unsigned char)*p) || *p == '_')) p++; |
0 |
1 |
1 |
|
| 406 |
8 |
▶ | } else if (nx == 'b' || nx == 'B') { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (nx == 'b' || nx == 'B') { |
7 |
1 |
8 |
| } else if (nx == 'b' || nx == 'B') { |
0 |
7 |
7 |
|
| 407 |
1 |
| p += 2; |
| 408 |
5 |
▶ | while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; |
Branch: 4 branches
| Branch | True | False | Total |
| while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; |
5 |
0 |
5 |
| while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; |
2 |
3 |
5 |
| while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; |
2 |
1 |
3 |
| while (p < end && (*p == '0' || *p == '1' || *p == '_')) p++; |
0 |
1 |
1 |
|
| 409 |
|
| } else { |
| 410 |
14 |
▶ | while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
14 |
0 |
14 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
7 |
7 |
14 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
0 |
7 |
7 |
|
| 411 |
7 |
▶ | if (p < end && *p == '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '.') { |
7 |
0 |
7 |
| if (p < end && *p == '.') { |
2 |
5 |
7 |
|
| 412 |
2 |
| p++; |
| 413 |
4 |
▶ | while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
4 |
0 |
4 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
2 |
2 |
4 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
0 |
2 |
2 |
|
| 414 |
|
| } |
| 415 |
7 |
▶ | if (p < end && (*p == 'e' || *p == 'E')) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == 'e' || *p == 'E')) { |
7 |
0 |
7 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
7 |
0 |
7 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
0 |
7 |
7 |
|
| 416 |
0 |
| p++; |
| 417 |
0 |
▶ | if (p < end && (*p == '+' || *p == '-')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
|
| 418 |
0 |
▶ | while (p < end && isdigit((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
|
| 419 |
|
| } |
| 420 |
|
| } |
| 421 |
|
| } else { |
| 422 |
31 |
▶ | while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
31 |
0 |
31 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
20 |
11 |
31 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
2 |
9 |
11 |
|
| 423 |
9 |
▶ | if (p < end && *p == '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '.') { |
9 |
0 |
9 |
| if (p < end && *p == '.') { |
1 |
8 |
9 |
|
| 424 |
1 |
| p++; |
| 425 |
3 |
▶ | while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
3 |
0 |
3 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
2 |
1 |
3 |
| while (p < end && (isdigit((unsigned char)*p) || *p == '_')) p++; |
0 |
1 |
1 |
|
| 426 |
|
| } |
| 427 |
9 |
▶ | if (p < end && (*p == 'e' || *p == 'E')) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == 'e' || *p == 'E')) { |
9 |
0 |
9 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
9 |
0 |
9 |
| if (p < end && (*p == 'e' || *p == 'E')) { |
0 |
9 |
9 |
|
| 428 |
0 |
| p++; |
| 429 |
0 |
▶ | if (p < end && (*p == '+' || *p == '-')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
| if (p < end && (*p == '+' || *p == '-')) p++; |
0 |
0 |
0 |
|
| 430 |
0 |
▶ | while (p < end && isdigit((unsigned char)*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
| while (p < end && isdigit((unsigned char)*p)) p++; |
0 |
0 |
0 |
|
| 431 |
|
| } |
| 432 |
|
| } |
| 433 |
|
| /* long / float / double suffix */ |
| 434 |
18 |
▶ | if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
Branch: 5 branches
| Branch | True | False | Total |
| if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
18 |
0 |
18 |
| if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
16 |
2 |
18 |
| if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
16 |
0 |
16 |
| if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
15 |
1 |
16 |
| if (p < end && (*p == 'L' || *p == 'l' || *p == 'f' || *p == 'F' || |
15 |
0 |
15 |
|
| 435 |
18 |
▶ | *p == 'd' || *p == 'D')) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| *p == 'd' || *p == 'D')) p++; |
15 |
0 |
15 |
| *p == 'd' || *p == 'D')) p++; |
0 |
15 |
15 |
|
| 436 |
18 |
| JAVA_SPAN("esh-n", ts, p); |
| 437 |
18 |
| continue; |
| 438 |
|
| } |
| 439 |
|
| |
| 440 |
|
| /* identifier / keyword / builtin */ |
| 441 |
554 |
▶ | if (eshu_hl_isalpha_(c)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_hl_isalpha_(c)) { |
170 |
384 |
554 |
|
| 442 |
170 |
| const char *ts = p; |
| 443 |
917 |
▶ | while (p < end && eshu_hl_isalnum_(*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && eshu_hl_isalnum_(*p)) p++; |
914 |
3 |
917 |
| while (p < end && eshu_hl_isalnum_(*p)) p++; |
747 |
167 |
914 |
|
| 444 |
170 |
| eshu_hl_flush(&out, plain, ts); |
| 445 |
170 |
| plain = p; |
| 446 |
170 |
▶ | if (eshu_hl_kw(ts, (size_t)(p - ts), eshu_hl_java_kw)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eshu_hl_kw(ts, (size_t)(p - ts), eshu_hl_java_kw)) { |
75 |
95 |
170 |
|
| 447 |
75 |
| eshu_hl_span(&out, "esh-k", ts, p); |
| 448 |
95 |
▶ | } else if (eshu_hl_kw(ts, (size_t)(p - ts), eshu_hl_java_bi)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (eshu_hl_kw(ts, (size_t)(p - ts), eshu_hl_java_bi)) { |
18 |
77 |
95 |
|
| 449 |
18 |
| eshu_hl_span(&out, "esh-b", ts, p); |
| 450 |
|
| } else { |
| 451 |
77 |
| eshu_hl_write_html(&out, ts, (size_t)(p - ts)); |
| 452 |
|
| } |
| 453 |
170 |
| continue; |
| 454 |
|
| } |
| 455 |
|
| |
| 456 |
384 |
| p++; |
| 457 |
|
| } |
| 458 |
|
| |
| 459 |
|
| /* flush any pending text block that wasn't closed */ |
| 460 |
52 |
| eshu_hl_flush(&out, plain, end); |
| 461 |
52 |
| eshu_buf_putc(&out, '\0'); |
| 462 |
52 |
| *out_len = out.len - 1; |
| 463 |
52 |
| return out.data; |
| 464 |
|
| |
| 465 |
|
| #undef JAVA_SPAN |
| 466 |
|
| } |
| 467 |
|
| |
| 468 |
|
| #endif /* ESHU_JAVA_H */ |