shotleybuilder

shotleybuilder

Unicode for emoji - string concatenation

Hi,

I’m not understanding the behaviour when including unicode inside a string which is then string concatenated. The resulting string is not known when streamed into a file.

Here’s something that works:
"❔ foobar" -> "❔ foobar"
This works
"\u2754 foobar" -> "❔ foobar"

This doesn’t work:
"❔" <> "foobar" -> �
Neither does this
"\u2754" <> "foobar" -> �

What am I missing?

First Post!

NobbZ

NobbZ

works for me:

Erlang/OTP 22 [erts-10.7] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Interactive Elixir (1.10.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> "❔" <> "foobar"
"❔foobar"

Most Liked

NobbZ

NobbZ

+U274c is represented by these 3 bytes in utf8: 0xE2 0x9D 0x8C.

If your terminal doesn’t support utf8, then you should probably inspect on a byte level rather than printed representation.

As you have not specified your terminals encoding, basically everything can be triggered by these bytes.

Assuming latin-X, which is often used in the windows world, then the 8x and 9x bytes are not used and can cause weirdnesses.

kip

kip

ex_cldr Core Team
iex> << 0x1F517 :: utf8 >>
"🔗"

iex> << 0xF0, 0x9F, 0x94, 0x97 >>
"🔗"

iex> << 0xF0, 0x9F, 0x94, 0x97>> == << 0x1f517 :: utf8 >>
true

d8 3d dd 17 is the UTF16 representation. Elixir is a UTF8 language where the encoding is f0 9f 94 97.

kip

kip

ex_cldr Core Team

With a little bit of erlang magic:

iex> :erlang.binary_to_list << 0x1f517 :: utf8 >>       
[240, 159, 148, 151]

I have a unicode library that examines code points. For example:

iex> Unicode.category << 0x1F49A :: utf8 >>             
[:So]
iex> Unicode.properties << 0x1F49A :: utf8 >>                                                                          
[[:emoji, :grapheme_base]]

Unfortunately the Regex module doesn’t support the Unicode character class [:So:]. Or any other Unicode character classes. I have another lib unicode_set that has some support for Unicode character classes. But regexes not yet - soon though.

Last Post!

LostKobrakai

LostKobrakai

iex(2)> IEx.configure inspect: [base: :hex]
:ok
iex(3)> << 0x1f517 :: utf8 >>
<<0xF0, 0x9F, 0x94, 0x97>>

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement