I wasn't aware of a general-purpose "doifstartswith" macro in ConTeXt (the \doifnextcharelse macro only works one character at a time, and the \doifinstring macros may capture substrings that are not prefixes), and I'd like to develop one for something I'm working on. I've been trying to do this in Lua, as that seemed like the most natural approach. Normally, something like this would work fine as a foundation: ``` function isprefix(prefix, str) if string.sub(str, 1, string.len(prefix)) == prefix then return true end return false end ``` Unfortunately, if I want to check for prefixes that include two-byte characters like § and ¶, then the positions and string lengths that I specify no longer correspond to the actual byte offsets and lengths that Lua uses. I'm aware of the utf8 plugin that was intended to address this issue, but the following code also isn't working: ``` function sbl.isprefix(prefix, str) -- lua is devious and measures string length in bytes, not chars, -- so we can't just use string.sub and string.len as we normally would. local i = utf8.offset(str, 1) local j = utf8.offset(str, utf8.len(prefix) + 1) - 1 if string.sub(str, i, j) == prefix then return true end return false end ``` The only other detail that may be relevant is that I'm passing a macro as the "str" input. But this should be expanded when the Lua code is manipulating it, right? I'm sure there's something obvious that I'm doing wrong, but I've been trying to get this to work for at least a couple hours now, and I don't know what else to try. If there is a simple fix to my Lua code or an existing ConTeXt macro that will get the job done, I'd appreciate it! Joey