Luca Martinetti
Luca Martinetti

Reputation: 3412

Handling .Net UTF-8 strings in Erlang

I'm playing a bit with erlang and the distributed db Mnesia.

One of the first problem I'm facing is the incompatibilty beetween the 'int list' strings of erlang and .Net UTF-8 strings.

Is there any good conversion library?

Thanks

Upvotes: 0

Views: 1201

Answers (2)

Gordon Guthrie
Gordon Guthrie

Reputation: 6264

The new R13B release of Erlang has better support for unicode.

The new Unicode module is documented here and the Unicode support implemented is described in the EEP 10 (Erlang Enhancement Proposal 10).

Upvotes: 3

Lucero
Lucero

Reputation: 60190

As far as I have seen, erlang uses UTF32, so using System.Text.Encoding.UTF32 might do the trick to get the ints for the list, then you need to create the list from those. Not tested though.

The following snippet may help (it creates an array of unicode ints which should match the ones expected for the erlang list):

public static int[] GetIntsForString(string source) {
    byte[] data = System.Text.Encoding.UTF32.GetBytes(source);
    int[] result = new int[source.Length];
    for (int i = 0; i < source.Length; i++) {
        result[i] = BitConverter.ToInt32(data, i*4);
    }
    return result;
}

Upvotes: 1

Related Questions