diff -r 17408c3607ce -r f25ba6fd7a08 src/javacodegen.c
--- a/src/javacodegen.c Thu Aug 25 11:30:30 2016 +0200
+++ b/src/javacodegen.c Thu Aug 25 12:16:57 2016 +0200
@@ -39,19 +39,21 @@
"volatile", "const", "float", "native", "super", "while", NULL
};
-void java_highlighter(char *src, UcxBuffer *dest, int *multiline_comment) {
+void java_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) {
+ /* reset buffers without clearing them */
+ hd->primary_buffer->size = hd->primary_buffer->pos = 0;
+ hd->secondary_buffer->size = hd->secondary_buffer->pos = 0;
- /* TODO: try to replace this buffer */
- char wordbuf[WORDBUF_SIZE];
- sstr_t word;
- word.ptr = wordbuf; word.length = 0;
+ /* alias the buffers for better handling */
+ UcxBuffer *wbuf = hd->primary_buffer;
+ /* local information */
size_t sp = (size_t)-1;
int isstring = 0, iscomment = 0, isimport = 0;
char quote = '\0';
int isescaping = 0;
- if (*multiline_comment) {
+ if (hd->multiline_comment) {
iscomment = 1;
ucx_buffer_puts(dest, "");
continue;
} else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
iscomment = 1;
- *multiline_comment = (src[sp+1] == '*');
+ hd->multiline_comment = (src[sp+1] == '*');
ucx_buffer_puts(dest, "");
}
}
- word.length = 0;
+ wbuf->pos = wbuf->size = 0; /* reset buffer */
+
+ /* write current character */
put_htmlescaped(dest, c);
} else {
- /* read word */
- if (word.length < WORDBUF_SIZE) {
- word.ptr[word.length++] = c;
- } else if (word.length == WORDBUF_SIZE) {
- /* TODO: this will be removed */
- ucx_buffer_puts(dest,
- "!!! WARNING - WORD TOO LONG TO PARSE !!!");
- word.length = 0;
- } else {
- put_htmlescaped(dest, c);
- }
+ /* buffer the current word */
+ ucx_buffer_putc(wbuf, c);
}
}