mirror of
https://github.com/toolgood/ToolGood.Words.git
synced 2026-10-17 04:40:38 +08:00
120 lines
3.3 KiB
HTML
120 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<meta name="referrer" content="always" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<title></title>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="result">
|
|
|
|
</div>
|
|
<script src="ToolGood.Words.StringSearch.js"></script>
|
|
<script src="ToolGood.Words.WordsSearch.js"></script>
|
|
<script>
|
|
function log(txt) {
|
|
var ele = document.getElementById("result");
|
|
ele.innerText = ele.innerText + "\r\n" + txt;
|
|
}
|
|
var s = "中国|国人|zg人";
|
|
var test = "我是中国人";
|
|
|
|
log("----------------------------------- StringSearch -----------------------------------");
|
|
var iwords = new StringSearch();
|
|
iwords.SetKeywords(s.split('|'));
|
|
|
|
log("StringSearch ContainsAny is run.");
|
|
var b = iwords.ContainsAny(test);
|
|
if (b == false) {
|
|
log("StringSearch ContainsAny is error.");
|
|
}
|
|
|
|
log("StringSearch FindFirst is run.");
|
|
var f = iwords.FindFirst(test);
|
|
if (f != "中国") {
|
|
log("StringSearch FindFirst is error.");
|
|
}
|
|
|
|
log("StringSearch FindAll is run.");
|
|
var all = iwords.FindAll(test);
|
|
if (all[0] != "中国") {
|
|
log("StringSearch FindAll is error.");
|
|
}
|
|
if (all[1] != "国人") {
|
|
log("StringSearch FindAll is error.");
|
|
}
|
|
if (all.length != 2) {
|
|
log("StringSearch FindAll is error.");
|
|
}
|
|
|
|
log("StringSearch Replace is run.");
|
|
var str = iwords.Replace(test, '*');
|
|
if (str != "我是***") {
|
|
log("StringSearch Replace is error.");
|
|
}
|
|
|
|
|
|
log("----------------------------------- WordsSearch -----------------------------------");
|
|
|
|
var wordsSearch = new WordsSearch();
|
|
wordsSearch.SetKeywords(s.split('|'));
|
|
|
|
log("WordsSearch ContainsAny is run.");
|
|
b = wordsSearch.ContainsAny(test);
|
|
if (b == false) {
|
|
log("WordsSearch ContainsAny is error.");
|
|
}
|
|
|
|
|
|
|
|
log("WordsSearch FindFirst is run.");
|
|
var f = wordsSearch.FindFirst(test);
|
|
if (f.Keyword != "中国") {
|
|
log("WordsSearch FindFirst is error.");
|
|
}
|
|
|
|
|
|
log("WordsSearch FindAll is run.");
|
|
var alls = wordsSearch.FindAll(test);
|
|
if (alls[0].Keyword != "中国") {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
if (alls[1].Keyword != "国人") {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
if (alls.length != 2) {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
if (alls[0].Start != 2) {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
if (alls[0].End != 3) {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
if (alls[0].Index != 0) {
|
|
log("WordsSearch FindAll is error.");
|
|
}
|
|
|
|
|
|
|
|
|
|
log("WordsSearch Replace is run.");
|
|
var t = wordsSearch.Replace(test, '*');
|
|
if (str != "我是***") {
|
|
log("WordsSearch Replace is error.");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log("----------------------------------- Test End -----------------------------------");
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |