/** * Create a list of Erlang integers representing Unicode codePoints. * This method does not check if the string contains valid code points. */ public OtpErlangList(string str) : base(str.Length) { if (string.IsNullOrWhiteSpace(str)) { return; } AddRange(OtpErlangString.ToCodePoints(str).Select((cp) => new OtpErlangInt(cp))); }
/** * Write a string to the stream. */ public void WriteString(string s) { int len = s.Length; switch (len) { case 0: WriteNil(); break; default: if (len <= 65535 && Is8bitString(s)) // 8-bit string { try { byte[] bytebuf = Encoding.GetEncoding("ISO-8859-1").GetBytes(s); Write1(OtpExternal.stringTag); Write2BE(len); WriteN(bytebuf); } catch (EncoderFallbackException) { WriteNil(); // it should never ever get here... } } else // unicode or longer, must code as list { int[] codePoints = OtpErlangString.ToCodePoints(s); WriteListHead(codePoints.Length); foreach (int codePoint in codePoints) { WriteInt(codePoint); } WriteNil(); } break; } }