All pastes #89663 Raw Edit

fixCStyleTickBug

public text v1 · immutable
#89663 ·published 2006-07-16 21:16 UTC
rendered paste body
Public Function fixCStyleTickBug(pString As String) As String
    Dim i As Integer
    Dim ret As String
    
    Const st_Initial = 0
    Const st_Slash = 1
    Const st_cComment = 3
    Const st_Asterix = 4

    Dim state As Integer
    state = st_Initial
    For i = 1 To Len(pString)
        Dim c As String
        c = Mid(pString, i, 1)
        Select Case c
            Case "/"
                Select Case state
                    Case st_Slash, st_Asterix
                        state = st_Initial
                    Case Else
                        state = st_Slash
                End Select
            Case "*"
                Select Case state
                    Case st_Slash
                        state = st_cComment
                    Case st_cComment
                        state = st_Asterix
                End Select
            Case "'"
                If state = st_cComment Then c = "`"
            Case Else
                If state <> st_cComment Then state = st_Initial
        End Select
        ret = ret & c
    Next i
    fixCStyleTickBug = ret
End Function