Public Function IsGoodInStrCount(Optional fLigaturesToo As Boolean) As Boolean
' verify correct InStrCount returns, 20021005
' returns True if all tests are passed
  
  ' replace ".InStrCount06" with the name of your function to test
  Dim fFailed As Boolean
  Dim Text As String
  
  With New CInStrMarzo
  If .InStrCount06("ababa", "a") <> 3 Then Stop: fFailed = True
  If .InStrCount06("ababa", "ab") <> 2 Then Stop: fFailed = True
  If .InStrCount06("ababa", "aba") <> 1 Then Stop: fFailed = True
  If .InStrCount06("ababa", "abb") <> 0 Then Stop: fFailed = True
  If .InStrCount06("ababa", "") <> 0 Then Stop: fFailed = True
  If .InStrCount06("", "a") <> 0 Then Stop: fFailed = True
  If .InStrCount06("aaaa", "aa") <> 2 Then Stop: fFailed = True
  
  If .InStrCount06("aAaA", "a") <> 2 Then Stop: fFailed = True
  If .InStrCount06("aAaA", "a", , vbTextCompare) <> 4 Then Stop: fFailed = True
  If .InStrCount06("aAaA", "A", , vbTextCompare) <> 4 Then Stop: fFailed = True
 
  ' unicode
  If .InStrCount06("€€€", "€") <> 3 Then Stop: fFailed = True
  If .InStrCount06("[a]{a}", "{A}", , vbTextCompare) <> 1 Then Stop: fFailed = True
  
  ' Common chars when parsing Unix "man" pages...
  Text = Replicate05(10, "{|}[/][\]{{||}}[/][\]{{{|||}}}[/][\]")
  If .InStrCount06(Text, "{|}", , vbTextCompare) <> 10 Then Stop: fFailed = True
  
  ' the 4 stooges: š/Š, œ/Œ, ž/Ž, ÿ/Ÿ (154/138, 156/140, 158/142, 255/159)
  If .InStrCount06("Hašiš", "Š", , vbTextCompare) <> 2 Then Stop: fFailed = True
  ' ligatures  textcompare (VBspeed entries do NOT have to pass this test)
  If fLigaturesToo Then
    ' ligatures, a digraphemic fun house: ss/ß, ae/æ, oe/œ, th/þ
    If .InStrCount06("Straße", "ss", , vbTextCompare) <> 1 Then Stop: fFailed = True
  End If
  
  End With
  
  ' well done
  IsGoodInStrCount = Not fFailed
  
End Function

Back to InStrCount