1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00

ch1-03: 更新图片

This commit is contained in:
chai2010 2018-07-25 06:57:04 +08:00
parent 5536342a09
commit edcba4cba7
7 changed files with 21 additions and 2 deletions

View File

@ -158,7 +158,7 @@ type StringHeader struct {
我们可以看看字符串“Hello, world”本身对应的内存结构
![](../images/ch1-03-string-1.png)
![](../images/ch1-03-string-1.ditaa.png)
分析可以发现“Hello, world”字符串底层数据和以下数组是完全一致的
@ -208,7 +208,7 @@ fmt.Println("\xe7\x95\x8c") // 打印: 界
下图展示了“Hello, 世界”字符串的内存结构布局:
![](../images/ch1-03-string-2.png)
![](../images/ch1-03-string-2.ditaa.png)
Go语言的字符串中可以存放任意的二进制字节序列而且即使是UTF8字符序列也可能会遇到坏的编码。如果遇到一个错误的UTF8编码输入将生成一个特别的Unicode字符\uFFFD这个字符在不同的软件中的显示效果可能不太一样在印刷中这个符号通常是一个黑色六角形或钻石形状里面包含一个白色的问号<E58FB7>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -0,0 +1,14 @@
hello, world
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| ... | h | e | l | l | o | , | | w | o | r | l | d | ... |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
^ ^
| |
+-----------=-+ :
| | |
+-----+---+ +---+----+ +---+----+
| data | | data | | data |
+---------+ +--------+ +--------+
| len: 12 | | len: 5 | | len: 5 |
+---------+ +--------+ +--------+
hello, world hello world

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -0,0 +1,5 @@
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| ... | h | e | l | l | o | , | | E4 | B8 | 96 | E7 | 95 | 8C | ... |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|<-------=- UTF8 Encoding -=-------->|

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB