From 60588c52f372ba7d8cd80df128272af3752c9d90 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Fri, 18 Aug 2023 11:28:34 +0800 Subject: [PATCH] doc: update docs/toml.md --- docs/toml.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 145 insertions(+), 15 deletions(-) diff --git a/docs/toml.md b/docs/toml.md index fb19b93..2270bdf 100644 --- a/docs/toml.md +++ b/docs/toml.md @@ -114,17 +114,47 @@ array3 = [ TOML 字符串 ----- -### 多行字符串 +### 基本字符串 ```toml -multiLineString = """ -Multi-line basic strings are surrounded -by three quotation marks on each side -and allow newlines. -""" +str1 = "I'm a string." +str2 = "You can \"quote\" me." +str3 = "Name\tJos\u00E9\nLoc\tSF." ``` -### 文字字符串 +### 多行基本字符串 + + +```toml +str1 = """ +Roses are red +Violets are blue""" + +str2 = """\ + The quick brown \ + fox jumps over \ + the lazy dog.\ + """ +``` + +用行末反斜杠自动剔除非空白字符前的任何空白字符 + +### 多行文字字符串 + + +```toml +re = '''\d{2} apps is t[wo]o many''' +lines = ''' +The first newline is +trimmed in raw strings. +All other whitespace +is preserved. +''' +``` + +由于没有转义,无法在由单引号包裹的字面量字符串中写入单引号 + +### 字面量字符串 ```toml path = 'C:\Users\nodejs\templates' @@ -135,16 +165,116 @@ regex = '<\i\c*\s*>' 用单引号括起来。不允许转义。 -### 多行文字字符串 +TOML 数字 +----- + +整数、浮点数、无穷甚至非数都是支持的。你可以用科学计数法甚至千分符 + +### 整数 ```toml -re = '''\d{2} apps is t[wo]o many''' -lines = ''' -The first newline is -trimmed in raw strings. -All other whitespace -is preserved. -''' +int1 = +99 +int2 = 42 +int3 = 0 +int4 = -17 +``` + +### 十六进制带有前缀 `0x` + +```toml +hex1 = 0xDEADBEEF +hex2 = 0xdeadbeef +hex3 = 0xdead_beef +``` + +### 八进制带有前缀 `0o` + +```toml +oct1 = 0o01234567 +oct2 = 0o755 +``` + +### 二进制带有前缀 `0b` + +```toml +bin1 = 0b11010110 +``` + +### both + +```toml +float7 = 6.626e-34 +``` + +### 分隔符 + +```toml +float8 = 224_617.445_991_228 +``` + +### 小数 + +```toml +float1 = +1.0 +float2 = 3.1415 +float3 = -0.01 +``` + +### 指数 + +```toml +float4 = 5e+22 +float5 = 1e06 +float6 = -2E-2 +``` + +### 无穷 + +```toml +infinite1 = inf # 正无穷 +infinite2 = +inf # 正无穷 +infinite3 = -inf # 负无穷 +``` + +### 非数 + +```toml +not1 = nan +not2 = +nan +not3 = -nan +``` + +TOML 日期与时刻 +----- + +TOML 支持日期、时刻、日期时刻,带或者不带时区偏移 + +### 坐标日期时刻 + +```toml +odt1 = 1979-05-27T07:32:00Z +odt2 = 1979-05-27T00:32:00-07:00 +odt3 = 1979-05-27T00:32:00.999999-07:00 +``` + +### 各地日期时刻 + +```toml +ldt1 = 1979-05-27T07:32:00 +ldt2 = 1979-05-27T00:32:00.999999 +``` + +### 各地日期 + +```toml +ld1 = 1979-05-27 +``` + +### 各地时刻 + +```toml +lt1 = 07:32:00 +lt2 = 00:32:00.999999 ``` TOML Tables