(query: string, options: SearchOptions)
| 24 | * 根据搜索选项创建正则表达式 |
| 25 | */ |
| 26 | export function createSearchPattern(query: string, options: SearchOptions): RegExp | null { |
| 27 | if (!query) return null |
| 28 | |
| 29 | try { |
| 30 | let pattern = options.useRegex ? query : escapeRegExp(query) |
| 31 | |
| 32 | if (options.matchWholeWord) { |
| 33 | pattern = `\\b${pattern}\\b` |
| 34 | } |
| 35 | |
| 36 | return new RegExp(pattern, options.matchCase ? 'g' : 'gi') |
| 37 | } catch { |
| 38 | // 无效的正则表达式 |
| 39 | return null |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * 在消息列表中查找所有匹配项 |
no test coverage detected