如何进行 Gtk TextIter 算术
我正在尝试使用 Gtk TextIter 对象从 TextBuffer 中提取三个字符的切片,但在算术上遇到了问题。我设置了一个迭代器 p 来指向范围的开头,并希望 q 指向后面的三个字符。
我已经尝试过了...
q = p + 3; // Doesn't compile
q = p; q += 3; // Doesn't compile
q = p; q++; q++; q++; // Happy
我想知道正确的方法是什么。第三种方法可行,但看起来像是一种可怕的黑客行为。
有什么想法吗?
I am attempting to use Gtk TextIter objects to lift three-character slices out of a TextBuffer, but am having trouble with the arithmetic. I set up an iterator p to point to the start of the range and want q to point to three characters further on.
I have tried...
q = p + 3; // Doesn't compile
q = p; q += 3; // Doesn't compile
q = p; q++; q++; q++; // Happy
I'd like to know what the correct way to do this is. The third method works, but looks like a ghastly hack.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您阅读文档,您会看到
TextIter
没有+
或+=
运算符。它是一个双向迭代器,而不是随机访问迭代器,所以这是应该的。您可以使用:
或
If you read the documentation you'll see that
TextIter
doesn't have a+
or+=
operator. It's a bidirectional iterator and not a random access iterator so this is as it should be.You can use either:
or
这很奇怪。
底层 C API 具有
gtk_text_iter_forward_chars()
应该做正确的事情。也许阅读源代码,和/或在 C++ 包装器上提交错误?That's weird.
The underlying C API has
gtk_text_iter_forward_chars()
which should do the right thing. Maybe read the source, and/or file a bug on the C++ wrapper?