/// <summary>Writes a newline and the appropriate amount of indentation afterward.</summary>
        /// <param name="indent">Whether to call Indent() beore writing the newline</param>
        /// <returns>A <see cref="Checkpoint"/> that can be used to revoke the newline</returns>
        /// <remarks>Note that "revoking" a newline does NOT restore the original indent level.</remarks>
        public Checkpoint Newline(int changeIndentLevel = 0)
        {
            var cp = GetCheckpoint();

            IndentLevel += changeIndentLevel;
            Contract.Assert(IndentLevel >= 0);

            var r = new Revokable(_lineStartIndex, S.Length, NewlineString.Length + IndentString.Length * IndentLevel);

            S.Append(NewlineString);
            LineNo++;
            _lineStartIndex = S.Length;
            for (int i = 0; i < IndentLevel; i++)
            {
                S.Append(IndentString);
            }
            _newlines.Add(r);
            return(cp);
        }
Exemple #2
0
		/// <summary>Revokes (deletes) the last newline created, and its indent.</summary>
		/// <param name="r">Object returned from Newline()</param>
		/// <remarks>Only the most recent newline can be revoked, and of course, 
		/// it can only be revoked once. Multiple newlines can be revoked if 
		/// they are revoked in the reverse order in which they were created.</remarks>
		private void Revoke(Revokable r)
		{
			S.Remove(r._index, r._length);
			_lineStartIndex = r._oldLineStartIndex;
			LineNo--;
		}
Exemple #3
0
		/// <summary>Writes a newline and the appropriate amount of indentation afterward.</summary>
		/// <param name="changeIndentLevel">Amount by which to change <see cref="IndentLevel"/> before writing the newline</param>
		/// <returns>A <see cref="Checkpoint"/> that can be used to revoke the newline</returns>
		/// <remarks>Note that "revoking" a newline does NOT restore the original indent level.</remarks>
		public Checkpoint Newline(int changeIndentLevel = 0)
		{
			var cp = GetCheckpoint();
			IndentLevel += changeIndentLevel;
			Contract.Assert(IndentLevel >= 0);

			var r = new Revokable(_lineStartIndex, S.Length, NewlineString.Length + IndentString.Length * IndentLevel);
			S.Append(NewlineString);
			LineNo++;
			_lineStartIndex = S.Length;
			for (int i = 0; i < IndentLevel; i++)
				S.Append(IndentString);
			_lineStartAfterIndent = S.Length;
			_newlines.Add(r);
			return cp;
		}
Exemple #4
0
 /// <summary>Revokes (deletes) the last newline created, and its indent.</summary>
 /// <param name="r">Object returned from Newline()</param>
 /// <remarks>Only the most recent newline can be revoked, and of course,
 /// it can only be revoked once. Multiple newlines can be revoked if
 /// they are revoked in the reverse order in which they were created.</remarks>
 private void Revoke(Revokable r)
 {
     S.Remove(r._index, r._length);
     _lineStartIndex = r._oldLineStartIndex;
     LineNo--;
 }