0

I want to convert a UnicodeString using ICU to a UTF-16 string, encoded in big-endian, for sending through a socket.

The big-endian thing is messing me up. I can't seem to find any resources relating to the topic with ICU and C++. Using C#, I could do System.Text.Encoding.BigEndianUnicode.GetBytes, but ICU seems to offer me no such alternative.

How do I convert an ICU UnicodeString into a big-endian, UTF-16 byte array?

Dylan
  • 572
  • 5
  • 10
  • well, if you KNOW that your string is big endian, socket ordering is also big endian, so you could simply ommit the htons call that you would normally do to convert your shorts to network order. – camelccc May 01 '13 at 11:07
  • I don't understand what you mean, but I have a question. Given a UTF-16 Unicode array, can I simply read each short from the array and swap it? I think that's logical, but I'm not sure about the whole Unicode thing. I'm going to see if I can do that in C# though, to check. – Dylan May 01 '13 at 11:24

1 Answers1

0

I sorted it, all I had to do was read each 2 byte (16 bit) character and swap the endianess manually. I thought it'd be more complicated, but I guess not.

Dylan
  • 572
  • 5
  • 10