Make dialog parser and keyword lines work with 4 byte unicode

This commit is contained in:
Veronica Berglyd Olsen
2025-07-05 01:50:47 +02:00
parent f8a333c4ea
commit 57bed18ccf
3 changed files with 45 additions and 9 deletions
+15
View File
@@ -493,6 +493,21 @@ def decodeMimeHandles(mimeData: QMimeData) -> list[str]:
return mimeData.data(nwConst.MIME_HANDLE).data().decode().split("|")
def utf16CharMap(text: str) -> list[int]:
"""Compute mapping from Python string index to QString index.
Python strings are always one character per position in either
ASCII, UCS-2 or UCS-4. QStrings are in UTF-16, so wide characters
use 2 indices, and thus creates an offset.
"""
posMap = list(range(0, len(text) + 1))
offset = 0
for i, c in enumerate(text):
if ord(c) > 0xffff:
offset += 1
posMap[i + 1] = i + 1 + offset
return posMap
##
# Encoder Functions
##