Skip to content

Commit

Permalink
Move source reading function
Browse files Browse the repository at this point in the history
This is used in several areas, and allows us to maintain the source file encoding determination in a single location.
  • Loading branch information
joyfullservice committed Nov 8, 2023
1 parent 54e070a commit 1390f2c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
27 changes: 1 addition & 26 deletions Version Control.accda.src/modules/clsSourceParser.cls
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,8 @@ Private this As udtThis
'---------------------------------------------------------------------------------------
'
Public Function LoadSourceFile(strPath As String)

Dim strTempFile As String

ResetContent

' Read text from file, and split into lines
If HasUcs2Bom(strPath) Then
this.strInput = ReadFile(strPath, "Unicode")
Else
' ADP projects may contain mixed Unicode content
If CurrentProject.ProjectType = acADP Then
strTempFile = GetTempFile
ConvertUcs2Utf8 strPath, strTempFile, False
this.strInput = ReadFile(strTempFile)
DeleteFile strTempFile
Else
If DbVersion <= 4 Then
' Access 2000 format exports using system codepage
' See issue #217
this.strInput = ReadFile(strPath, GetSystemEncoding)
Else
' Newer versions export as UTF-8
this.strInput = ReadFile(strPath)
End If
End If
End If

this.strInput = ReadSourceFile(strPath)
End Function


Expand Down
36 changes: 36 additions & 0 deletions Version Control.accda.src/modules/modVCSUtility.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,39 @@ Public Function PassesSchemaFilter(strItem As String, varFilterArray As Variant)
PassesSchemaFilter = blnPass

End Function


'---------------------------------------------------------------------------------------
' Procedure : ReadSourceFile
' Author : Adam Waller
' Date : 11/8/2023
' Purpose : Load source file content into a string. (Considers BOM and file type)
'---------------------------------------------------------------------------------------
'
Public Function ReadSourceFile(strPath As String) As String

Dim strTempFile As String

' Read text from file, and split into lines
If HasUcs2Bom(strPath) Then
ReadSourceFile = ReadFile(strPath, "Unicode")
Else
' ADP projects may contain mixed Unicode content
If CurrentProject.ProjectType = acADP Then
strTempFile = GetTempFile
ConvertUcs2Utf8 strPath, strTempFile, False
ReadSourceFile = ReadFile(strTempFile)
DeleteFile strTempFile
Else
If DbVersion <= 4 Then
' Access 2000 format exports using system codepage
' See issue #217
ReadSourceFile = ReadFile(strPath, GetSystemEncoding)
Else
' Newer versions export as UTF-8
ReadSourceFile = ReadFile(strPath)
End If
End If
End If

End Function

0 comments on commit 1390f2c

Please sign in to comment.