private static Hangul[,] SeparateCode(string code, out int width, out int height, bool utf32Included = false) { var lines = code.Replace("\r\n", "\n").Split('\n'); if (utf32Included) { lines = lines.Select(s => ReplaceUtf32(s)).ToArray(); } height = lines.Length; width = lines.Max(s => s.Length); var board = new Hangul[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (lines[i].Length > j) { board[i, j] = new Hangul(lines[i][j]); } else { board[i, j] = new Hangul(' '); } } } return(board); }
public virtual void Step() { var next = GetNextCursor(); bool?straight = null; switch (CurrentCode.Choseong) { case 'ㅎ': IsExited = true; if (_storage.CanPop(1)) { ExitCode = TToInt(_storage.Pop()); } break; // ㄷ 묶음 case 'ㄷ': straight = _storage.Add(); break; case 'ㄸ': straight = _storage.Mul(); break; case 'ㅌ': straight = _storage.Sub(); break; case 'ㄴ': straight = _storage.Div(); break; case 'ㄹ': straight = _storage.Mod(); break; // ㅂ 묶음 case 'ㅂ': T value; if (CurrentCode.Jongseong == 'ㅇ') { value = NeedInput(true); } else if (CurrentCode.Jongseong == 'ㅎ') { value = NeedInput(false); } else { value = IntToT(Hangul.GetStrokeCount(CurrentCode.Jongseong)); } _storage.Push(value); break; case 'ㅁ': if (_storage.TryPop(out T popped)) { if (CurrentCode.Jongseong == 'ㅇ') { NeedOutput(popped, true); } else if (CurrentCode.Jongseong == 'ㅎ') { NeedOutput(popped, false); } } else { straight = false; } break; case 'ㅃ': straight = _storage.Duplicate(); break; case 'ㅍ': straight = _storage.Swap(); break; // ㅅ 묶음 case 'ㅅ': _storage.Select(CurrentCode.Jongseong); break; case 'ㅆ': straight = _storage.Move(CurrentCode.Jongseong); break; case 'ㅈ': straight = _storage.Compare(); break; case 'ㅊ': straight = _storage.Conditional(); break; } if (straight == false) { next.Reverse(); } next.Step(); _cursor = next; }