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.

131 lines
2.9 KiB

  1. Attribute VB_Name = "Strings"
  2. Option Explicit
  3. Public Function XmlText( _
  4. ByVal i_str As String _
  5. ) As String
  6. Dim intIndex As Long
  7. Dim intLength As Long
  8. Dim strChar As String
  9. Dim str As String
  10. str = RemoveExtraSpaces(i_str)
  11. intLength = Len(str)
  12. XmlText = ""
  13. For intIndex = 1 To intLength
  14. strChar = Mid$(str, intIndex, 1)
  15. Select Case strChar
  16. Case Is = "<"
  17. XmlText = XmlText & "&lt;"
  18. Case Is = ">"
  19. XmlText = XmlText & "&gt;"
  20. Case Is = "&"
  21. XmlText = XmlText & "&amp;"
  22. Case Is = "'"
  23. XmlText = XmlText & "&apos;"
  24. Case Is = """"
  25. XmlText = XmlText & "&quot;"
  26. Case Else
  27. XmlText = XmlText & strChar
  28. End Select
  29. Next
  30. End Function
  31. Public Function RemoveExtraSpaces( _
  32. ByVal i_strText As String _
  33. ) As String
  34. Dim arrStr() As String
  35. Dim intIndex As Long
  36. RemoveExtraSpaces = ""
  37. arrStr = Split(i_strText)
  38. For intIndex = LBound(arrStr) To UBound(arrStr)
  39. If (arrStr(intIndex) <> "") Then
  40. If (RemoveExtraSpaces = "") Then
  41. RemoveExtraSpaces = RemoveExtraSpaces & arrStr(intIndex)
  42. Else
  43. RemoveExtraSpaces = RemoveExtraSpaces & " " & arrStr(intIndex)
  44. End If
  45. End If
  46. Next
  47. End Function
  48. Public Function RemoveCRLF( _
  49. ByVal i_strText As String _
  50. ) As String
  51. Dim intIndex As Long
  52. Dim strCurrentChar As String
  53. RemoveCRLF = ""
  54. For intIndex = 1 To Len(i_strText)
  55. strCurrentChar = Mid$(i_strText, intIndex, 1)
  56. If ((strCurrentChar = vbCr) Or (strCurrentChar = vbLf)) Then
  57. ' Ignore this char
  58. Else
  59. RemoveCRLF = RemoveCRLF & strCurrentChar
  60. End If
  61. Next
  62. End Function
  63. Public Function ChangeBackSlashToSlash( _
  64. ByVal i_str As String _
  65. ) As String
  66. Dim intIndex As Long
  67. Dim str As String
  68. str = i_str
  69. For intIndex = 1 To Len(str)
  70. If (Mid$(str, intIndex, 1) = "\") Then
  71. str = Mid$(str, 1, intIndex - 1) & "/" & Mid$(str, intIndex + 1)
  72. End If
  73. Next
  74. ChangeBackSlashToSlash = str
  75. End Function
  76. Private Function p_IsSpecialChar( _
  77. ByVal i_chr As String _
  78. ) As Boolean
  79. Select Case i_chr
  80. Case " ", vbTab, "/", "\"
  81. p_IsSpecialChar = True
  82. Case Else
  83. p_IsSpecialChar = XMLSpecialCharacter(i_chr)
  84. End Select
  85. End Function
  86. ' HHTs: Create an ENTRY from a string.
  87. Public Function Mangle( _
  88. ByVal i_strName _
  89. ) As String
  90. Dim intIndex As Long
  91. Dim chr As String
  92. Mangle = ""
  93. For intIndex = 1 To Len(i_strName)
  94. chr = Mid$(i_strName, intIndex, 1)
  95. Mangle = Mangle & IIf(p_IsSpecialChar(chr), "_", chr)
  96. Next
  97. End Function