Beispiel #1
0
 /// <summary>
 /// Insert in the buffer a text line that can be split.
 /// </summary>
 /// <param name="text">The text</param>
 /// <param name="from">from position in the buffer</param>
 /// <param name="to">to position in the buffer</param>
 /// <param name="bInsertSplit">true if splitting must handle, false otherwise</param>
 private void InsertLineMaybeSplit(SourceText buffer, string text, int from, int to, bool bInsertSplit)
 {
     if (bInsertSplit && this.Layout == ColumnsLayout.CobolReferenceFormat)
     {
         int crPos = text.LastIndexOf('\r');
         int lfPos = text.LastIndexOf('\n');
         int crlf  = 0;
         crlf += crPos >= 0 ? 1 : 0;
         crlf += lfPos >= 0 ? 1 : 0;
         int lineStartOffset;
         int lineEndOffset;
         int lineLen = buffer.GetLineInfo(from, out lineStartOffset, out lineEndOffset);
         if (((from - lineStartOffset) + (text.Length - crlf)) >= LEGAL_COBOL_LINE_LENGTH)
         {
             string lefttext = buffer.GetTextAt(lineStartOffset, from);
             ICollection <ITextLine> lines = CobolTextLine.CreateCobolLines(this.Layout, -1, ' ', "",
                                                                            lefttext + (crlf > 0 ? text.Substring(0, text.Length - crlf) : text), LEGAL_COBOL_LINE_LENGTH, 65, false);
             StringWriter sw  = new StringWriter();
             string       sep = "";
             foreach (var line in lines)
             {
                 sw.Write(sep);
                 sw.WriteLine(line.Text);
                 sep = Environment.NewLine;
             }
             //We must insert "\r\n" if the target line is empty and the inserted test has one.
             if ((lineEndOffset == lineStartOffset) && crlf > 0)
             {
                 sw.Write(Environment.NewLine);
             }
             sw.Flush();
             text = sw.ToString();
             buffer.Insert(text, lineStartOffset, to);
         }
         else
         {
             buffer.Insert(text, from, to);
         }
     }
     else
     {
         buffer.Insert(text, from, to);
     }
 }