Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎯 poc/string length #5001

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions emojis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const messages = [
"This is a message with a 👍",
"This is a message with a 👍🏾",
"This is a message with a 👍🏾👍",
]

messages.forEach(message => {
console.log(message, message.length);
})
12 changes: 12 additions & 0 deletions emojis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def jslen(string):
return int(len(string.encode(encoding='utf_16_le'))/2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is that I don't understand why we need to specify the encoding to be utf_16_le when we are using utf-8 for everything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the problem to solve is to keep aligned string lengths between python and javascript. Spans boundaries are defined in python, and probably will be processed in python. We need to ensure that the same piece of text will be processed in both python and javascript. Here is an article about span processing

https://betterprogramming.pub/slicing-strings-containing-emoji-differences-between-python-and-javascript-4716c419718f

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi team, this feat does not work with utf 8



array = [
'This is a message with a 👍',
'This is a message with a 👍🏾',
'This is a message with a 👍🏾👍',
]

for i in array:
print(i, jslen(i))
Loading