X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Flexer.c;h=bad24d3f9baeca4e4be9e5c32c95a3a9c509d130;hb=61cb03a73ff9f5d38e9728d4bf5a449212d3acdc;hp=27d5dedb5464728dd4186c2640b6d1f9531ef5d3;hpb=51acdebd6747816b6f955634e1bfcc9c8071b56d;p=pspp diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index 27d5dedb54..bad24d3f9b 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "language/command.h" #include "language/lexer/macro.h" @@ -1219,39 +1218,12 @@ lex_token_get_last_line_number (const struct lex_source *src, } } -static int -count_columns (const char *s_, size_t length) -{ - const uint8_t *s = CHAR_CAST (const uint8_t *, s_); - int columns; - size_t ofs; - int mblen; - - columns = 0; - for (ofs = 0; ofs < length; ofs += mblen) - { - ucs4_t uc; - - mblen = u8_mbtouc (&uc, s + ofs, length - ofs); - if (uc != '\t') - { - int width = uc_width (uc, "UTF-8"); - if (width > 0) - columns += width; - } - else - columns = ROUND_UP (columns + 1, 8); - } - - return columns + 1; -} - static int lex_token_get_first_column (const struct lex_source *src, const struct lex_token *token) { - return count_columns (&src->buffer[token->line_pos - src->tail], - token->token_pos - token->line_pos); + return utf8_count_columns (&src->buffer[token->line_pos - src->tail], + token->token_pos - token->line_pos) + 1; } static int @@ -1265,7 +1237,7 @@ lex_token_get_last_column (const struct lex_source *src, newline = memrchr (start, '\n', end - start); if (newline != NULL) start = newline + 1; - return count_columns (start, end - start); + return utf8_count_columns (start, end - start) + 1; } static struct msg_location