int TryGeneratedUtf8EncodeFlat(string input, out string output) { try { var res = UTF8Encoder.Apply(input); output = res; return 0; } catch (Exception e) { output = null; return 1; } }
int TryGeneratedUtf8EncodeStream(string input, out string output) { try { var res = new String(new List<char>(UTF8Encoder.Transduce(input)).ToArray()); output = res; return 0; } catch (Exception e) { output = null; return 1; } }
public static IEnumerable<char> Transduce(IEnumerable<char> input) { var encoder = new UTF8Encoder(); int state = encoder.q0; foreach (char c in input) { foreach (char d in encoder.Psi(state, (int)c)) yield return d; state = encoder.Delta(state, (int)c); } if (encoder.F.Contains(state)) { foreach (char d in encoder.Psi(state, -1)) yield return d; } else throw new Exception("UTF8Encoder"); }