Skip to content

Commit

Permalink
#2 改正正则表达
Browse files Browse the repository at this point in the history
  • Loading branch information
testacount1 committed Oct 19, 2018
1 parent 3e0c990 commit 77890f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions test/释义处理测试.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
在Chrome下运行, 不知为何在火狐中报错: invalid regexp group
*/

QUnit.test("分词性", function (assert) {
assert.deepEqual(
分词性("n. 种类, 方式\\nvt. 分类", 词性),
Expand Down Expand Up @@ -70,10 +74,16 @@ QUnit.test("拆分骆驼命名_多个单词", function (assert) {
"");
});

// TODO: 修复
/*QUnit.test("拆分骆驼命名_全大写单词", function (assert) {
QUnit.test("拆分骆驼命名_全大写单词", function (assert) {
assert.deepEqual(
拆分骆驼命名("READING"),
["READING"],
"");
});*/
});

QUnit.test("拆分骆驼命名_部分连续大写单词", function (assert) {
assert.deepEqual(
拆分骆驼命名("HTMLElement"),
["HTML", "Element"],
"");
});
3 changes: 2 additions & 1 deletion 功用/文本处理.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ function 取字段中最长句(字段) {
}

function 拆分骆驼命名(命名) {
return 命名.split(/(?=[A-Z])/);
// 参考: https://stackoverflow.com/a/7599674/1536803
return 命名.split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/);
}

0 comments on commit 77890f1

Please sign in to comment.