Short functions to encode/decode string<->punycode data. You can use these functions as an Internationalized Domain Names VBScript converter.
ByteArray - Punycode - unicode conversions | |
---|---|
Dim m_BA Function BA If IsEmpty(m_BA) Then Set m_BA = CreateObject("ScriptUtils.ByteArray"): m_BA.CharSet = "utf-8" Set BA = m_BA End Function 'conversion from unicode string to punycode Function ToPUNYCODE(Data) Dim Outdata BA.String = Data Outdata = "<div>ToPUNYCODE : Punycode representation of '" & _ Data & "' string :<div style=background-color:yellow;color:blue>" Outdata = Outdata & "<b>" & BA.Punycode & "</b>" Outdata = Outdata & "</div></div>" ToPUNYCODE = Outdata End Function 'conversion from punycode string (OLE String) to a UNICODE string Function FromPUNYCODE(Data) Dim Outdata On Error Resume Next BA.Punycode = Data If Err=0 Then Outdata = "<div>FromPUNYCODE : Unicode string :<div style=background-color:yellow;color:blue>" Outdata = Outdata & "<b>" & BA.String & "</b>"'write the UTF representation Outdata = Outdata & "</div></div>" Else Outdata = "<div style=background-color:red;color:yellow>FromPUNYCODE:Punycode string '" & _ Data & "' has no unicode representation.</div>" End If FromPUNYCODE = Outdata End Function 'conversion of a host name (www.anychar.com) to a punycode idn version (www.xn--translated.com) Function ToIDN(Data) Dim Outdata, pData, partuni, partpuny pData = Split(Data, ".") For Each partuni In pData BA.String = partuni partpuny = BA.Punycode If Right(partpuny,1)<>"-" Then partpuny = "xn--" & partpuny Else partpuny = partuni Outdata = Outdata & partpuny & "." Next Outdata = Left(Outdata, Len(Outdata)-1) ToIDN = "<div>ToIDN : IDN representation of '" & _ Data & "' string :<div style=background-color:yellow;color:blue><b>" & _ Outdata & "</b></div></div>" End Function 'conversion of a host name in idn punycode (www.xn--translated.com) ' to an unicode string (www.anychar.com) Function FromIDN(ByVal Data) Dim Outdata, pData, partuni, partpuny Data = LCase(Data) pData = Split(Data, ".") For Each partpuny In pData If Left(partpuny,4)="xn--" Then BA.Punycode = Mid(partpuny, 5) partuni = Ba.String Else 'on error resume next 'BA.Punycode = partpuny Dim re :set re = New RegExp re.pattern = "^[-a-zA-Z0-9]+$" If re.Test(partpuny) Then partuni = partpuny Else partuni = "<font Color=red>error (" & partpuny & ")</Font>" End If End If Outdata = Outdata & partuni & "." Next Outdata = Left(Outdata, Len(Outdata)-1) FromIDN = "<div>FromIDN : Unicode representation of IDN '" & Data & _ "' :<div style=background-color:yellow;color:blue><b>" & _ Outdata & "</b></div></div>" End Function |
Works with safearray binary data - save/restore binary data from/to a disk, convert to a string/hexstring, codepage/charset conversions, Base64 conversion, etc.
ByteArray is a COM class specially designed to work with Microsoft Windows Scripting engines - VB Script and JScript in Active Server Pages or WSH and in CHM or HTA applications. It also works with VB Net, Visual basic (VBA - VB 5, VB 6, Word, Excel, Access, …), C#, J#, C++, ASP, ASP.Net, Delphi and with T-SQL OLE functions - see Use ByteArray object article. You can also use the object in other programming environments with COM support, such is PowerBuilder.
Source code for ByteArray is available within distribution license, please see License page for ASP file upload and ScriptUtilities.
Huge ASP upload is easy to use, hi-performance ASP file upload component with progress bar indicator. This component lets you upload multiple files with size up to 4GB to a disk or a database along with another form fields. Huge ASP file upload is a most featured upload component on a market with competitive price and a great performance . The software has also a free version of asp upload with progress, called Pure asp upload , written in plain VBS, without components (so you do not need to install anything on server). This installation package contains also ScriptUtilities library. Script Utilities lets you create hi-performance log files , works with binary data , you can download multiple files with zip/arj compression, work with INI files and much more with the ASP utility.
© 1996 - 2011 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz