bugfix:正则表达式字符转义 - #1
Merged
Merged
Conversation
Owner
|
一开始的时候我也思考过这个问题。但是后来想了想,其实不存在这样的情况。因为你仔细查看代码。 public void OnSelectionChanged(TextManager textManager, int nStart, int nLen) {
// ... other code ...
var line = textManager.GetLineFromCharIndex(nStart);
// m_spliter -> 单词拆分器 确保m_spliter.Each()中每一个都是完整的单词。当然如果m_spliter没有bug的话
m_spliter.Each(line.RawString, nStart - line.IndexOfFirstChar, (str, ns, nl) => {
// ns -> Index of word Start
// nl -> Length of word
if (ns + line.IndexOfFirstChar == nStart && nLen == nl) {
strKey = str.Substring(ns, nl);
}
// 所以上面的判断是
// 如果当前选中的起始索引和它起始行所在的某个单词的索引一致
// 并且
// 选中的长度和单词长度一致
// strKey 才是有效的 所以strKey中间不会出现任何正则相关的字符 因为那将变成多个单词
return false;
});
// ... other code ...
}如果你有一下文本 如果你选中 |
Author
|
你说的有道理。 |
Owner
|
确实会有你提到的问题。如果是选择单词没有任何问题。。如果选择的是一些或者一个符号就可能会出现bug。因为单独的或者同系列的符号也会被
private Regex m_reg_reg = new Regex(@"([*.?+$^\[\](){}|\\])");
//...
strKey = m_reg_reg.Replace(strKey, @"\$1"); |
DebugST
added a commit
that referenced
this pull request
Mar 3, 2023
DebugST
added a commit
that referenced
this pull request
Mar 3, 2023
DebugST
added a commit
that referenced
this pull request
Mar 3, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
当选中编辑器里的字符时,需对正则表达式的保留字符转义