提交 42ee0424 编写于 作者: S Sean Barrett

Re-add lost fix to 'get_location' function as reported by Andreas Fredriksson.

上级 48234a16
// stb_c_lexer.h - v0.04 - public domain Sean Barrett 2013 // stb_c_lexer.h - v0.05 - public domain Sean Barrett 2013
// lexer for making little C-like languages with recursive-descent parsers // lexer for making little C-like languages with recursive-descent parsers
// //
// This file provides both the interface and the implementation. // This file provides both the interface and the implementation.
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
// suffixes on integer constants are not handled (you can override this). // suffixes on integer constants are not handled (you can override this).
// //
// History: // History:
// 0.05
// refixed get_location because github version had lost the fix
// 0.04 // 0.04
// fix octal parsing bug // fix octal parsing bug
// 0.03 // 0.03
...@@ -22,7 +24,6 @@ ...@@ -22,7 +24,6 @@
// Status: // Status:
// - haven't tested compiling as C++ // - haven't tested compiling as C++
// - haven't tested the float parsing path // - haven't tested the float parsing path
// - maybe tested "get_location" function (used for error reporting) in 0.03
// - haven't tested the non-default-config paths (e.g. non-stdlib) // - haven't tested the non-default-config paths (e.g. non-stdlib)
// - only tested default-config paths by eyeballing output of self-parse // - only tested default-config paths by eyeballing output of self-parse
// //
...@@ -294,7 +295,7 @@ void stb_c_lexer_get_location(const stb_lexer *lexer, const char *where, stb_lex ...@@ -294,7 +295,7 @@ void stb_c_lexer_get_location(const stb_lexer *lexer, const char *where, stb_lex
char *p = lexer->input_stream; char *p = lexer->input_stream;
int line_number = 1; int line_number = 1;
int char_offset = 0; int char_offset = 0;
while (*p) { while (*p && p < where) {
if (*p == '\n' || *p == '\r') { if (*p == '\n' || *p == '\r') {
p += (p[0]+p[1] == '\r'+'\n' ? 2 : 1); // skip newline p += (p[0]+p[1] == '\r'+'\n' ? 2 : 1); // skip newline
line_number += 1; line_number += 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册