Make dialog parser and keyword lines work with 4 byte unicode
This commit is contained in:
@@ -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
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user