Exemplo n.º 1
0
    /// <summary>
    ///     Returns the character as the specified document position.
    /// </summary>
    /// <param name="position">The zero-based document position of the character to get.</param>
    /// <returns>The character at the specified <paramref name="position" />.</returns>
    private static unsafe int GetCharAt(int position)
    {
        position = Clamp(position, 0, TextLength);
        position = Lines.CharToBytePosition(position);

        var nextPosition = Sci.Send(SciMsg.SCI_POSITIONRELATIVE, new IntPtr(position), new IntPtr(1)).ToInt32();
        var length       = (nextPosition - position);

        if (length <= 1)
        {
            // Position is at single-byte character
            return(Sci.Send(SciMsg.SCI_GETCHARAT, new IntPtr(position)).ToInt32());
        }

        // Position is at multibyte character
        var bytes = new byte[length + 1];

        fixed(byte *bp = bytes)
        {
            Sci_TextRange *range = stackalloc Sci_TextRange[1];

            range->chrg.cpMin = position;
            range->chrg.cpMax = nextPosition;
            range->lpstrText  = new IntPtr(bp);

            Sci.Send(SciMsg.SCI_GETTEXTRANGE, IntPtr.Zero, new IntPtr(range));
            var str = GetString(new IntPtr(bp), length, Encoding);

            return(str[0]);
        }
    }
Exemplo n.º 2
0
    /// I keep those methods just in case, but they are either slower than their counterparts,
    /// or their existence is unjustified...

    #region Dont use...

    /// <summary>
    ///     Deletes a range of text from the document.
    /// </summary>
    /// <param name="position">The zero-based character position to start deleting.</param>
    /// <param name="length">The number of characters to delete.</param>
    private static void DeleteRange(int position, int length)
    {
        var textLength = TextLength;

        position = Clamp(position, 0, textLength);
        length   = Clamp(length, 0, textLength - position);

        // Convert to byte position/length
        var byteStartPos = Lines.CharToBytePosition(position);
        var byteEndPos   = Lines.CharToBytePosition(position + length);

        Sci.Send(SciMsg.SCI_DELETERANGE, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos));
    }