关于在 tutorial02 中验证数字

作者: imba-tjd创建于 2018年9月3日更新于 2024年1月21日

emm This part has already been done at https://GitHub.com/miloyip/json-tutorial/issues/15. I tried to implement the validate number in Tutorial 2's lept_parse_number without seeing the answer, and found that the meaning is different from the answer. The result I got is that I check the json string in the context until the end, and return LEPT_PARSE_INVALID_VALUE as long as there is a character that does not meet the requirements. So when I saw the test case, I was surprised that 0x0 is actually LEPT_PARSE_ROOT_NOT_SINGULAR, and in theory, x is an illegal character. Also, I found that 1. was tested but not 1e. In fact, 1. can be converted to 1, while 1e will cause an error. So I think it should be included in the test for LEPT_PARSE_INVALID_VALUE.

However, after seeing the answer, I found that it is enough to find the first position where the complete parsing is completed, and the rest should be considered as LEPT_PARSE_ROOT_NOT_SINGULAR. After thinking carefully, this is also the case, and the above questions are no longer there.

内容来源: miloyip/json-tutorial