The MASM Forum

General => The Campus => Topic started by: rc on November 02, 2019, 02:16:00 AM

Title: Get all charranges starting with a digit in richtext edit
Post by: rc on November 02, 2019, 02:16:00 AM
Hello community,

is there an easy way to get all strings starting with a digit in a rich text control?
I want to parse the text in a rich text edit control and get all charranges starting with a digit. CHARRANGE (https://docs.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-charrange).
I've already implemented a simple "Find Text" feature in my editor so the user can search for text in their document. I just thought finding text starting with a digit must work similar.

What i want to do is implement a very simple highlighter that highlights digits, strings and comments. So that it is very universal.
So analog i need to check somehowe if it is a comment (starting with ;) or a string (inbetween quotes)

The rules would be:
- check if it is a comment -> highlight comment, else:
    - check if it is a string (inbetween quotes) -> highlight string, else:
        - check if it starts with a digit (e.g. 41h) -> highlight digit

Or:
- check if digit and not within a comment or string -> highlight digit
- check if string (inbetween quotes) and not inside comment -> highlight string
- check if comment -> highlight comment

The problem is, how do i get the charranges of a text inbetween quotes, or a comment starting with ; and the end of line or a text starting with a digit and the last character of that text.
Title: Re: Get all charranges starting with a digit in richtext edit
Post by: jj2007 on November 02, 2019, 02:45:07 AM
- use the EM_GETTEXTLENGTHEX message to know the length of your text
- allocate a buffer
- use the EM_GETTEXTEX message to load your text into the buffer
- parse the buffer
Title: Re: Get all charranges starting with a digit in richtext edit
Post by: nidud on November 02, 2019, 04:47:38 AM
deleted
Title: Re: Get all charranges starting with a digit in richtext edit
Post by: rc on November 03, 2019, 07:18:43 PM
That's a good example, thanks :)