Scintilla User Guide (2)-Full text search and modification

Source: Internet
Author: User
Tags gtk
In Scintilla, each character is followed by a byte that represents a character style, a character byte, and a style byte together to form a character cell. The 8 bits of the style byte are divided into two parts: a character style and a character indicator. You can set a character indicator for a text by Sci_indicatorfillrange messages. The default low 5 bits are character styles, and the high 3 bits are character indicators. Therefore, there can be 32 character styles. 3 independent character indicators, which can be used to indicate grammatical errors, deprecated names, and bad indentation information. You can use the Sci_setstylebits message to set the character style bit to a maximum of 7 bit bits, and the remainder will be assigned to the character indicator.
Position indicates the position of the character in the Scintilla or the spot before the character. The first character's position is 0, the second one is 1, and so on. If a document contains Nlen characters, the position of the last character is nlen–1. The cursor exists between two characters and can be positioned before the first character (0) and after the last character (Nlen).
When two characters are treated as one character, the cursor cannot exist between two characters. In this case, it usually occurs when a multibyte character or line terminator is CRLF in Chinese. The constant Invalid_position (-1) represents an illegal location.
For performance reasons, all lines of text have the same height: the height of the largest font in the current style.

Sci_gettext, Sci_settext

1) sci_gettext (int length, char *text)
Get text:
(1) When text is 0 o'clock, returns the entire document length Len + 1;
(2) When length is 0 o'clock, return 0;
(3) When text is not 0 and length is greater than 0 o'clock, the returned Length–1,text is populated with length–1 characters starting at position 0 and a 0 terminator. If length is greater than the document length, the extra position is filled with a null character of 0.

unsigned int len = SendMessage (sci_gettext, 0, 0); char *chtext = new Char[len]; SendMessage (Sci_gettext, Len, (LPARAM) chtext);.. delete [] chtext;

2) Sci_settext (<UNUSED>, const char *text)
Sets the document text to Text,text is a constant string ending with 0. If text is 0, returns False (0), otherwise true (1) is returned.

Sci_setsavepointsci_setsavepoint

When you set the savepoint, the document status changes to unmodified, which returns True (1). The SCI_SETSAVEPOINT message will trigger the Scn_savepointreached event notification. The Scn_savepointleft event notification is triggered when the document status changes to modified.

Sci_getline

Sci_getline (int line, char *text)
Gets the specified line text, which returns the length of the specified line text, including the line terminator. Line number starts at 0 and returns 0 if the line number is greater than the maximum line number. When text is 0 o'clock, the length of the specified line is returned directly, and when text is not 0 o'clock, text is populated with the specified line text, but the Terminator 0 is not automatically set.

unsigned int len = SendMessage (sci_getline, 1, 0), char *chtext = new Char[len + 1];memset (chtext, 0, Len + 1); SendMessage (Sci_getline, 1, (LPARAM) chtext);.. delete [] chtext;

Sci_replacesel

Sci_replacesel (<UNUSED>, const char *text)
Replaces the selection text, which is a constant string ending with 0. When no text is selected, the text is inserted at the current position. When replaced, the cursor is placed after the inserted text, and the view is automatically scrolled to make the text visible. When text is 0 o'clock, returns False (0), otherwise true (1) is returned.

Sci_setreadonly, Sci_getreadonly

1) sci_setreadonly (bool readOnly)
Sets the document to read-only and Returns True (1). When the document is in a read-only state, the Scn_modifyattemptro event notification is triggered when the document changes.
2) sci_getreadonly
Gets the document read-only state, which returns True (1) or False (0).

Sci_gettextrange

Sci_gettextrange (<unused>, TextRange *tr)
Gets the specified range of text, if the TR is 0, returns 0, otherwise returns the length of the text (excluding 0 terminator) and fills Tr.lpstrtext with the specified range of text and a 0 terminator. When Tr.chrg.cpMax is-1, it is indicated to the end of the document. You must make sure that the Tr.lpstrtext character buffer is large enough ((tr.chrg.cpmax-tr.chrg.cpmin) + 1).

Sci_getstyledtext

Sci_getstyledtext (<unused>, TextRange *tr)
Gets the specified range style text, similar to Sci_gettextrange, but the required character buffer size is twice times sci_gettextrange (2 * (tr.chrg.cpmax-tr.chrg.cpmin) + 2). Scintilla will automatically append 2 0 terminator to Tr.lpstrtext tail.

Sci_allocate

Sci_allocate (int bytes, <unused>)
Allocates a buffer that is large enough to hold the specified size of bytes, returning True (1). The buffer is redistributed only if the specified size is larger than the current buffer size, otherwise no processing is done.

Sci_addtext

Sci_addtext (int length, const char *s)
Inserts the specified length of the specified text at the current position, and S is a constant string ending with 0, returning 0. After inserting text, the current position is inserted after the text, but the view is not automatically scrolled to make it visible.

Sci_addstyledtext

Sci_addstyledtext (int length, cell *s)
Inserts the style text at the current position, similar to Sci_addtext, and returns 0.

Sci_appendtext

Sci_appendtext (int length, const char *s)
Inserts text at the end of the document, similar to Sci_addtext, and returns 0.

Sci_inserttext

Sci_inserttext (int pos, const char *text)
Inserts text at the specified position, similar to Sci_addtext, and returns 0. When POS is-1, it is inserted at the current position.

Sci_clearall

Sci_clearall
Removes all characters from the document, returning 0 unless the document is read-only.

Sci_cleardocumentstyle

Sci_cleardocumentstyle
Clears all style information for the document and returns 0. This is usually used when you need to reset the document style.

Sci_getcharat

Sci_getcharat (int position)
Returns the character at the specified position. Returns 0 when position is less than 0 or greater than the document end position.

Sci_getstyleat

Sci_getstyleat (int position)
Returns the style for the specified position. Returns 0 when position is less than 0 or greater than the document end position.

Sci_setstylebits, Sci_getstylebits

1) sci_setstylebits (int bits)
Sets the width of the style bit in bytes and returns True (1). The default is 5 bit, the maximum can be set to 7 bits, the remaining bit bits will be used to represent the character indicator.
2) Sci_getstylebits
Returns the style bit width in bytes.

Sci_targetasutf8 *

Sci_targetasutf8 (<UNUSED>, Char *s)
Converts the target string to UTF8 encoded format, returns the encoded text length, and fills the encoded bytes into S. This message is only available on the GTK + platform.

Sci_encodedfromutf8 *

Sci_encodedfromutf8 (const char *utf8, char *encoded)
Converts the UTF8 format string to the document encoding format, returns the converted byte length, and populates the converted bytes into encoded. This message is only available on the GTK + platform.

Sci_setlengthforencode

Sci_setlengthforencode (int bytes)
Sets the document encoding length, which returns 0.

The above is the Scintilla User Guide (2)-Full text search and modify content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.