Scintilla:如何找到给定特定字符位置的字节位置

发布于 2024-10-08 08:22:09 字数 140 浏览 0 评论 0原文

给定一行上的特定字符索引,例如第 3 行上的第 10 个字符,是否有一种简单的方法来计算 Scintilla 的该字符的“位置”?

使用 ASCII 字符时很简单,但使用多字节 UTF-8 字符时我看不到简单的方法,其中单个字符可能占用多个字节位置。

Given a specific character index on a line, e.g. 10th character on line 3, is there an easy way to calculate Scintilla's 'position' of that character?

It's straight forward when using ASCII characters but I can't see an easy way to do it when using multi-byte UTF-8 characters, where a single character may take up several byte positions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心在旅行 2024-10-15 08:22:09

将行文本转换为 UTF8,然后计算字节位置。如果可能发出多个请求,则缓存转换。

Convert line text to UTF8 and then count the byte positions. Cache conversion if multiple requests may be made.

蛮可爱 2024-10-15 08:22:09

您应该从字符串的开头开始并索引到字符串,无论当前位置的字符对应多少个字节(以便您现在索引下一个字符),并记录到目前为止您已经看到的字符数。这种线性时间索引是 UTF-8 的缺点之一。也许 Scintilla 已经有能力做到这一点。

You should start at the beginning of the string and index into the string however many bytes correspond to the character in the current position, (so that you now index the next character), and keep a count of how many characters you have seen so far. This linear-time indexing is one of the drawbacks of UTF-8. Maybe Scintilla already has a facility to do this.

渔村楼浪 2024-10-15 08:22:09

您是否尝试过:SCI_FINDCOLUMN?:
SCI_FINDCOLUMN(int行,int列)
此消息返回行上列的位置,并考虑制表符的宽度。它将多字节字符视为单列。列号,如行号,从 0 开始。

Did you tried: SCI_FINDCOLUMN ?:
SCI_FINDCOLUMN(int line, int column)
This message returns the position of a column on a line taking the width of tabs into account. It treats a multi-byte character as a single column. Column numbers, like lines start at 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文