Skip to content

Commit ec5bf81

Browse files
committed
Bug fixed: unable to catch special cases of like operator.
1 parent d41aa37 commit ec5bf81

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/VBAexpressions.cls

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,11 +1378,7 @@ Private Function GetEvalToken(ByRef Expression As String) As Token
13781378
GetTokenStart Expression, TokenDet.Position, TokenStart
13791379
'@--------------------------------------------------------------------
13801380
' Find token end
1381-
If TokenDet.OperationToken <> otLike Then
1382-
GetTokenEnd Expression, TokenDet.Position, TokenDet.OperatorLen, TokenEnd
1383-
Else
1384-
GetTokenEnd Expression, InStrB(TokenDet.Position + 4, Expression, d_Apostrophe), TokenDet.OperatorLen, TokenEnd
1385-
End If
1381+
GetTokenEnd Expression, TokenDet.Position, TokenDet.OperatorLen, TokenEnd
13861382
'@--------------------------------------------------------------------
13871383
' Fill token data
13881384
GetEvalToken.DefString = MidB$(Expression, TokenStart, TokenEnd - TokenStart + 2)
@@ -1691,6 +1687,19 @@ Private Sub GetOperands(ByRef CurToken As Token, ByRef CurTree As ClusterTree, _
16911687
End If
16921688
End Sub
16931689

1690+
Private Function IsSymbolInLiteralString(ByRef Expression As String, SymbolPos As Long) As Boolean
1691+
Dim flagCounter As Long
1692+
Dim tmpPos As Long
1693+
1694+
tmpPos = InStrB(1, Expression, d_Apostrophe)
1695+
If tmpPos Then
1696+
Do While tmpPos < SymbolPos
1697+
flagCounter = flagCounter + 1
1698+
tmpPos = InStrB(tmpPos + 2, Expression, d_Apostrophe)
1699+
Loop
1700+
End If
1701+
IsSymbolInLiteralString = flagCounter And 1
1702+
End Function
16941703
Private Function GetOPeratorSymbolPos(ByRef Expression As String, _
16951704
ByRef OperatorSymbol As String, _
16961705
Optional StartPosition As Long = 1) As Long
@@ -1699,13 +1708,9 @@ Private Function GetOPeratorSymbolPos(ByRef Expression As String, _
16991708
Dim LStrClosePos As Long
17001709

17011710
tmpResult = InStrB(StartPosition, Expression, OperatorSymbol)
1702-
LStrOpenPos = InStrB(StartPosition, Expression, d_Apostrophe)
1703-
If LStrOpenPos Then
1704-
LStrClosePos = InStrB(LStrOpenPos + LenB(OperatorSymbol), Expression, d_Apostrophe)
1705-
Do While (tmpResult > LStrOpenPos) And (tmpResult < LStrClosePos)
1706-
tmpResult = InStrB(tmpResult + LenB(OperatorSymbol), Expression, OperatorSymbol)
1707-
Loop
1708-
End If
1711+
Do While IsSymbolInLiteralString(Expression, tmpResult)
1712+
tmpResult = InStrB(tmpResult + LenB(OperatorSymbol), Expression, OperatorSymbol)
1713+
Loop
17091714
GetOPeratorSymbolPos = tmpResult
17101715
End Function
17111716

@@ -1758,7 +1763,7 @@ Private Function GetPowerSymbolPos(ByRef Expression As String) As Long
17581763
tmpPos = GetOPeratorSymbolPos(Expression, op_power)
17591764
Do While tmpPos
17601765
tmpResult = tmpPos
1761-
tmpPos = GetOPeratorSymbolPos(Expression, op_power)
1766+
tmpPos = GetOPeratorSymbolPos(Expression, op_power, tmpPos)
17621767
Loop
17631768
GetPowerSymbolPos = tmpResult
17641769
End Function
@@ -1881,6 +1886,15 @@ Private Sub GetTokenEnd(ByRef Expression As String, ByRef startIndex As Long, By
18811886
lenExpr = LenB(Expression)
18821887
outLng = startIndex + OPlen
18831888
curChar = MidB$(Expression, outLng, 2)
1889+
'@--------------------------------------------------------------------
1890+
' Skip literal strings
1891+
If curChar = d_Apostrophe Then
1892+
Do
1893+
outLng = outLng + 2
1894+
curChar = MidB$(Expression, outLng, 2)
1895+
Loop While curChar <> d_Apostrophe And outLng < lenExpr
1896+
If outLng >= lenExpr Then Exit Sub
1897+
End If
18841898
Do
18851899
tmpPos = outLng
18861900
If IsLetter(curChar) Then 'Check for functions [ arg/-funct(...) ] and Sci notation
@@ -1952,10 +1966,17 @@ End Function
19521966
Private Sub GetTokenStart(ByRef Expression As String, ByRef startIndex As Long, ByRef outLng As Long)
19531967
Dim curChar As String
19541968

1955-
'@--------------------------------------------------------------------
1956-
' Find token start
19571969
outLng = startIndex - 2
19581970
curChar = MidB$(Expression, outLng, 2)
1971+
'@--------------------------------------------------------------------
1972+
' Skip literal strings
1973+
If curChar = d_Apostrophe Then
1974+
Do
1975+
outLng = outLng - 2
1976+
curChar = MidB$(Expression, outLng, 2)
1977+
Loop While curChar <> d_Apostrophe And outLng > 1
1978+
If outLng = 1 Then Exit Sub
1979+
End If
19591980
Do While (InStrB(1, op_AllItems, curChar) = 0) And outLng > 1
19601981
outLng = outLng - 2
19611982
curChar = MidB$(Expression, outLng, 2)

0 commit comments

Comments
 (0)