@Override
	public String replace(String text, ReplaceStrategy s) {
		checkNotNull(text, "Null value not allowed for parameter 'text'");
		checkNotNull(s, "Null value not allowed for parameter 'strategy'");

		StringBuilder ret = new StringBuilder();
		char[] chars = text.toCharArray();
		TrieNode last = this.root;
		int lastIndex = 0;
		/* 保留上一字符匹配到的字符串，比如心事、心事重、心事重重 */
		String preKeyword = null;
		/* 已匹配的关键词个数 */
		int cnt = 0;
		for (int i = lastIndex; i < chars.length; i++) {
			char ch = chars[i];
			if (skipChars.contains(ch)) {
				continue;
			}
			while (last.get(ch) == null) {
				if (last == this.root) {
					break;
				}
				last = last.getFail();
			}
			last = last.get(ch);
			if(null == last) {
				last = root;
			}
			if (!last.getResults().isEmpty()) {
				preKeyword = last.getResults().iterator().next();
				cnt++;
				// 已经匹配到主串的最后一个字符，直接替换
				if (i == chars.length - 1) {
					ret.setLength(ret.length() - (preKeyword.length() - cnt));
					ret.append(s.replaceWith(preKeyword));
				}
			} else if (preKeyword != null) {
				ret.setLength(ret.length() - (preKeyword.length() - cnt));
				ret.append(s.replaceWith(preKeyword));
				ret.append(ch);
				// 重置状态
				preKeyword = null;
				cnt = 0;
			} else {
				ret.append(ch);
			}
		}

		return ret.toString();
	}