u_dfc_base_func.sru 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. $PBExportHeader$u_dfc_base_func.sru
  2. forward
  3. global type u_dfc_base_func from nonvisualobject
  4. end type
  5. type ust_ip_option_information from structure within u_dfc_base_func
  6. end type
  7. type ust_icmp_echo_reply from structure within u_dfc_base_func
  8. end type
  9. end forward
  10. type ust_ip_option_information from structure
  11. character ttl
  12. character tos
  13. character flags
  14. character optionssize
  15. long optionsdata
  16. end type
  17. type ust_icmp_echo_reply from structure
  18. unsignedlong address
  19. unsignedlong status
  20. unsignedlong roundtriphome
  21. unsignedinteger datasize
  22. unsignedinteger reserved
  23. unsignedlong datapointer
  24. ust_ip_option_information options
  25. character data[250]
  26. end type
  27. global type u_dfc_base_func from nonvisualobject autoinstantiate
  28. end type
  29. type prototypes
  30. end prototypes
  31. type variables
  32. end variables
  33. forward prototypes
  34. public function string uf_replaceall (string psreplacestring, string psoldstring, string psnewstring)
  35. public function string uf_get_token (ref string pssource, string psseparator)
  36. public function boolean uf_split (string pssource, string pssperator, ref string pssplit[])
  37. public function string uf_getkeyvalue (string psstring, string pskey)
  38. public function string uf_setkeyvalue (string psstring, string pskey, string psvalue)
  39. public function string uf_get_token (ref string pssource, string psseparator, boolean pbremovecomma)
  40. public function boolean uf_split (string pssource, string pssperator, ref string pssplit[], boolean pbremovecomma)
  41. end prototypes
  42. public function string uf_replaceall (string psreplacestring, string psoldstring, string psnewstring);Long dlLen, dlPos, dlStart
  43. String dsResult
  44. dlLen = Len(psOldString)
  45. dsResult = psReplaceString
  46. dlStart = 1
  47. DO WHILE TRUE
  48. dlPos = Pos(dsResult, psOldString, dlStart)
  49. IF dlPos > 0 THEN
  50. dsResult = Replace(dsResult, dlPos, dlLen, psNewString)
  51. dlStart = dlPos + Len(psNewString)
  52. ELSE
  53. EXIT
  54. END IF
  55. LOOP
  56. Return dsResult
  57. end function
  58. public function string uf_get_token (ref string pssource, string psseparator);Return uf_Get_Token(psSource, psSeparator, True)
  59. end function
  60. public function boolean uf_split (string pssource, string pssperator, ref string pssplit[]);Return uf_Split(psSource, psSperator, psSplit, True)
  61. end function
  62. public function string uf_getkeyvalue (string psstring, string pskey);String dsKey[]
  63. String dsValue[]
  64. Integer i
  65. psString = uf_ReplaceAll(psString, "~~t", "~t")
  66. uf_Split(psString, "~t", dsKey)
  67. For i = 1 To UpperBound(dsKey)
  68. uf_Split(dsKey[i], "=", dsValue)
  69. If UpperBound(dsValue) >= 2 Then
  70. If Upper(Trim(dsValue[1])) = Upper(Trim(psKey)) Then
  71. Return dsValue[2]
  72. End If
  73. End If
  74. Next
  75. Return ""
  76. end function
  77. public function string uf_setkeyvalue (string psstring, string pskey, string psvalue);String dsKey[]
  78. String dsValue[]
  79. Integer i
  80. Boolean dbFound
  81. String dsString
  82. psString = uf_ReplaceAll(psString, "~~t", "~t")
  83. uf_Split(psString, "~t", dsKey)
  84. dbFound = False
  85. dsString = ""
  86. For i = 1 To UpperBound(dsKey)
  87. uf_Split(dsKey[i], "=", dsValue)
  88. If dsString <> "" Then
  89. dsString += "~t"
  90. End If
  91. If UpperBound(dsValue) >= 2 Then
  92. If Upper(Trim(dsValue[1])) = Upper(Trim(psKey)) Then
  93. dbFound = True
  94. dsValue[2] = psValue
  95. End If
  96. dsString += dsValue[1] + "="
  97. If Pos(dsValue[2], "=") > 0 Or Pos(dsValue[2], "~t") > 0 Then
  98. If Pos(dsValue[2], '"') = 0 Then
  99. dsString += '"' + dsValue[2]+ '"'
  100. ElseIf Pos(dsValue[2], "'") = 0 Then
  101. dsString += "'" + dsValue[2] + "'"
  102. Else
  103. MessageBox("出错信息", "调用函数 uf_SetKeyValue 出错!~n~n" + &
  104. "关键字: " + dsValue[1] + "~n值: " + dsValue[2] + "~n~n" + &
  105. "无法处理值中的等于号(=)!", StopSign!)
  106. Return ""
  107. End If
  108. Else
  109. dsString += dsValue[2]
  110. End If
  111. Else
  112. dsString += dsValue[1]
  113. End If
  114. Next
  115. If Not dbFound Then
  116. If dsString <> "" Then
  117. dsString += "~t"
  118. End If
  119. dsString += psKey + "="
  120. If Pos(psValue, "=") > 0 Or Pos(psValue, "~t") > 0 Then
  121. If (Left(psValue, 1) = "'" And Right(psValue, 1) = "'") Or &
  122. Left(psValue, 1) = '"' And Right(psValue, 1) = '"' Then
  123. dsString += psValue
  124. Else
  125. If Pos(psValue, '"') = 0 Then
  126. dsString += '"' + psValue + '"'
  127. ElseIf Pos(psValue, "'") = 0 Then
  128. dsString += "'" + psValue + "'"
  129. Else
  130. MessageBox("出错信息", "调用函数 uf_SetKeyValue 出错!~n~n" + &
  131. "关键字: " + psKey + "~n值: " + psValue + "~n~n" + &
  132. "无法处理值中的等于号(=)!", StopSign!)
  133. Return ""
  134. End If
  135. End If
  136. Else
  137. dsString += psValue
  138. End If
  139. End If
  140. Return dsString
  141. end function
  142. public function string uf_get_token (ref string pssource, string psseparator, boolean pbremovecomma);// uf_Get_Token
  143. // 参数:
  144. // psSource: 源串
  145. // psSparator: 分隔符
  146. // pbRemoveComma: 是否去除引号
  147. // 返回:
  148. // 分隔符前的串
  149. long p
  150. Long dlPos
  151. string ret
  152. Boolean dbFoundComma1, dbFoundComma2
  153. // p = Pos(psSource, psSeparator) // Get the position of the psSeparator
  154. // 查找 psSource 中 psSeparator 的位置
  155. p = 0
  156. dbFoundComma1 = False
  157. dbFoundComma2 = False
  158. For dlPos = 1 To Len(psSource)
  159. If Mid(psSource, dlPos, 1) = '"' Then
  160. dbFoundComma1 = Not dbFoundComma1
  161. End If
  162. If Mid(psSource, dlPos, 1) = "'" Then
  163. dbFoundComma2 = Not dbFoundComma2
  164. End If
  165. If Mid(psSource, dlPos, 1) = psSeparator Then
  166. If Not dbFoundComma1 And Not dbFoundComma2 Then
  167. p = dlPos
  168. Exit
  169. End If
  170. End If
  171. Next
  172. if p = 0 then // if no psSeparator,
  173. ret = psSource // return the whole psSource string and
  174. psSource = "" // make the original psSource of zero length
  175. else
  176. ret = Mid (psSource, 1, p - 1) // otherwise, return just the token and
  177. psSource = Mid (psSource, p + Len ( psSeparator )) // strip it & the psSeparator
  178. end if
  179. ret = Trim(ret)
  180. ret = uf_ReplaceAll(ret, "''", "'")
  181. ret = uf_ReplaceAll(ret, '""', '"')
  182. If pbRemoveComma Then
  183. If Left(ret, 1) = Right(ret, 1) And &
  184. (Left(ret, 1) = "'" Or Left(ret, 1) = '"') Then
  185. ret = Mid(ret, 2, Len(ret) - 2)
  186. End If
  187. End If
  188. return ret
  189. end function
  190. public function boolean uf_split (string pssource, string pssperator, ref string pssplit[], boolean pbremovecomma);// uf_Split
  191. // 参数
  192. // psSource
  193. // psSperator
  194. // psSpilt
  195. // pbRemoveComma: 去除引号
  196. Integer i
  197. Boolean dbFound
  198. // 判断 psSource 的最后是否是分隔符, 如果是, 则在最后添加一个空值
  199. If Right(psSource, Len(psSperator)) = psSperator Then
  200. dbFound = True
  201. Else
  202. dbFound = False
  203. End If
  204. i = 0
  205. Do While psSource <> ""
  206. i ++
  207. psSplit[i] = Trim(uf_Get_Token(psSource, psSperator, pbRemoveComma))
  208. Loop
  209. // 如果最后一个值是分隔符, 则添加一个空值在最后
  210. If dbFound Then
  211. i ++
  212. psSplit[i] = ""
  213. End If
  214. Return True
  215. end function
  216. on u_dfc_base_func.create
  217. call super::create
  218. TriggerEvent( this, "constructor" )
  219. end on
  220. on u_dfc_base_func.destroy
  221. TriggerEvent( this, "destructor" )
  222. call super::destroy
  223. end on