解决针对''中含有的相同转义引号(即\')的错误识别,导致的包裹错误问题(双引号同理) #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
更改正则表达式 i18nStrReg :
1、将原代码中的两部分[^'{}\n]* ,更改为(?:[^'{}\n]|\.),解决了词条开头、中间遇到相同转义引号'时,会与'中的引号错误匹配产生词条包裹错误的问题(双引号同理),但此时并不适用于结尾为'的词条(因为会与结尾的'中的\进行匹配,而将'中的'作为词条结束的引号,见Eg2)
Eg1: 词条:''一'、'二'、三'
原始表达式/'([^'{}\n][^\x00-\xff]+[^'{}\n])'/g : 匹配结果是 '一' 和 '二'
第一步修改后表达式/'((?:[^'{}\n]|\.)[^\x00-\xff]+(?:[^'{}\n]|\.))'/g : 匹配结果为 ''一'、'二'、三'
Eg2:词条:''一'、'二'、'三''
原始表达式/'([^'{}\n][^\x00-\xff]+[^'{}\n])'/g : 匹配结果是 '一' 和 '二'和'三'
第一步修改后表达式/'((?:[^'{}\n]|\.)[^\x00-\xff]+(?:[^'{}\n]|\.)*)'/g : 匹配结果为 ''一'、'二'、'三'(最后的'未匹配)
2、为了能够在第一步的基础上解决不适用于结尾为'的词条,将第二部分的(?:[^'{}\n]|\.)改为(?:[^'{}\n\\]|\.),使表达式不与结尾的'中的\进行匹配,不会将'中的'作为词条结束的引号(双引号同理)
Eg3: 词条:''一'、'二'、'三''
原始表达式/'([^'{}\n][^\x00-\xff]+[^'{}\n])'/g : 匹配结果是 '一' 和 '二'和'三'
第一步修改后表达式/'((?:[^'{}\n]|\.)[^\x00-\xff]+(?:[^'{}\n]|\.))'/g : 匹配结果为 ''一'、'二'、'三'
最终表达式/'((?:[^'{}\n]|\.)[^\x00-\xff]+(?:[^'{}\n\\]|\.))'/g :匹配结果是 '一' 和 '二'和'三''
以上双引号均与单引号同理,故最终修改为:
const i18nStrReg = /"((?:[^"{}\n]|\.)[^\x00-\xff]+(?:[^"{}\n\\]|\.))"|'((?:[^'{}\n]|\.)[^\x00-\xff]+(?:[^'{}\n\\]|\.))'/g