From 84a9feb735e96c8bf28b4b16b82618b1322b0c31 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Tue, 30 Aug 2011 16:49:49 +0400 Subject: [PATCH] python --- python/UTF8to1251table.py | 8 ++++++++ python/unicode.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 python/UTF8to1251table.py create mode 100644 python/unicode.py diff --git a/python/UTF8to1251table.py b/python/UTF8to1251table.py new file mode 100644 index 0000000..6702f83 --- /dev/null +++ b/python/UTF8to1251table.py @@ -0,0 +1,8 @@ +# -*- coding: cp1251 -*- + +for i in range(0,256): + c=unicode(chr(i),"koi8-r") + c.encode("UTF-8") + +for i in range(0,128): + print i," " diff --git a/python/unicode.py b/python/unicode.py new file mode 100644 index 0000000..6e01c62 --- /dev/null +++ b/python/unicode.py @@ -0,0 +1,19 @@ +declare +@ucs nvarchar(4000), +@utf varchar(8000), +@w varbinary(2), +@i int + +set @ucs = N'яфя Åk Paço عوديهالشرموطةناناالشرموطةفاطمةالشرموطةليلىالسحاقيةهالة' +set @utf = '' +set @i = 1 + +while @i <= len(@ucs) +begin +set @w = (select utf8 from ucs2utf8 where ucs2 = unicode(substring(@ucs, @i, 1))) +if @w/256 != 0 set @utf = @utf + char(@w/256) +if @w-(@w/256)*256 != 0 set @utf = @utf + char(@w-(@w/256)*256) +set @i = @i + 1 +end + +print @utf