IronRuby.StandardLibrary.Yaml.Emitter.WriteFolded C# (CSharp) Method

WriteFolded() private method

private WriteFolded ( string text ) : void
text string
return void
        private void WriteFolded(string/*!*/ text) {
            WriteIndicator(">" + DetermineChomp(text), true, false, false);
            WriteIndent();
            bool leadingSpace = false;
            bool spaces = false;
            bool breaks = false;
            int start = 0, ending = 0;

            string data;
            while (ending <= text.Length) {
                char ceh = '\0';
                if (ending < text.Length) {
                    ceh = text[ending];
                }
                if (breaks) {
                    if (ceh == 0 || !('\n' == ceh)) {
                        if (!leadingSpace && ceh != 0 && ceh != ' ' && text[start] == '\n') {
                            WriteLineBreak();
                        }
                        leadingSpace = ceh == ' ';

                        // q sequence of eolns followed by non-eoln:
                        for (int i = start; i < ending; i++) {
                            WriteLineBreak();
                        }

                        if (ceh != 0) {
                            WriteIndent();
                        }
                        start = ending;
                    }
                } else if (spaces) {
                    if (ceh != ' ') {
                        if (start + 1 == ending && _column > _bestWidth) {
                            WriteIndent();
                        } else {
                            data = text.Substring(start, ending - start);
                            _column += data.Length;
                            _writer.Write(data);
                        }
                        start = ending;
                    }
                } else {
                    if (ceh == 0 || ' ' == ceh || '\n' == ceh) {
                        data = text.Substring(start, ending - start);
                        _writer.Write(data);
                        if (ceh == 0) {
                            WriteLineBreak();
                        }
                        start = ending;
                    }
                }
                if (ceh != 0) {
                    breaks = '\n' == ceh;
                    spaces = ceh == ' ';
                }
                ending++;
            }
        }