Skip to content

Commit 9286b5c

Browse files
committed
Merge branch 'main' of github.com:abetlen/llama_cpp_python into main
2 parents f116175 + 3226b3c commit 9286b5c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

llama_cpp/llama_grammar.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,17 +556,11 @@ def add_rule(
556556
# }
557557
def decode_utf8(src: const_char_p) -> Tuple[int, const_char_p]:
558558
"""Decodes a UTF-8 character from the source string."""
559-
lookup = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4)
560-
first_byte = ord(src[0]) # type: int
561-
highbits = first_byte >> 4 # type: int
562-
len = lookup[highbits] # type: int
563-
mask = (1 << (8 - len)) - 1 # type: int
564-
value = first_byte & mask # type: int
565-
end = src + len # type: const_char_p # may overrun!
566-
pos = src + 1 # type: const_char_p
567-
while pos < end and pos[0]:
568-
value = (value << 6) + (ord(pos[0]) & 0x3F)
569-
pos += 1
559+
# Get the codepoint of the first character
560+
value = ord(src[0])
561+
# Move the pointer ahead one character
562+
pos = src + 1
563+
570564
return value, pos
571565

572566

0 commit comments

Comments
 (0)