zoukankan      html  css  js  c++  java
  • 在LotusScript中处理UTF8编码的内容

    最近工作需要,要完成一个基于Lotus Domino的网站。由于涉及混合语种问题,网站编码基调定为UTF-8,而且其中有部分需要用LotusScprit代理直接接收HTML Form里Submit过来的数据。以前遇到这个问题都是想办法绕开的,那时候没时间,为了赶进度,只能这样。这次项目时间较富裕,我决定吭一下,看看牙口尚好否。
    目标:Decode UTF-8 form data in LotusScript Agent.
    Google、Baidu外加IBM Lotus论坛,搜索了一通,有四、五段现成的代码,经测试没有一个对的,想偷懒都不行了:(
    转变思路,查询UTF-8编码规则,Baidu上找到一篇关于UTF-8的说明,很不错,终于看懂了字符编码到UTF-8编码的转换规则。
    原来UTF-8编码是将字符编码通过一种转换规则变成1~6字节的编码。
    浏览器将form中的多字节字符和一部分单字字符转变成这种编码,与其他单字节字符连成字符串,再把其中的空格用“+”代替,就成了在Lotus Agent中接收到的字符串参数了。
    由于LotusScript中Uchr()函数最多只能转换双字节字符,3、4字节的字符就不做转换了,保留在原字符串中。
    Function Utf8Decode(s As String) As String
     Dim i As Integer
     Dim tmp As String
     Dim c As String
     tmp = ""
     For i = 1 To Len(s)
      c = Mid$(s, i, 1)
      If c = "+" Then
       c = " "
      Elseif c = "%" Then
       c = Mid$(s, i + 1, 2)
       If (Val("&H" & c) >= 0) And (Val("&H" & c) <= Val("&H7F")) Then
        c = Uchr$("&H" & c)
        i = i + 2
       Elseif (Val("&H" & c) >= Val("&HC0")) And (Val("&H" & c) <= Val("&HDF")) Then
        c = Right(Bin$(Val("&H" & Mid$(s, i + 1, 2))),5)
        c = c & Right(Bin$(Val("&H" & Mid$(s, i + 4, 2))),6)
        c = Uchr$("&B" & c)
        i = i + 5
       Elseif (Val("&H" & c) >= Val("&HE0")) And (Val("&H" & c) <= Val("&HEF")) Then
        c = Right(Bin$(Val("&H" & Mid$(s, i + 1, 2))),4)
        c = c & Right(Bin$(Val("&H" & Mid$(s, i + 4, 2))),6)
        c = c & Right(Bin$(Val("&H" & Mid$(s, i + 7, 2))),6)
        c = Uchr$("&B" & c)
        i = i + 8
       Else
        c = Mid$(s, i, 3)
        i = i + 2
       End If
      End If
      tmp = tmp + c
     Next i
     Utf8Decode = tmp
    End Function
  • 相关阅读:
    redis全面解析
    SoapUI Pro Project Solution Collection-change the JDBC Request behavior
    SoapUI Pro Project Solution Collection-Test Step Object
    SoapUI Pro Project Solution Collection-access the soapui object
    SoapUI Pro Project Solution Collection –Easy develop Groovy Script to improve SoapUI ability
    Eclipse 个人使用配置
    Selenium 致命杀手(有关自动化的通病)
    Open-Source performance testing tools(From other site)
    麦当劳理论(转转转)
    java command line error opening registry key 'SoftwareJavaSoftJava Runtime Environment' java.dll
  • 原文地址:https://www.cnblogs.com/hannover/p/1867572.html
Copyright © 2011-2022 走看看