Leaked source code of windows server 2003
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.

283 lines
7.3 KiB

  1. Attribute VB_Name = "StringContentsTest"
  2. Option Explicit
  3. Private p_arrVerbalOperatorsAnd() As String
  4. Private p_arrVerbalOperatorsOr() As String
  5. Private p_arrVerbalOperatorsNot() As String
  6. Private Const OPERATOR_DELIMITER_C As String = ";"
  7. Public Function ContainsGarbage( _
  8. ByVal i_strText As String _
  9. ) As Boolean
  10. Static blnGarbageCharsInitialized As Boolean
  11. Static arrGarbageChars() As String
  12. Dim char As Variant
  13. ContainsGarbage = False
  14. If (Not blnGarbageCharsInitialized) Then
  15. p_LoadGarbageChars arrGarbageChars
  16. blnGarbageCharsInitialized = True
  17. End If
  18. For Each char In arrGarbageChars
  19. If (InStr(i_strText, char) <> 0) Then
  20. ContainsGarbage = True
  21. Exit Function
  22. End If
  23. Next
  24. ContainsGarbage = Not XMLValidString(i_strText)
  25. End Function
  26. Private Sub p_LoadGarbageChars( _
  27. ByRef o_arrGarbageChars() As String _
  28. )
  29. ReDim o_arrGarbageChars(4)
  30. o_arrGarbageChars(0) = vbCr
  31. o_arrGarbageChars(1) = vbLf
  32. o_arrGarbageChars(2) = vbTab
  33. o_arrGarbageChars(3) = chr(146)
  34. o_arrGarbageChars(4) = chr(145)
  35. End Sub
  36. Public Function ContainsVerbalOperator( _
  37. ByVal i_strText As String _
  38. ) As Boolean
  39. Dim str As Variant
  40. Dim arrStr() As String
  41. Dim intIndex As Long
  42. ContainsVerbalOperator = False
  43. arrStr = Split(LCase$(i_strText))
  44. For Each str In p_arrVerbalOperatorsAnd
  45. For intIndex = LBound(arrStr) To UBound(arrStr)
  46. If (arrStr(intIndex) = str) Then
  47. ContainsVerbalOperator = True
  48. Exit Function
  49. End If
  50. Next
  51. Next
  52. For Each str In p_arrVerbalOperatorsOr
  53. For intIndex = LBound(arrStr) To UBound(arrStr)
  54. If (arrStr(intIndex) = str) Then
  55. ContainsVerbalOperator = True
  56. Exit Function
  57. End If
  58. Next
  59. Next
  60. For Each str In p_arrVerbalOperatorsNot
  61. For intIndex = LBound(arrStr) To UBound(arrStr)
  62. If (arrStr(intIndex) = str) Then
  63. ContainsVerbalOperator = True
  64. Exit Function
  65. End If
  66. Next
  67. Next
  68. End Function
  69. Public Function IsVerbalOperator( _
  70. ByVal i_strText As String _
  71. ) As Boolean
  72. Dim str As String
  73. Dim strOperator As Variant
  74. IsVerbalOperator = False
  75. str = LCase$(i_strText)
  76. For Each strOperator In p_arrVerbalOperatorsAnd
  77. If (str = strOperator) Then
  78. IsVerbalOperator = True
  79. Exit Function
  80. End If
  81. Next
  82. For Each strOperator In p_arrVerbalOperatorsOr
  83. If (str = strOperator) Then
  84. IsVerbalOperator = True
  85. Exit Function
  86. End If
  87. Next
  88. For Each strOperator In p_arrVerbalOperatorsNot
  89. If (str = strOperator) Then
  90. IsVerbalOperator = True
  91. Exit Function
  92. End If
  93. Next
  94. End Function
  95. Public Sub GetVerbalOperators( _
  96. ByRef o_arrStrAnd() As String, _
  97. ByRef o_arrStrOr() As String, _
  98. ByRef o_arrStrNot() As String _
  99. )
  100. o_arrStrAnd = p_arrVerbalOperatorsAnd
  101. o_arrStrOr = p_arrVerbalOperatorsOr
  102. o_arrStrNot = p_arrVerbalOperatorsNot
  103. End Sub
  104. Public Sub SetVerbalOperators( _
  105. ByVal i_strAnd As String, _
  106. ByVal i_strOr As String, _
  107. ByVal i_strNot As String _
  108. )
  109. p_SetVerbalOperators i_strAnd, p_arrVerbalOperatorsAnd
  110. p_SetVerbalOperators i_strOr, p_arrVerbalOperatorsOr
  111. p_SetVerbalOperators i_strNot, p_arrVerbalOperatorsNot
  112. End Sub
  113. Private Sub p_SetVerbalOperators( _
  114. ByVal i_str As String, _
  115. ByRef o_arrOperators() As String _
  116. )
  117. Dim strOperator As Variant
  118. Dim arrStr() As String
  119. Dim intIndex As Long
  120. arrStr = Split(i_str, OPERATOR_DELIMITER_C)
  121. If (UBound(arrStr) = -1) Then
  122. Exit Sub
  123. End If
  124. ReDim o_arrOperators(UBound(arrStr) - LBound(arrStr))
  125. For Each strOperator In arrStr
  126. strOperator = Trim$(LCase$(strOperator))
  127. If (strOperator <> "") Then
  128. o_arrOperators(intIndex) = strOperator
  129. intIndex = intIndex + 1
  130. End If
  131. Next
  132. If (intIndex > 0) Then
  133. ReDim Preserve o_arrOperators(intIndex - 1)
  134. End If
  135. End Sub
  136. Public Function ContainsIndependentOperatorShortcut( _
  137. ByVal i_strText As String _
  138. ) As Boolean
  139. Static blnOperatorShortcutsInitialized As Boolean
  140. Static arrOperatorShortcuts() As String
  141. Dim char As Variant
  142. Dim arrStr() As String
  143. Dim intIndex As Long
  144. ' "a + b" qualifies
  145. ' "a+b", "a+ b", "a +b", don't qualify.
  146. arrStr = Split(i_strText)
  147. ContainsIndependentOperatorShortcut = False
  148. If (Not blnOperatorShortcutsInitialized) Then
  149. p_LoadOperatorShortcuts arrOperatorShortcuts
  150. blnOperatorShortcutsInitialized = True
  151. End If
  152. For Each char In arrOperatorShortcuts
  153. For intIndex = LBound(arrStr) To UBound(arrStr)
  154. If (arrStr(intIndex) = char) Then
  155. ContainsIndependentOperatorShortcut = True
  156. Exit Function
  157. End If
  158. Next
  159. Next
  160. End Function
  161. Public Function ContainsOperatorShortcut( _
  162. ByVal i_strText As String _
  163. ) As Boolean
  164. Static blnOperatorShortcutsInitialized As Boolean
  165. Static arrOperatorShortcuts() As String
  166. Dim char As Variant
  167. ' "a + b", "a+b", "a+ b", "a +b", all qualify.
  168. ContainsOperatorShortcut = False
  169. If (Not blnOperatorShortcutsInitialized) Then
  170. p_LoadOperatorShortcuts arrOperatorShortcuts
  171. blnOperatorShortcutsInitialized = True
  172. End If
  173. For Each char In arrOperatorShortcuts
  174. If (InStr(i_strText, char) <> 0) Then
  175. ContainsOperatorShortcut = True
  176. Exit Function
  177. End If
  178. Next
  179. End Function
  180. Public Function RemoveOperatorShortcuts( _
  181. ByVal i_strText As String _
  182. ) As String
  183. Static blnOperatorShortcutsInitialized As Boolean
  184. Static arrOperatorShortcuts() As String
  185. Dim intIndex1 As Long
  186. Dim intLength As Long
  187. Dim intIndex2 As Long
  188. Dim str As String
  189. If (Not blnOperatorShortcutsInitialized) Then
  190. p_LoadOperatorShortcuts arrOperatorShortcuts
  191. blnOperatorShortcutsInitialized = True
  192. End If
  193. str = i_strText
  194. intLength = Len(str)
  195. For intIndex1 = 1 To intLength
  196. For intIndex2 = LBound(arrOperatorShortcuts) To UBound(arrOperatorShortcuts)
  197. If (Mid$(str, intIndex1, 1) = arrOperatorShortcuts(intIndex2)) Then
  198. str = Mid$(str, 1, intIndex1 - 1) & " " & Mid$(str, intIndex1 + 1)
  199. End If
  200. Next
  201. Next
  202. RemoveOperatorShortcuts = str
  203. End Function
  204. Private Sub p_LoadOperatorShortcuts( _
  205. ByRef o_arrOperatorShortcuts() As String _
  206. )
  207. ReDim o_arrOperatorShortcuts(6)
  208. o_arrOperatorShortcuts(0) = """"
  209. o_arrOperatorShortcuts(1) = "&"
  210. o_arrOperatorShortcuts(2) = "|"
  211. o_arrOperatorShortcuts(3) = "!"
  212. o_arrOperatorShortcuts(4) = "+"
  213. o_arrOperatorShortcuts(5) = "("
  214. o_arrOperatorShortcuts(6) = ")"
  215. End Sub