vscode 源码学到的技巧

将json格式中的非json替换

		// First group matches a double quoted string
		// Second group matches a single quoted string
		// Third group matches a multi line comment
		// Forth group matches a single line comment
		// Fifth group matches a trailing comma
		const regexp = /("[^"\\]*(?:\\.[^"\\]*)*")|('[^'\\]*(?:\\.[^'\\]*)*')|(\/\*[^\/\*]*(?:(?:\*|\/)[^\/\*]*)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))|(,\s*[}\]])/g;
		/**
		 *
		 * @param {string} content
		 * @returns {string}
		 */
		function stripComments(content) {
			return content.replace(regexp, function (match, _m1, _m2, m3, m4, m5) {
				// Only one of m1, m2, m3, m4, m5 matches
				if (m3) {
					// A block comment. Replace with nothing
					return '';
				} else if (m4) {
					// Since m4 is a single line comment is is at least of length 2 (e.g. //)
					// If it ends in \r?\n then keep it.
					const length = m4.length;
					if (m4[length - 1] === '\n') {
						return m4[length - 2] === '\r' ? '\r\n' : '\n';
					}
					else {
						return '';
					}
				} else if (m5) {
					// Remove the trailing comma
					return match.substring(1);
				} else {
					// We match a string
					return match;
				}
			});
		}

例子:
启动argv.json文件

// This configuration file allows you to pass permanent command line arguments to VS Code.
// Only a subset of arguments is currently supported to reduce the likelihood of breaking
// the installation.
//
// PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
//
// NOTE: Changing this file requires a restart of VS Code.
{
	// Use software rendering instead of hardware accelerated rendering.
	// This can help in cases where you see rendering issues in VS Code.
	// "disable-hardware-acceleration": true,

	// Allows to disable crash reporting.
	// Should restart the app if the value is changed.
	"enable-crash-reporter": true,

	// Unique id used for correlating crash reports sent from this instance.
	// Do not edit this value.
	"crash-reporter-id": "7d869ddc-01cd-4184-a9bb-029e673556b1"
}

替换后








{






        "enable-crash-reporter": true,



        "crash-reporter-id": "7d869ddc-01cd-4184-a9bb-029e673556b1"       
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值