Kouhei Sutou
null+****@clear*****
Fri May 11 15:18:35 JST 2018
Kouhei Sutou 2018-05-11 15:18:35 +0900 (Fri, 11 May 2018) New Revision: 1bf0641a944b76290d39204d344c73f218140047 https://github.com/groonga/groonga/commit/1bf0641a944b76290d39204d344c73f218140047 Message: Extract common code Modified files: lib/highlighter.c Modified: lib/highlighter.c (+44 -38) =================================================================== --- lib/highlighter.c 2018-05-11 15:15:41 +0900 (c8a6632f5) +++ lib/highlighter.c 2018-05-11 15:18:35 +0900 (ec5dcc553) @@ -302,6 +302,36 @@ grn_highlighter_prepare(grn_ctx *ctx, highlighter->need_prepared = GRN_FALSE; } +static uint64_t +grn_highlighter_highlight_lexicon_flush(grn_ctx *ctx, + grn_highlighter *highlighter, + const char *text, + size_t text_length, + grn_obj *output, + grn_highlighter_location *location, + uint64_t offset) +{ + if (location->offset > offset) { + grn_text_escape_xml(ctx, + output, + text + offset, + location->offset - offset); + } + GRN_TEXT_PUT(ctx, + output, + highlighter->tag.open, + highlighter->tag.open_length); + grn_text_escape_xml(ctx, + output, + text + location->offset, + location->length); + GRN_TEXT_PUT(ctx, + output, + highlighter->tag.close, + highlighter->tag.close_length); + return location->offset + location->length; +} + static void grn_highlighter_highlight_lexicon(grn_ctx *ctx, grn_highlighter *highlighter, @@ -451,47 +481,23 @@ grn_highlighter_highlight_lexicon(grn_ctx *ctx, continue; } if (current->offset > previous->offset) { - if (previous->offset > offset) { - grn_text_escape_xml(ctx, - output, - text + offset, - previous->offset - offset); - } - GRN_TEXT_PUT(ctx, - output, - highlighter->tag.open, - highlighter->tag.open_length); - grn_text_escape_xml(ctx, - output, - text + previous->offset, - previous->length); - offset = previous->offset + previous->length; - GRN_TEXT_PUT(ctx, - output, - highlighter->tag.close, - highlighter->tag.close_length); + offset = grn_highlighter_highlight_lexicon_flush(ctx, + highlighter, + text, + text_length, + output, + previous, + offset); } previous = current; } - if (previous->offset > offset) { - grn_text_escape_xml(ctx, - output, - text + offset, - previous->offset - offset); - } - GRN_TEXT_PUT(ctx, - output, - highlighter->tag.open, - highlighter->tag.open_length); - grn_text_escape_xml(ctx, - output, - text + previous->offset, - previous->length); - offset = previous->offset + previous->length; - GRN_TEXT_PUT(ctx, - output, - highlighter->tag.close, - highlighter->tag.close_length); + offset = grn_highlighter_highlight_lexicon_flush(ctx, + highlighter, + text, + text_length, + output, + previous, + offset); if (offset < text_length) { grn_text_escape_xml(ctx, output, -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180511/58d853e6/attachment-0001.htm