STATIC SUB Add ( State AS Integer [ , Count AS Integer ] )Defines the state of an UTF-8 character of the highlighted line.
The first time this method is called, the state of the first character of the line is defined. Then you should call this method for each other character until all are highlighted.
If Count is defined, then Count successive characters got the same state. By default, Count is one.
The State must be one of the following constants:
' HTML highlighting from the HighlightEditor example
' Note that the String class is used for dealing with UTF-8 characters.
PUBLIC SUB Editor1_Highlight()
DIM iState AS Integer
DIM iNextState AS Integer
DIM iInd AS Integer
DIM J AS Integer
DIM sText AS String
DIM sCar AS String
DIM iPos AS Integer
DIM bMarkup AS Boolean
iState = Highlight.State
sText = Highlight.Text
FOR iInd = 1 TO String.Len(sText)
iNextState = iState
sCar = String.Mid$(sText, iInd, 1)
IF bMarkup THEN
IF sCar = ">" THEN
bMarkup = FALSE
iState = Highlight.Keyword
iNextState = Highlight.Normal
ELSE IF sCar = " " THEN
iNextState = Highlight.Operator
ELSE IF sCar = "=" THEN
iNextState = Highlight.String
ENDIF
ELSE
SELECT CASE iState
CASE Highlight.Normal
IF sCar = "\<" THEN
IF String.Mid$(sText, iInd, 4) = "\<!--" THEN
iState = Highlight.Comment
iNextState = Highlight.Comment
ELSE
iState = Highlight.Keyword
iNextState = Highlight.Keyword
bMarkup = TRUE
ENDIF
ELSE IF sCar = "&" THEN
iPos = String.InStr(sText, ";", iInd)
IF iPos = 0 OR iPos = iInd + 1 THEN
iState = Highlight.Error
ELSE
FOR J = iInd + 1 TO iPos - 1
sCar = String.Mid$(sText, J, 1)
IF IsLetter(sCar) THEN CONTINUE
IF IsDigit(sCar) THEN CONTINUE
IF InStr("_#", sCar) THEN CONTINUE
BREAK
NEXT
IF J = iPos THEN
Highlight.Add(Highlight.Number, iPos - iInd + 1)
iInd = iPos
CONTINUE
ELSE
iState = Highlight.Error
ENDIF
ENDIF
ENDIF
CASE Highlight.Comment
IF sCar = ">" AND IF iInd > 2 AND IF String.Mid$(sText, iInd - 2, 2) = "--" THEN
iNextState = Highlight.Normal
ENDIF
END SELECT
ENDIF
Highlight.Add(iState)
iState = iNextState
NEXT
IF iNextState <> Highlight.Comment THEN
iNextState = Highlight.Normal
ENDIF
Highlight.State = iNextState
Highlight.ShowLimit = FALSE
END