<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Кириллица в URL]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=10161&amp;type=atom" />
	<updated>2015-08-23T23:38:16Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=10161</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96788#p96788" />
			<content type="html"><![CDATA[<p>Одинаково:<br /></p><div class="codebox"><pre><code>SetFormat, IntegerFast, H
str := &quot;ЁЁ&quot;
MsgBox, % NumGet(str, &quot;UInt&quot;)
While code := NumGet(str, A_Index - 1, &quot;UChar&quot;)
    MsgBox, % code

VarSetCapacity(var, StrPut(str, &quot;UTF-8&quot;))
StrPut(str, &amp;var, &quot;UTF-8&quot;)
MsgBox, % NumGet(var, &quot;UInt&quot;)

While code := NumGet(var, A_Index - 1, &quot;UChar&quot;)
    MsgBox, % code</code></pre></div><p>В UTF-8 Ё — 0x81D0, a в URL — в обратном порядке: %D0%81</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T23:38:16Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96788#p96788</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96787#p96787" />
			<content type="html"><![CDATA[<p>Туго у меня с этим делом... Например почему в случае с &quot;перебором&quot; байтов в &quot;UTF-8&quot; всё по порядку?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-08-23T23:31:53Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96787#p96787</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96784#p96784" />
			<content type="html"><![CDATA[<p>Чтение идёт от младших байтов к старшим.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T23:27:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96784#p96784</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96783#p96783" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>0x1 — это 0x01<br />0x4 — это 0x04<br />Вместе 0x0401</p></blockquote></div><p>Жутко не понятно, почему не по порядку - 0x0104.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-08-23T23:25:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96783#p96783</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96782#p96782" />
			<content type="html"><![CDATA[<p>А, ну да, может быть и четыре для всяких символов типа арабских. В AHK-Unicode строки кодируются в UTF-16, так что </p><div class="codebox"><pre><code>encoding := &quot;UTF-16&quot; 
VarSetCapacity(var, StrPut(str, encoding))
StrPut(str, &amp;var, encoding) </code></pre></div><p>не нужно.<br /></p><div class="codebox"><pre><code>SetFormat, IntegerFast, H
str := &quot;Ё&quot; 

While code := NumGet(str, A_Index - 1, &quot;UChar&quot;)
    MsgBox, % code</code></pre></div><p>0x1 — это 0x01<br />0x4 — это 0x04<br />Вместе 0x0401</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T23:22:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96782#p96782</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96781#p96781" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>UTF-16 — 2 байта на символ (16 бит).</p></blockquote></div><p>Но может быть и 4?<br /></p><div class="quotebox"><cite>wikipedia пишет:</cite><blockquote><p>Один символ кодировки UTF-16 представлен последовательностью двух байтов или <span class="bbu">двух пар байтов</span></p></blockquote></div><p>Ещё меньше понимаю что за 1 потом 4 в этом коде:<br /></p><div class="codebox"><pre><code>SetFormat, IntegerFast, H
str := &quot;Ё&quot; 
encoding := &quot;UTF-16&quot; 
VarSetCapacity(var, StrPut(str, encoding))
StrPut(str, &amp;var, encoding) 
While code := NumGet(Var, A_Index - 1, &quot;UChar&quot;)
    MsgBox, % code</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-08-23T23:08:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96781#p96781</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96780#p96780" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>SetFormat, IntegerFast, H
str := &quot;ЁЁ&quot;
VarSetCapacity(var, StrPut(str, &quot;UTF-8&quot;))
StrPut(str, &amp;var, &quot;UTF-8&quot;)
MsgBox, % NumGet(var, &quot;UInt&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T22:56:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96780#p96780</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96779#p96779" />
			<content type="html"><![CDATA[<p>UTF-16 — 2 байта на символ (16 бит).<br /></p><div class="codebox"><pre><code>SetFormat, IntegerFast, H
str := &quot;ЁЁ&quot;
MsgBox, % NumGet(&amp;str, &quot;UInt&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T22:43:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96779#p96779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96777#p96777" />
			<content type="html"><![CDATA[<p>Теперь ещё более непонятно, 0xD0 и 0x81 это цифровое представление двух байт в UTF-8.?<br />А какая связь 0x401 и UTF-16?&nbsp; В UTF-16 кажется 4 байта на символ, да и 0x401 не может быть представлением байта.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-08-23T22:24:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96777#p96777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96775#p96775" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>С первым MsgBox понятно, а во втором число 0x401 как то логично &quot;разбивается&quot; на 0xd0 &amp; 0x81?</p></blockquote></div><p>Ё = 0x401 — это UTF-16, а %D0%81 — это UTF-8.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2015-08-23T22:10:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96775#p96775</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=96768#p96768" />
			<content type="html"><![CDATA[<p>Пара вопросов.<br />Сократил запись (хлебом не корми):<br /></p><div class="codebox"><pre><code>
URIEncode(str, encoding := &quot;UTF-8&quot;) {  
    VarSetCapacity(var, StrPut(str, encoding)), StrPut(str, &amp;var, encoding) 
    While code := NumGet(Var, A_Index - 1, &quot;UChar&quot;)
        UrlStr .= (code &gt; 0x7F || code &lt; 0x30 || code = 0x3D) ? Format(&quot;%{:02X}&quot;, code) : Chr(code) 
    Return UrlStr
}
</code></pre></div><p>Есть ли ошибки, и смущает расхождение с оригиналом:<br /></p><div class="codebox"><pre><code>SubStr(&quot;0&quot; . SubStr(code, 3), -1)</code></pre></div><p> <br />После процента обязательно должно быть 2 знака?</p><p>И для общего развития, по поводу индекса в Unicode и значений байтов (собственно а есть ли тут связь?).<br /></p><div class="codebox"><pre><code>SetFormat, IntegerFast, h
 ; в комментариях значения как и в NumGet
str :=  &quot;,&quot;  
MsgBox, % Ord(str) ; 0x2c

str :=  &quot;Ё&quot; 
MsgBox, % Ord(str) ; 0xd0 &amp; 0x81</code></pre></div><p>С первым MsgBox понятно, а во втором число 0x401 как то логично &quot;разбивается&quot; на 0xd0 &amp; 0x81?</p><p>Ап: По поводу: </p><div class="quotebox"><blockquote><p>После процента обязательно должно быть 2 знака?</p></blockquote></div><p>Разобрался, поправил.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-08-23T18:55:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=96768#p96768</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=88474#p88474" />
			<content type="html"><![CDATA[<p>Немного сократил:<br /></p><div class="codebox"><pre><code>text := &quot;&quot;&quot;кодировка URL&quot;&quot;&quot;
GoogleSearch := &quot;https://www.google.ru/search?q=&quot;

MsgBox, % url := GoogleSearch . URIEncode(text)
Run, % url

URIEncode(str, encoding := &quot;UTF-8&quot;)
{
   PrevFormat := A_FormatInteger
   SetFormat, IntegerFast, H
; кодируем стоку в указанную кодировку с помощью StrPut()
   VarSetCapacity(var, StrPut(str, encoding))
   StrPut(str, &amp;var, encoding)
; последовательно перебирая символы, кодируем их в URL-формат   
   While code := NumGet(Var, A_Index - 1, &quot;UChar&quot;)   ; пока code не равно 0, что означает конец строки
   {
      bool := (code &gt; 0x7F || code &lt; 0x30 || code = 0x3D)   ; отсеиваем символы, которые кодировать не нужно
      UrlStr .= bool ? &quot;%&quot; . SubStr(&quot;0&quot; . SubStr(code, 3), -1) : Chr(code)
   }
   SetFormat, IntegerFast, % PrevFormat
   Return UrlStr
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-11-19T20:18:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=88474#p88474</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=88469#p88469" />
			<content type="html"><![CDATA[<p>Тоже не понял в каких случаях, но если пример универсален, то поддерживаю, надо в коллекцию.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-11-19T17:09:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=88469#p88469</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=88467#p88467" />
			<content type="html"><![CDATA[<p>Можно, хотя я так и не понял, в каких конкретно случаях требуется конвертировать в ANSI.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-11-19T17:02:11Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=88467#p88467</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Кириллица в URL]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=88455#p88455" />
			<content type="html"><![CDATA[<p>Предлагаю пример в Коллекцию. Это становится актуально.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2014-11-19T09:47:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=88455#p88455</id>
		</entry>
</feed>
