-
Notifications
You must be signed in to change notification settings - Fork 244
Find dollar sign in a text string for adding emoji #458
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
Conversation
Yang-33
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @punkzberryz ! Almost all looks good to me. Let me leave minor comments. After fixing minors, this change will be released as v8.7.0!
linebot/find_dollar_sign.go
Outdated
| bytes := utf16.Encode([]rune(text)) | ||
| for i := range bytes { | ||
|
|
||
| if bytes[i] == 36 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify 36 is $, how about this?
| bytes := utf16.Encode([]rune(text)) | |
| for i := range bytes { | |
| if bytes[i] == 36 { | |
| encoded := utf16.Encode([]rune(text)) | |
| for i, unit := range encoded { | |
| if unit == '$' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value unit itself is actually value 36. Because the value has been encoded.
But I see your point. So I will do this instead:
type CharInUTF16 uint16
const dollarSign CharInUTF16 = 36
...
encoded := utf16.Encode([]rune(text))
for i, unit := range encoded {
if unit == uint16(dollarSign) {There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
8edfa94 to
a21cb7f
Compare
aced864 to
4b95277
Compare
Yang-33
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @punkzberryz !
From Easy way to add emoji to text message #456
When we want to add Emoji in text message, we use $ as a placeholder inside the text and provide the index of the $. (ref)
Function FindDollarSignIndexInUni16Text helps to identify the the dollar-sign position inside the string.
Example use case can be found in Kitchen Signk
Example result shown in the image
