From 00449c2bfb8ec5e4b9dfc70f39d99e5ca7fe9fd1 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Mon, 21 Aug 2023 21:35:34 +0800 Subject: [PATCH] :zap: optimize code --- src/nasal_lexer.cpp | 6 +++--- test/httptest.nas | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/nasal_lexer.cpp b/src/nasal_lexer.cpp index facfe13..c745cef 100644 --- a/src/nasal_lexer.cpp +++ b/src/nasal_lexer.cpp @@ -11,11 +11,11 @@ bool lexer::skip(char c) { } bool lexer::is_id(char c) { - return (c=='_') || ('a'<=c && c<='z') || ('A'<=c && c<='Z') || (c<0); + return (c=='_') || std::isalpha(c) || (c<0); } bool lexer::is_hex(char c) { - return ('0'<=c && c<='9') || ('a'<=c && c<='f') || ('A'<=c && c<='F'); + return std::isdigit(c) || ('a'<=c && c<='f') || ('A'<=c && c<='F'); } bool lexer::is_oct(char c) { @@ -23,7 +23,7 @@ bool lexer::is_oct(char c) { } bool lexer::is_dec(char c) { - return '0'<=c && c<='9'; + return std::isdigit(c); } bool lexer::is_str(char c) { diff --git a/test/httptest.nas b/test/httptest.nas index 2fac7f8..be0f6bb 100644 --- a/test/httptest.nas +++ b/test/httptest.nas @@ -48,28 +48,31 @@ http.establish("127.0.0.1",8080); var highlight_style=" "; var html_read_file=func(filename){