Skip to content

Commit

Permalink
New StringHasUnicode closes joyfullservice#186
Browse files Browse the repository at this point in the history
  • Loading branch information
A9G-Data-Droid committed Mar 4, 2021
1 parent dece32e commit 13cfd5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 4 additions & 13 deletions Version Control.accda.src/modules/modEncoding.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'---------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------
' Module : modEncoding
' Author : Adam Waller
' Date : 12/4/2020
Expand Down Expand Up @@ -531,16 +531,7 @@ End Sub
'---------------------------------------------------------------------------------------
'
Public Function StringHasUnicode(strText As String) As Boolean

StringHasUnicode = (StrConv(strText, vbUnicode) = strText)

Dim reg As VBScript_RegExp_55.RegExp

Perf.OperationStart "Unicode Check"
Set reg = New VBScript_RegExp_55.RegExp
With reg
' Include extended ASCII characters here.
.Pattern = "[^\u0000-\u007F]"
StringHasUnicode = .Test(strText)
End With
Perf.OperationEnd

End Function
End Function
17 changes: 12 additions & 5 deletions Version Control.accda.src/modules/modUnitTesting.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Option Compare Database
Option Compare Database
Option Explicit
Option Private Module

Expand Down Expand Up @@ -39,7 +39,7 @@ Public Sub TestUCS2toUTF8RoundTrip()

'Arrange:
Dim queryName As String
queryName = "Temp_Test_Query_Delete_Me_Æ_ø_Å"
queryName = "Temp_Test_Query_Delete_Me_Æ_ø_Å"
Dim tempFileName As String
tempFileName = GetTempFile()

Expand All @@ -53,7 +53,7 @@ Public Sub TestUCS2toUTF8RoundTrip()
UTFtoUCS = tempFileName & "UTF-8toUCS-2"

' Use temporary query to export example file
CurrentDb.CreateQueryDef queryName, "SELECT * FROM TEST WHERE TESTING='ÆØÅ'"
CurrentDb.CreateQueryDef queryName, "SELECT * FROM TEST WHERE TESTING='ÆØÅ'"
Application.SaveAsText acQuery, queryName, tempFileName
CurrentDb.QueryDefs.Delete queryName

Expand Down Expand Up @@ -106,7 +106,7 @@ Private Sub TestParseSpecialCharsInJson()

Set FSO = CreateObject("Scripting.FileSystemObject")
With FSO.CreateTextFile(strPath, True)
.WriteLine "{""Test"":""ÆØÅ are special?""}"
.WriteLine "{""Test"":""ÆØÅ are special?""}"
.Close
End With

Expand All @@ -130,6 +130,13 @@ TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
End Sub

'@TestMethod("TextConversion")
Private Sub TestStringHasUnicode()
Assert.IsTrue StringHasUnicode("aß?de?????µ???p?st?f?")
Assert.IsFalse StringHasUnicode("'——————————————————————————————————————————————————————————————————————————————————————————")
End Sub



'@TestMethod("Sorting")
Private Sub TestSortDictionaryByKeys()
Expand Down Expand Up @@ -213,4 +220,4 @@ TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
End Sub
End Sub

0 comments on commit 13cfd5e

Please sign in to comment.