Skip to content

Commit 870d538

Browse files
committed
Add header
1 parent 23577f6 commit 870d538

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tutorial04_answer/tutorial04_answer.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
本文是[《从零开始的 JSON 库教程》](https://zhuanlan.zhihu.com/json-tutorial)的第四个单元解答篇。解答代码位于 [json-tutorial/tutorial04_answer](https://github.com/miloyip/json-tutorial/blob/master/tutorial04_answer)
77

8-
1. 实现 `lept_parse_hex4()`
8+
## 1. 实现 `lept_parse_hex4()`
99

1010
这个函数只是读 4 位 16 进制数字,可以简单地自行实现:
1111

@@ -37,7 +37,7 @@ static const char* lept_parse_hex4(const char* p, unsigned* u) {
3737

3838
但这个实现会错误地接受 `"\u 123"` 这种不合法的 JSON,因为 `strtol()` 会跳过开始的空白。要解决的话,还需要检测第一个字符是否 `[0-9A-Fa-f]`,或者 `!isspace(*p)`。但为了 `strtol()` 做多余的检测,而且自行实现也很简单,我个人会选择首个方案。(前两个单元用 `strtod()` 就没辨法,因为它的实现要复杂得多。)
3939

40-
2. 实现 `lept_encode_utf8()`
40+
## 2. 实现 `lept_encode_utf8()`
4141

4242
这个函数只需要根据那个 UTF-8 编码表就可以实现:
4343

@@ -66,7 +66,7 @@ static void lept_encode_utf8(lept_context* c, unsigned u) {
6666
6767
其实超过 1 个字符输出时,可以只调用 1 次 `lept_context_push()`。这里全用 `PUTC()` 只是为了代码看上去简单一点。
6868
69-
3. 代理对的处理
69+
## 3. 代理对的处理
7070
7171
遇到高代理项,就需要把低代理项 `\uxxxx` 也解析进来,然后用这两个项去计算出码点:
7272
@@ -89,10 +89,10 @@ case 'u':
8989
break;
9090
~~~
9191

92-
4. 总结
92+
## 4. 总结
9393

9494
JSON 的字符串解析终于完成了。但更重要的是,同学通过教程和练习后,应该对于 Unicode 和 UTF-8 编码有基本了解。使用 Unicode 标准去处理文本数据已是世界潮流。虽然 C11/C++11 引入了 Unicode 字符串字面量及少量函数,但仍然有很多不足,一般需要借助第三方库。
9595

96-
我们在稍后的单元还要处理生成时的 Unicode 问题。
96+
我们在稍后的单元还要处理生成时的 Unicode 问题,接下来我们要继续讨论数组和对象的解析
9797

9898
如果你遇到问题,有不理解的地方,或是有建议,都欢迎在评论或 [issue](https://github.com/miloyip/json-tutorial/issues) 中提出,让所有人一起讨论。

0 commit comments

Comments
 (0)