- a simple string split for nest block
- the default block is '【' and '】'
- for test block-comments in nvalng, nvlang NOT support /* AND */
- npm install nv-string-nest
const {s2rng_json, s2str_json, _s2json_eng} = require("nv-string-nest");
s2str_json(s, L="【", R="】" )
s2rng_json(s:<s.length MUST le 67_108_864> L="【", R="】" )
// 67_108_864 (2**64) IS:
// the max <AS JString>'length for each code-file in nvalng
// 2**26
var cmt = `
{
k 【k.lengh must < 16】 : 100,
d : null 【
//如果不是null 需要包含d0
d0 : 【
d00: ~Number
d01: ~String
】
】,
a : [1,2,3,4,5]
}
`
var [bcmt, codes] = s2str_json(cmt);
> bcmt
[
[ 'k.lengh must < 16' ],
[
'\n \n //如果不是null 需要包含d0\n d0 : ',
[
'\n' +
' d00: ~Number\n' +
' d01: ~String\n' +
' '
],
'\n \n '
],
[ '...' ]
]
>
> console.log(codes.join(""))
{
k : 100,
d : null ,
a : [1,2,3,4,5]
}
using range, this is for transfer using
const {encd_srng,decd_srng} =require("nv-facutil-csutil");
var [bcmt, codes] = s2rng_json(cmt);
> bcmt
[
[ 2550136887 ],
[ 7985955005, [ 12750684451 ], 19595788616 ],
[ 25635586433 ]
]
>
> codes
[ 37, 3758096502, 22078816637, 25904021963 ]
>
>
> decd_srng(2550136887)
[ 38, 55 ]
> cmt.slice(38,55)
'k.lengh must < 16'
>
>
// box is just a array; TO stop iteration
> var [bcmt, codes] = _s2json_eng(cmt);
>
> bcmt
[
[ ___Box___(2) [ 38, 55 ] ],
[
___Box___(2) [ 119, 189 ],
[ [___Box___] ],
___Box___(2) [ 292, 328 ]
],
[ ___Box___(2) [ 382, 385 ] ]
]
> codes
[
___Box___(2) [ 0, 37 ],
___Box___(2) [ 56, 118 ],
___Box___(2) [ 329, 381 ],
___Box___(2) [ 386, 459 ]
]
>
>
{
check_pair_cfg: [Function: check_pair_cfg],
_char: {
zh_lbk_cd: 12304,
zh_rbk_cd: 12305,
zh_langle_cd: 12298,
zh_rangle_cd: 12299,
zh_lp_cd: 65288,
zh_rp_cd: 65289,
zh_lbk_ch: '【',
zh_rbk_ch: '】',
zh_langle_ch: '《',
zh_rangle_ch: '》',
zh_lp_ch: '(',
zh_rp_ch: ')'
},
DFLT_ENCD: [Function: DFLT_ENCD],
_s2json_eng: [Function: _s2json_eng],
S2RNG_ENCD: [Function: S2RNG_ENCD],
s2rng_json: [Function: s2rng_json],
S2STR_ENCD: [Function: S2STR_ENCD],
s2str_json: [Function: s2str_json]
}