コード例 #1
0
        /// <summary>
        /// Splits the word into two parts.
        /// </summary>
        /// <param name="word">The word.</param>
        /// <param name="pos">The position, which lies in the range <c>[1, Length - 1]</c>.</param>
        /// <returns>The part after <paramref name="pos"/> is returned as a new <see cref="TextWord"/>.</returns>
        /// <remarks>
        /// The part before <paramref name="pos"/> is assigned to
        /// the reference parameter <paramref name="word"/>, the part after <paramref name="pos"/> is returned.
        /// </remarks>
        public static TextWord Split(ref TextWord word, int pos)
        {
#if DEBUG
            if (word.Type != TextWordType.Word)
            {
                throw new ArgumentException("word.Type must be Word");
            }

            if (pos <= 0)
            {
                throw new ArgumentOutOfRangeException("pos", pos, "pos must be > 0");
            }

            if (pos >= word.Length)
            {
                throw new ArgumentOutOfRangeException("pos", pos, "pos must be < word.Length");
            }
#endif
            TextWord after = new TextWord(word._document, word._line, word._offset + pos, word._length - pos, word._color, word._hasDefaultColor);
            word = new TextWord(word._document, word._line, word._offset, pos, word._color, word._hasDefaultColor);
            return(after);
        }
コード例 #2
0
    /// <summary>
    /// Splits the word into two parts. 
    /// </summary>
    /// <param name="word">The word.</param>
    /// <param name="pos">The position, which lies in the range <c>[1, Length - 1]</c>.</param>
    /// <returns>The part after <paramref name="pos"/> is returned as a new <see cref="TextWord"/>.</returns>
    /// <remarks>
    /// The part before <paramref name="pos"/> is assigned to
    /// the reference parameter <paramref name="word"/>, the part after <paramref name="pos"/> is returned.
    /// </remarks>
    public static TextWord Split(ref TextWord word, int pos)
    {
#if DEBUG
      if (word.Type != TextWordType.Word)
        throw new ArgumentException("word.Type must be Word");

      if (pos <= 0)
        throw new ArgumentOutOfRangeException("pos", pos, "pos must be > 0");

      if (pos >= word.Length)
        throw new ArgumentOutOfRangeException("pos", pos, "pos must be < word.Length");
#endif
      TextWord after = new TextWord(word._document, word._line, word._offset + pos, word._length - pos, word._color, word._hasDefaultColor);
      word = new TextWord(word._document, word._line, word._offset, pos, word._color, word._hasDefaultColor);
      return after;
    }