Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
5.4 KiB

  1. Attribute VB_Name = "StringContentsTest"
  2. Option Explicit
  3. Public Function ContainsGarbage( _
  4. ByVal i_strText As String _
  5. ) As Boolean
  6. Static blnGarbageCharsInitialized As Boolean
  7. Static arrGarbageChars() As String
  8. Dim char As Variant
  9. ContainsGarbage = False
  10. If (Not blnGarbageCharsInitialized) Then
  11. p_LoadGarbageChars arrGarbageChars
  12. blnGarbageCharsInitialized = True
  13. End If
  14. For Each char In arrGarbageChars
  15. If (InStr(i_strText, char) <> 0) Then
  16. ContainsGarbage = True
  17. Exit Function
  18. End If
  19. Next
  20. ContainsGarbage = Not XMLValidString(i_strText)
  21. End Function
  22. Private Sub p_LoadGarbageChars( _
  23. ByRef o_arrGarbageChars() As String _
  24. )
  25. ReDim o_arrGarbageChars(4)
  26. o_arrGarbageChars(0) = vbCr
  27. o_arrGarbageChars(1) = vbLf
  28. o_arrGarbageChars(2) = vbTab
  29. o_arrGarbageChars(3) = chr(146)
  30. o_arrGarbageChars(4) = chr(145)
  31. End Sub
  32. Public Function ContainsVerbalOperator( _
  33. ByVal i_strText As String _
  34. ) As Boolean
  35. Static blnVerbalOperatorsInitialized As Boolean
  36. Static arrVerbalOperators() As String
  37. Dim str As Variant
  38. Dim arrStr() As String
  39. Dim intIndex As Long
  40. arrStr = Split(i_strText)
  41. ContainsVerbalOperator = False
  42. If (Not blnVerbalOperatorsInitialized) Then
  43. p_LoadVerbalOperators arrVerbalOperators
  44. blnVerbalOperatorsInitialized = True
  45. End If
  46. For Each str In arrVerbalOperators
  47. For intIndex = LBound(arrStr) To UBound(arrStr)
  48. If (arrStr(intIndex) = str) Then
  49. ContainsVerbalOperator = True
  50. Exit Function
  51. End If
  52. Next
  53. Next
  54. End Function
  55. Public Function IsVerbalOperator( _
  56. ByVal i_strText As String _
  57. ) As Boolean
  58. Static blnVerbalOperatorsInitialized As Boolean
  59. Static arrVerbalOperators() As String
  60. Dim str As String
  61. Dim intIndex As Long
  62. If (Not blnVerbalOperatorsInitialized) Then
  63. p_LoadVerbalOperators arrVerbalOperators
  64. blnVerbalOperatorsInitialized = True
  65. End If
  66. IsVerbalOperator = False
  67. str = LCase$(i_strText)
  68. For intIndex = LBound(arrVerbalOperators) To UBound(arrVerbalOperators)
  69. If (arrVerbalOperators(intIndex) = str) Then
  70. IsVerbalOperator = True
  71. Exit Function
  72. End If
  73. Next
  74. End Function
  75. Private Sub p_LoadVerbalOperators( _
  76. ByRef o_arrVerbalOperators() As String _
  77. )
  78. ReDim o_arrVerbalOperators(2)
  79. o_arrVerbalOperators(0) = "and"
  80. o_arrVerbalOperators(1) = "or"
  81. o_arrVerbalOperators(2) = "not"
  82. End Sub
  83. Public Function ContainsIndependentOperatorShortcut( _
  84. ByVal i_strText As String _
  85. ) As Boolean
  86. Static blnOperatorShortcutsInitialized As Boolean
  87. Static arrOperatorShortcuts() As String
  88. Dim char As Variant
  89. Dim arrStr() As String
  90. Dim intIndex As Long
  91. ' "a + b" qualifies
  92. ' "a+b", "a+ b", "a +b", don't qualify.
  93. arrStr = Split(i_strText)
  94. ContainsIndependentOperatorShortcut = False
  95. If (Not blnOperatorShortcutsInitialized) Then
  96. p_LoadOperatorShortcuts arrOperatorShortcuts
  97. blnOperatorShortcutsInitialized = True
  98. End If
  99. For Each char In arrOperatorShortcuts
  100. For intIndex = LBound(arrStr) To UBound(arrStr)
  101. If (arrStr(intIndex) = char) Then
  102. ContainsIndependentOperatorShortcut = True
  103. Exit Function
  104. End If
  105. Next
  106. Next
  107. End Function
  108. Public Function ContainsOperatorShortcut( _
  109. ByVal i_strText As String _
  110. ) As Boolean
  111. Static blnOperatorShortcutsInitialized As Boolean
  112. Static arrOperatorShortcuts() As String
  113. Dim char As Variant
  114. ' "a + b", "a+b", "a+ b", "a +b", all qualify.
  115. ContainsOperatorShortcut = False
  116. If (Not blnOperatorShortcutsInitialized) Then
  117. p_LoadOperatorShortcuts arrOperatorShortcuts
  118. blnOperatorShortcutsInitialized = True
  119. End If
  120. For Each char In arrOperatorShortcuts
  121. If (InStr(i_strText, char) <> 0) Then
  122. ContainsOperatorShortcut = True
  123. Exit Function
  124. End If
  125. Next
  126. End Function
  127. Public Function RemoveOperatorShortcuts( _
  128. ByVal i_strText As String _
  129. ) As String
  130. Static blnOperatorShortcutsInitialized As Boolean
  131. Static arrOperatorShortcuts() As String
  132. Dim intIndex1 As Long
  133. Dim intLength As Long
  134. Dim intIndex2 As Long
  135. Dim str As String
  136. If (Not blnOperatorShortcutsInitialized) Then
  137. p_LoadOperatorShortcuts arrOperatorShortcuts
  138. blnOperatorShortcutsInitialized = True
  139. End If
  140. str = i_strText
  141. intLength = Len(str)
  142. For intIndex1 = 1 To intLength
  143. For intIndex2 = LBound(arrOperatorShortcuts) To UBound(arrOperatorShortcuts)
  144. If (Mid$(str, intIndex1, 1) = arrOperatorShortcuts(intIndex2)) Then
  145. str = Mid$(str, 1, intIndex1 - 1) & " " & Mid$(str, intIndex1 + 1)
  146. End If
  147. Next
  148. Next
  149. RemoveOperatorShortcuts = str
  150. End Function
  151. Private Sub p_LoadOperatorShortcuts( _
  152. ByRef o_arrOperatorShortcuts() As String _
  153. )
  154. ReDim o_arrOperatorShortcuts(6)
  155. o_arrOperatorShortcuts(0) = """"
  156. o_arrOperatorShortcuts(1) = "&"
  157. o_arrOperatorShortcuts(2) = "|"
  158. o_arrOperatorShortcuts(3) = "!"
  159. o_arrOperatorShortcuts(4) = "+"
  160. o_arrOperatorShortcuts(5) = "("
  161. o_arrOperatorShortcuts(6) = ")"
  162. End Sub