C++ Glib::正则表达式拾取TextTag-s
我正在使用Glib::Regex和Gtk::TextView与Gtk::TextBuffer-s进行实验,并尝试使用Gtk::TextTag-s进行语法高亮显示 我的语法更新代码(它在行首和行尾接收迭代器) 因此,将C++ Glib::正则表达式拾取TextTag-s,c++,regex,gtk,glib,C++,Regex,Gtk,Glib,我正在使用Glib::Regex和Gtk::TextView与Gtk::TextBuffer-s进行实验,并尝试使用Gtk::TextTag-s进行语法高亮显示 我的语法更新代码(它在行首和行尾接收迭代器) 因此,将类写入TextView的输出将导致突出显示第一个类,而未拾取第二个类,log: c (added at[1]; with [1]bytes) word: c l (added at[2]; with [1]bytes) word: cl a (added at[3]; with
类写入TextView的输出将导致突出显示第一个类,而未拾取第二个类,log:
c (added at[1]; with [1]bytes)
word: c
l (added at[2]; with [1]bytes)
word: cl
a (added at[3]; with [1]bytes)
word: cla
s (added at[4]; with [1]bytes)
word: clas
s (added at[5]; with [1]bytes)
word: class
class (keyword at: [0;5])
(added at[6]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: r
c (added at[7]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
l (added at[8]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
a (added at[9]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: a
s (added at[10]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: as
s (added at[11]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: ass
很容易注意到,最后一行显示它移动了两个偏移量。可能是应用了标记。还有,这里不清楚的是:word:rd
。我使用关键字
作为标记的名称。当这段代码还在使用迭代器时,info.fetch(1)
返回了“关键字”
,那么regex是否也在匹配标记呢
我希望在Glib和Gtk方面有经验的人知道答案,谢谢。我没有使用这个特定的API yet1,但我认为您在对象生存期方面有问题iter->get\u visible\u text()
返回的字符串对象在调用regex->match()
后被销毁。这是一个问题,因为Glib::MatchInfo::next()
希望该字符串仍然存在2。这可能就是为什么你会在第二场比赛中收到垃圾。我认为你做这样的事情是安全的:
....
auto visbuf = start.get_visible_text(end);
auto ok = regex->match(visbuf, info); // existing line
...
这样我就可以满嘴废话了
来自Glib::MatchInfo::next()文档:匹配是在传递给match函数的字符串上完成的,因此在调用此函数之前无法释放该字符串
我没有注意到match
引用了字符串,谢谢
c (added at[1]; with [1]bytes)
word: c
l (added at[2]; with [1]bytes)
word: cl
a (added at[3]; with [1]bytes)
word: cla
s (added at[4]; with [1]bytes)
word: clas
s (added at[5]; with [1]bytes)
word: class
class (keyword at: [0;5])
(added at[6]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: r
c (added at[7]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
l (added at[8]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
a (added at[9]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: a
s (added at[10]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: as
s (added at[11]; with [1]bytes)
word: class
class (keyword at: [0;5])
word: rd
word: ass
....
auto visbuf = start.get_visible_text(end);
auto ok = regex->match(visbuf, info); // existing line
...