Microsoft.Cci.CompositeSourceDocument.ToLineColumn C# (CSharp) Method

ToLineColumn() public method

Maps the given (zero based) source position to a (one based) line and column, by scanning the source character by character, counting new lines until the given source position is reached. The source position and corresponding line+column are remembered and scanning carries on where it left off when this routine is called next. If the given position precedes the last given position, scanning restarts from the start. Optimal use of this method requires the client to sort calls in order of position.
public ToLineColumn ( int position, int &line, int &column ) : void
position int
line int
column int
return void
    public void ToLineColumn(int position, out int line, out int column)
      //^^ requires position >= 0 && position <= Length;
      //^^ ensures line >= 1 && column >= 1;
    {
      if (!this.enumeratorIsValid || position < this.currentFragmentOffset || position < this.lastPosition) {
        this.fragmentEnumerator = this.GetFragments().GetEnumerator();
        this.currentFragmentOffset = 0;
        this.enumeratorIsValid = this.fragmentEnumerator.MoveNext();
        this.lastPosition = 0;
        this.lineCounter = 1;
        this.columnCounter = 1;
      }
      line = this.lineCounter;
      column = this.columnCounter;
      Contract.Assert(this.fragmentEnumerator != null);
      while (this.enumeratorIsValid) {
        Contract.Assume((this.lastPosition >= position - this.currentFragmentOffset || this.lastPosition >= this.fragmentEnumerator.Current.Source.Length) || 0 <= this.lastPosition);
        this.ToLineColumn(position - this.currentFragmentOffset, ref line, ref column, this.fragmentEnumerator.Current.Source);
        int fragmentLength = this.fragmentEnumerator.Current.Length;
        if (this.currentFragmentOffset + fragmentLength > position) break;
        this.currentFragmentOffset += fragmentLength;
        this.enumeratorIsValid = this.fragmentEnumerator.MoveNext();
        this.lastPosition = 0;
      }
      this.lineCounter = line;
      this.columnCounter = column;
    }

Same methods

CompositeSourceDocument::ToLineColumn ( int position, int &line, int &column, string text ) : void