TextHighlighter: Fix possible overflows.

[GB.EVAL.HIGHLIGHT]
* BUG: TextHighlighter: The 'State' property is now a Short too.
* BUG: TextHighlighter: Fix possible overflows.
* NEW: Move old code to project files.
This commit is contained in:
Benoît Minisini 2023-01-31 07:40:59 +01:00
parent 85626256b5
commit 8ee286ffbf
19 changed files with 131 additions and 60 deletions

View File

@ -0,0 +1,71 @@
' Gambas module file
Public Sub ReadNumber(sText As String, iPos As Integer) As Integer
sText = String.Mid$(sText, iPos)
iPos = 1
If IsDigit(Left(sText)) Then
Inc iPos
Else If InStr("+-", Left(sText)) And If IsDigit(Mid$(sText, 2, 1)) Then
iPos += 2
Else
Return 0
Endif
While IsDigit(Mid$(sText, iPos, 1))
Inc iPos
Wend
If Mid$(sText, iPos, 1) = "." Then
Inc iPos
Else
Return iPos - 1
Endif
While IsDigit(Mid$(sText, iPos, 1))
Inc iPos
Wend
If InStr("eE", Mid$(sText, iPos, 1)) Then
Inc iPos
Else
Return iPos - 1
Endif
If InStr("+-", Mid$(sText, iPos, 1)) And If IsDigit(Mid$(sText, iPos + 1, 1)) Then
iPos += 2
Else If IsDigit(Mid$(sText, iPos, 1)) Then
Inc iPos
Else
Return iPos - 1
Endif
While IsDigit(Mid$(sText, iPos, 1))
Inc iPos
Wend
Return iPos - 1
End
Public Sub ReadIdentifier(sText As String, iPos As Integer, sIdentCar As String) As Integer
sText = String.Mid$(sText, iPos)
iPos = 1
If InStr(sIdentCar, Left(sText)) Then
While InStr(sIdentCar, Mid$(sText, iPos, 1)) > 0 And Asc(Mid$(sText, iPos, 1)) > 32
Inc iPos
Wend
Else
While InStr(sIdentCar, Mid$(sText, iPos, 1)) = 0 And Asc(Mid$(sText, iPos, 1)) > 32
Inc iPos
Wend
Endif
Return iPos - 1
End

View File

@ -7,43 +7,43 @@ Public Const STYLE_CSS As Integer = 3
Private Const TAG_HTML As Integer = 0
Private Const TAG_CODE As Integer = 1
Public Sub Main2()
Dim sLine As String
Dim fTime As Float
Dim aScan As String[]
Dim I As Integer
For I = 1 To 1
fTime = Timer
For Each sLine In Split(File.Load("~/gambas/3.0/trunk/comp/src/gb.form.editor/test.html"), "\n")
'Inc iLine
'Debug iLine;; Len(sLine)
Highlight.Text = sLine
Highlight.State = Highlight.Normal
HighlightHTML.Run(STYLE_HTML)
Next
Print Timer - fTime
For Each sLine In Split(File.Load("/proc/self/maps"), "\n")
If InStr(sLine, "[heap]") Then
aScan = Scan(sLine, "*-* *")
Print "Heap size is " & Format(Val("&H" & aScan[1] & "&") - Val("&H" & aScan[0] & "&"), "#,##0") & " bytes."
Break
Endif
Next
Next
End
' Public Sub Main2()
'
' Dim sLine As String
' Dim fTime As Float
' Dim aScan As String[]
' Dim I As Integer
'
' For I = 1 To 1
'
' fTime = Timer
'
' For Each sLine In Split(File.Load("~/gambas/3.0/trunk/comp/src/gb.form.editor/test.html"), "\n")
'
' 'Inc iLine
' 'Debug iLine;; Len(sLine)
'
' Highlight.Text = sLine
' Highlight.State = Highlight.Normal
'
' HighlightHTML.Run(STYLE_HTML)
'
' Next
'
' Print Timer - fTime
'
' For Each sLine In Split(File.Load("/proc/self/maps"), "\n")
' If InStr(sLine, "[heap]") Then
' aScan = Scan(sLine, "*-* *")
' Print "Heap size is " & Format(Val("&H" & aScan[1] & "&") - Val("&H" & aScan[0] & "&"), "#,##0") & " bytes."
' Break
' Endif
' Next
'
' Next
'
' End
'
Public Sub Main()
Dim hHighlighter As TextHighlighter

View File

@ -22,7 +22,7 @@ Property Read Styles As String[]
Static Public _Highlight As Byte[]
Static Public (Line) As Integer
Static Public State As Integer
Static Public State As Short
Static Public Tag As Short
Static Public TextAfter As String
Static Public Alternate As Boolean
@ -44,7 +44,7 @@ Private Sub GetAlternate() As Integer
End
Fast Static Public Sub Add((State) As Integer, Optional Count As Integer = 1)
Fast Static Public Sub Add((State) As Short, Optional Count As Integer = 1)
Dim iState As Integer
Dim I As Integer
@ -112,7 +112,7 @@ Public Sub ToHTML(Text As String, Optional Theme As Variant) As String
Dim I As Integer
Dim sHTML As String
Dim aText As String[]
Dim iState As Integer
Dim iState As Short
Dim hStyle As TextHighlighterStyle
Dim bAlt As Boolean
Dim iLen As Integer

View File

@ -51,8 +51,8 @@ End
Public Sub RunWith(sText As String, cKeyword As Collection, cOperator As Collection, cType As Collection)
Dim iState As Integer
Dim iTag As Integer
Dim iState As Short
Dim iTag As Short
Dim iLenText As Integer
Dim iPos, iSavePos As Integer
Dim sCar As String

View File

@ -72,16 +72,16 @@ End
Public Sub Run(sText As String)
Dim iState As Integer
Dim iNextState As Integer
Dim iState As Short
Dim iNextState As Short
Dim iInd As Integer
Dim sOrgText As String
Dim sCar As String
Dim bLimit As Boolean
Dim iTag As Integer
Dim iTag As Short
Dim sProperty As String
Dim sWait As String
Dim iSaveState As Integer
Dim iSaveState As Short
Dim iPos, iPos2 As Integer
Dim bEscape As Boolean
Dim N As Integer

View File

@ -8,7 +8,7 @@ Public Const _Styles As String = "File,Header,Position,Added,Removed"
Public Sub Run(sText As String)
Dim iState As Integer
Dim iState As Short
Dim nSpace As Integer
TextHighlighter.Limit = False

View File

@ -49,8 +49,8 @@ End
Public Sub Run(Text As String)
Dim iState As Integer
Dim iTag As Integer
Dim iState As Short
Dim iTag As Short
Dim iPos As Integer
Dim I As Integer
Dim iLen As Integer

View File

@ -32,7 +32,7 @@ Private Enum TAG_VARIABLE, TAG_CODE_MARKUP
Static Private $sTextAfter As String
Static Private $sBufferAfter As String
Static Private $aStateStack As Integer[]
Static Private $aStateStack As Short[]
' TODO: call TextHighlighter_Gambas !
@ -41,8 +41,8 @@ Private Sub AnalyzeCode(sText As String) As String
Dim iInd As Integer
Dim iPos As Integer
Dim iLen As Integer
Dim iState As Integer
Dim iTag As Integer
Dim iState As Short
Dim iTag As Short
'Print "AnalyzeCode: "; sText
@ -99,13 +99,13 @@ End
Private Sub RunWith(Text As String, iStyle As Integer)
Dim iState As Integer
Dim iTag, iTagCode, iTagMode As Integer
Dim iState As Short
Dim iTag, iTagCode, iTagMode As Short
Dim sText As String
Dim I, iLenText As Integer
Dim sCar As String
Dim iPos As Integer
Dim iNextState As Integer
Dim iNextState As Short
Dim bLimit, bNextLimit As Boolean
Dim sQuote As String
Dim sMarkup As String
@ -597,7 +597,7 @@ NEXT_CHAR:
PUSH_STATE:
If Not $aStateStack Then $aStateStack = New Integer[]
If Not $aStateStack Then $aStateStack = New Short[]
$aStateStack.Push(TextHighlighter.State)
$aStateStack.Push(TextHighlighter.Tag)

View File

@ -20,7 +20,7 @@ Static Public Sub _init()
$aKeywords = New String[]
For Each sStr In ["break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export",
"extends", "finally", "for", "function", "get", "if", "import", "in", "instanceof", "new", "return", "set", "super", "switch", "throw",
"extends", "finally", "for", "function", "get", "if", "import", "in", "instanceof", "let", "new", "return", "set", "super", "switch", "throw",
"try", "typeof", "var", "void", "while", "with", "yield"]
$cKeyword[sStr] = 0
$aKeywords.Add(sStr)
@ -47,7 +47,7 @@ End
Public Sub Run(sText As String)
Dim iState As Integer
Dim iTag As Integer
Dim iTag As Short
Dim iLenText As Integer
Dim iPos As Integer
Dim sCar As String

View File

@ -51,7 +51,7 @@ End
Public Sub Run(sText As String)
Dim iState As Integer
Dim iTag As Integer
Dim iTag As Short
Dim iLenText As Integer
Dim iPos As Integer
Dim sCar As String

View File

@ -63,7 +63,7 @@ End
Public Sub RunWith(sText As String, cKeyword As Collection, cOperator As Collection, cType As Collection)
Dim iState As Integer
Dim iTag As Integer
Dim iTag As Short
Dim iLenText As Integer
Dim iPos, iSavePos As Integer
Dim sCar As String