~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to sigscheme/doc/multibyte.html

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2008-05-18 22:18:10 UTC
  • mfrom: (1.1.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080518221810-4d2rd0ca18xnu8kc
Tags: 1:1.5.1-1
* New upstream release
* uim-qt3: Add uim inputcontext plugin for Qt3. And due to uim-*-qt are
  not supported in Qt4 for now officially, uim-*-qt are contained in
  this package.
* uim-qt: Depends uim-qt3 because of described above.
* libuim6: New package for syncing with upstream upgrade soversion.
* 05_qmake_bug_workaround.dpatch: patch for the workaround that qmake does
  not add link option against other libraries(e.g. -lX11) by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 
2
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
3
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 
4
<head>
 
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
6
<meta name="generator" content="AsciiDoc 8.2.2" />
 
7
<style type="text/css">
 
8
/* Debug borders */
 
9
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
 
10
/*
 
11
  border: 1px solid red;
 
12
*/
 
13
}
 
14
 
 
15
body {
 
16
  margin: 1em 5% 1em 5%;
 
17
}
 
18
 
 
19
a {
 
20
  color: blue;
 
21
  text-decoration: underline;
 
22
}
 
23
a:visited {
 
24
  color: fuchsia;
 
25
}
 
26
 
 
27
em {
 
28
  font-style: italic;
 
29
}
 
30
 
 
31
strong {
 
32
  font-weight: bold;
 
33
}
 
34
 
 
35
tt {
 
36
  color: navy;
 
37
}
 
38
 
 
39
h1, h2, h3, h4, h5, h6 {
 
40
  color: #527bbd;
 
41
  font-family: sans-serif;
 
42
  margin-top: 1.2em;
 
43
  margin-bottom: 0.5em;
 
44
  line-height: 1.3;
 
45
}
 
46
 
 
47
h1 {
 
48
  border-bottom: 2px solid silver;
 
49
}
 
50
h2 {
 
51
  border-bottom: 2px solid silver;
 
52
  padding-top: 0.5em;
 
53
}
 
54
 
 
55
div.sectionbody {
 
56
  font-family: serif;
 
57
  margin-left: 0;
 
58
}
 
59
 
 
60
hr {
 
61
  border: 1px solid silver;
 
62
}
 
63
 
 
64
p {
 
65
  margin-top: 0.5em;
 
66
  margin-bottom: 0.5em;
 
67
}
 
68
 
 
69
pre {
 
70
  padding: 0;
 
71
  margin: 0;
 
72
}
 
73
 
 
74
span#author {
 
75
  color: #527bbd;
 
76
  font-family: sans-serif;
 
77
  font-weight: bold;
 
78
  font-size: 1.1em;
 
79
}
 
80
span#email {
 
81
}
 
82
span#revision {
 
83
  font-family: sans-serif;
 
84
}
 
85
 
 
86
div#footer {
 
87
  font-family: sans-serif;
 
88
  font-size: small;
 
89
  border-top: 2px solid silver;
 
90
  padding-top: 0.5em;
 
91
  margin-top: 4.0em;
 
92
}
 
93
div#footer-text {
 
94
  float: left;
 
95
  padding-bottom: 0.5em;
 
96
}
 
97
div#footer-badges {
 
98
  float: right;
 
99
  padding-bottom: 0.5em;
 
100
}
 
101
 
 
102
div#preamble,
 
103
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
 
104
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
 
105
div.admonitionblock {
 
106
  margin-right: 10%;
 
107
  margin-top: 1.5em;
 
108
  margin-bottom: 1.5em;
 
109
}
 
110
div.admonitionblock {
 
111
  margin-top: 2.5em;
 
112
  margin-bottom: 2.5em;
 
113
}
 
114
 
 
115
div.content { /* Block element content. */
 
116
  padding: 0;
 
117
}
 
118
 
 
119
/* Block element titles. */
 
120
div.title, caption.title {
 
121
  font-family: sans-serif;
 
122
  font-weight: bold;
 
123
  text-align: left;
 
124
  margin-top: 1.0em;
 
125
  margin-bottom: 0.5em;
 
126
}
 
127
div.title + * {
 
128
  margin-top: 0;
 
129
}
 
130
 
 
131
td div.title:first-child {
 
132
  margin-top: 0.0em;
 
133
}
 
134
div.content div.title:first-child {
 
135
  margin-top: 0.0em;
 
136
}
 
137
div.content + div.title {
 
138
  margin-top: 0.0em;
 
139
}
 
140
 
 
141
div.sidebarblock > div.content {
 
142
  background: #ffffee;
 
143
  border: 1px solid silver;
 
144
  padding: 0.5em;
 
145
}
 
146
 
 
147
div.listingblock {
 
148
  margin-right: 0%;
 
149
}
 
150
div.listingblock > div.content {
 
151
  border: 1px solid silver;
 
152
  background: #f4f4f4;
 
153
  padding: 0.5em;
 
154
}
 
155
 
 
156
div.quoteblock > div.content {
 
157
  padding-left: 2.0em;
 
158
}
 
159
 
 
160
div.attribution {
 
161
  text-align: right;
 
162
}
 
163
div.verseblock + div.attribution {
 
164
  text-align: left;
 
165
}
 
166
 
 
167
div.admonitionblock .icon {
 
168
  vertical-align: top;
 
169
  font-size: 1.1em;
 
170
  font-weight: bold;
 
171
  text-decoration: underline;
 
172
  color: #527bbd;
 
173
  padding-right: 0.5em;
 
174
}
 
175
div.admonitionblock td.content {
 
176
  padding-left: 0.5em;
 
177
  border-left: 2px solid silver;
 
178
}
 
179
 
 
180
div.exampleblock > div.content {
 
181
  border-left: 2px solid silver;
 
182
  padding: 0.5em;
 
183
}
 
184
 
 
185
div.verseblock div.content {
 
186
  white-space: pre;
 
187
}
 
188
 
 
189
div.imageblock div.content { padding-left: 0; }
 
190
div.imageblock img { border: 1px solid silver; }
 
191
span.image img { border-style: none; }
 
192
 
 
193
dl {
 
194
  margin-top: 0.8em;
 
195
  margin-bottom: 0.8em;
 
196
}
 
197
dt {
 
198
  margin-top: 0.5em;
 
199
  margin-bottom: 0;
 
200
  font-style: italic;
 
201
}
 
202
dd > *:first-child {
 
203
  margin-top: 0;
 
204
}
 
205
 
 
206
ul, ol {
 
207
    list-style-position: outside;
 
208
}
 
209
ol.olist2 {
 
210
  list-style-type: lower-alpha;
 
211
}
 
212
 
 
213
div.tableblock > table {
 
214
  border: 3px solid #527bbd;
 
215
}
 
216
thead {
 
217
  font-family: sans-serif;
 
218
  font-weight: bold;
 
219
}
 
220
tfoot {
 
221
  font-weight: bold;
 
222
}
 
223
 
 
224
div.hlist {
 
225
  margin-top: 0.8em;
 
226
  margin-bottom: 0.8em;
 
227
}
 
228
div.hlist td {
 
229
  padding-bottom: 5px;
 
230
}
 
231
td.hlist1 {
 
232
  vertical-align: top;
 
233
  font-style: italic;
 
234
  padding-right: 0.8em;
 
235
}
 
236
td.hlist2 {
 
237
  vertical-align: top;
 
238
}
 
239
 
 
240
@media print {
 
241
  div#footer-badges { display: none; }
 
242
}
 
243
 
 
244
div#toctitle {
 
245
  color: #527bbd;
 
246
  font-family: sans-serif;
 
247
  font-size: 1.1em;
 
248
  font-weight: bold;
 
249
  margin-top: 1.0em;
 
250
  margin-bottom: 0.1em;
 
251
}
 
252
 
 
253
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
 
254
  margin-top: 0;
 
255
  margin-bottom: 0;
 
256
}
 
257
div.toclevel2 {
 
258
  margin-left: 2em;
 
259
  font-size: 0.9em;
 
260
}
 
261
div.toclevel3 {
 
262
  margin-left: 4em;
 
263
  font-size: 0.9em;
 
264
}
 
265
div.toclevel4 {
 
266
  margin-left: 6em;
 
267
  font-size: 0.9em;
 
268
}
 
269
/* Workarounds for IE6's broken and incomplete CSS2. */
 
270
 
 
271
div.sidebar-content {
 
272
  background: #ffffee;
 
273
  border: 1px solid silver;
 
274
  padding: 0.5em;
 
275
}
 
276
div.sidebar-title, div.image-title {
 
277
  font-family: sans-serif;
 
278
  font-weight: bold;
 
279
  margin-top: 0.0em;
 
280
  margin-bottom: 0.5em;
 
281
}
 
282
 
 
283
div.listingblock div.content {
 
284
  border: 1px solid silver;
 
285
  background: #f4f4f4;
 
286
  padding: 0.5em;
 
287
}
 
288
 
 
289
div.quoteblock-content {
 
290
  padding-left: 2.0em;
 
291
}
 
292
 
 
293
div.exampleblock-content {
 
294
  border-left: 2px solid silver;
 
295
  padding-left: 0.5em;
 
296
}
 
297
 
 
298
/* IE6 sets dynamically generated links as visited. */
 
299
div#toc a:visited { color: blue; }
 
300
</style>
 
301
<title>Multibyte character processing in SigScheme</title>
 
302
</head>
 
303
<body>
 
304
<div id="header">
 
305
<h1>Multibyte character processing in SigScheme</h1>
 
306
</div>
 
307
<h2>1. Overview</h2>
 
308
<div class="sectionbody">
 
309
<p>SigScheme's multibyte character handling interface is basically based on R6RS
 
310
Unicode character handlings. See also "R6RS conformance" section and
 
311
"Characters" subsection of "R5RS conformance" of <a href="spec.html">Specifications
 
312
of SigScheme</a>.</p>
 
313
<p>In addition to R6RS Unicode character handlings, SigScheme supports EUC-JP,
 
314
EUC-CN, EUC-KR and Shift_JIS character encoding schemes and they can be used
 
315
simultaneously. But no character encoding conversion method such as iconv is
 
316
provided at now.</p>
 
317
</div>
 
318
<h2>2. Current character codec</h2>
 
319
<div class="sectionbody">
 
320
<p>On SigScheme, characters and strings are processed in accordance with the
 
321
parameter <strong>current character codec</strong>. Its initial value is specified by
 
322
<tt>&#8212;enable-default-encoding</tt> option of the configure script and defaults to
 
323
UTF-8. So characters and strings in SigScheme are treated as UTF-8 by default.</p>
 
324
<p>The value of current character codec can be checked by <tt>%%current-char-codec</tt>
 
325
procedure of SigScheme extension.</p>
 
326
<div class="listingblock">
 
327
<div class="content">
 
328
<pre><tt>sscm&gt; (require-extension (sscm-ext))
 
329
sscm&gt; (%%current-char-codec)
 
330
"UTF-8"</tt></pre>
 
331
</div></div>
 
332
<p>To specify another encoding as default character codec, pass <tt>-C</tt> option to
 
333
<tt>sscm</tt> command as follows, or specify it in the second argument of
 
334
<tt>scm_initialize()</tt>.</p>
 
335
<div class="listingblock">
 
336
<div class="content">
 
337
<pre><tt>$ sscm -C ISO-8859-1
 
338
$ sscm -C UTF-8
 
339
$ sscm -C EUC-JP
 
340
$ sscm -C EUC-CN
 
341
$ sscm -C EUC-KR
 
342
$ sscm -C Shift_JIS</tt></pre>
 
343
</div></div>
 
344
<p><tt>provided?</tt> predicate can be used to know whether an encoding is enabled by the
 
345
configuration or not.</p>
 
346
<div class="listingblock">
 
347
<div class="content">
 
348
<pre><tt>(provided? "utf8")
 
349
(provided? "eucjp")
 
350
(provided? "euccn")
 
351
(provided? "euckr")
 
352
(provided? "sjis")</tt></pre>
 
353
</div></div>
 
354
<p>The <tt>ISO-8859-1</tt> encoding is used as generic singlebyte character encoding and
 
355
accepts any character represented in integer range 0-255, and always provided
 
356
regardless of configuration.</p>
 
357
<p>Use <tt>with-char-codec</tt> procedure to switch to another encoding temporarily.</p>
 
358
<div class="listingblock">
 
359
<div class="content">
 
360
<pre><tt>(define euc-A (with-char-codec "EUC-JP" (lambda () (integer-&gt;char #xa4a2))))</tt></pre>
 
361
</div></div>
 
362
<p>See also "Ports" section of this document for current character codec switching
 
363
on I/O.</p>
 
364
</div>
 
365
<h2>3. Characters</h2>
 
366
<div class="sectionbody">
 
367
<p>When the reader is working on an UTF-8 port:</p>
 
368
<div class="listingblock">
 
369
<div class="content">
 
370
<pre><tt>#\あ     ==&gt; #\あ  ;; U+3042 HIRAGANA LETTER A
 
371
#\x3042  ==&gt; #\あ  ;; U+3042 HIRAGANA LETTER A</tt></pre>
 
372
</div></div>
 
373
<p>Conversion between character and integer is performed based on the value of
 
374
<tt>%%current-char-codec</tt>. When <tt>%%current-char-codec</tt> is "UTF-8", integer value
 
375
of an Unicode character corresponds to the Unicode code point.</p>
 
376
<p>When <tt>%%current-char-codec</tt> is "UTF-8":</p>
 
377
<div class="listingblock">
 
378
<div class="content">
 
379
<pre><tt>(integer-&gt;char #x3042)  ==&gt; #\あ   ;; U+3042 HIRAGANA LETTER A
 
380
(char-&gt;integer #\あ)    ==&gt; 12354  ;; #x3042</tt></pre>
 
381
</div></div>
 
382
<p>If an integer value is invalid for the current codec, an error is caused.</p>
 
383
<div class="listingblock">
 
384
<div class="content">
 
385
<pre><tt>(with-char-codec "UTF-8"      (lambda () (integer-&gt;char #x3042)))  ==&gt; #\あ
 
386
(with-char-codec "ISO-8859-1" (lambda () (integer-&gt;char #x3042)))  ==&gt; error</tt></pre>
 
387
</div></div>
 
388
<p>Since a character in SigScheme is internally represented as an integer value
 
389
marked with character-object tag without any character encoding information,
 
390
user is responsible to manage the character encoding scheme of each character
 
391
object.</p>
 
392
<p>And no character encoding conversion is performed on integer&lt;-&gt;char conversion
 
393
regaradless of <tt>%%current-char-codec</tt>.</p>
 
394
<div class="listingblock">
 
395
<div class="content">
 
396
<pre><tt>;; U+3042 HIRAGANA LETTER A in Unicode
 
397
(define ucs-A    (with-char-codec "UTF-8"  (lambda () (integer-&gt;char #x3042))))
 
398
 
 
399
;; HIRAGANA LETTER A in EUC-JP
 
400
(define eucjp-A  (with-char-codec "EUC-JP" (lambda () (integer-&gt;char #xa4a2))))
 
401
 
 
402
(eqv? ucs-A eucjp-A)  ==&gt; #f
 
403
 
 
404
;; no conversion is performed
 
405
(with-char-codec "UTF-8"
 
406
  (lambda () (char-&gt;integer eucjp-A)))  ==&gt; 42146  ;; U+A4A2 YI RADICAL ZUP</tt></pre>
 
407
</div></div>
 
408
</div>
 
409
<h2>4. Strings</h2>
 
410
<div class="sectionbody">
 
411
<p>When both reader's port and <tt>%%current-char-codec</tt> is UTF-8:</p>
 
412
<div class="listingblock">
 
413
<div class="content">
 
414
<pre><tt>"\x3042;a\x3044;"        ==&gt; "あaい"
 
415
(string-&gt;list "あaい")   ==&gt; (#\あ #\a #\い)
 
416
(string-length "あaい")  ==&gt; 3</tt></pre>
 
417
</div></div>
 
418
<p>A string in SigScheme is internally represented as a C string with its logical
 
419
character length without character encoding information. User is responsible to
 
420
manage the character encoding scheme of each string object. Though strings have
 
421
no encoding information, they have logical character length counted in
 
422
<tt>%%current-char-codec</tt> on its object creation. So processing a string in
 
423
another encoding such as UTF-8 string as byte string cannot fully be performed.</p>
 
424
<div class="listingblock">
 
425
<div class="content">
 
426
<pre><tt>;; U+3042 HIRAGANA LETTER A, with string length 1 counted in UTF-8
 
427
(define utf8-A "あ")
 
428
 
 
429
;; string length is not re-counted even if %%current-char-codec is changed
 
430
(with-char-codec "UTF-8"      (lambda () (string-length utf8-A)))  ==&gt; 1
 
431
(with-char-codec "ISO-8859-1" (lambda () (string-length utf8-A)))  ==&gt; 1
 
432
 
 
433
;; character reference of string is based on %%current-char-codec
 
434
(with-char-codec "UTF-8"      (lambda () (string-ref utf8-A 0)))  ==&gt; #\あ
 
435
(with-char-codec "ISO-8859-1" (lambda () (string-ref utf8-A 0)))  ==&gt; #\ã
 
436
 
 
437
;; character reference that exceeds logical length is an error even if its
 
438
;; physical length is enough
 
439
(with-char-codec "UTF-8"      (lambda () (string-ref utf8-A 1)))  ==&gt; error
 
440
(with-char-codec "ISO-8859-1" (lambda () (string-ref utf8-A 1)))  ==&gt; error</tt></pre>
 
441
</div></div>
 
442
</div>
 
443
<h2>5. Identifiers</h2>
 
444
<div class="sectionbody">
 
445
<p>Any Unicode characters can be used as identifiers in Scheme as R6RS allows.</p>
 
446
<div class="listingblock">
 
447
<div class="content">
 
448
<pre><tt>'Français-symbole
 
449
'日本語シンボル
 
450
(define ひらがな-&gt;カタカナ (lambda (イ . ロ) ...))</tt></pre>
 
451
</div></div>
 
452
<p>But since SigScheme's Unicode handling is incomplete, all non-ASCII Unicode
 
453
characters are treated as ordinary letter. Though it allows using any
 
454
whitespace characters and punctuations as identifier, it should not be done.</p>
 
455
<p>Non-ASCII identifier in SigScheme is only allowed for Unicode. In other words,
 
456
allowed only if the reading port is UTF-8. This limitation is intended to avoid
 
457
character identity problem between different character encodings. For example,
 
458
WAVE DASH and FULLWIDTH TILDE may be altered to another unexpectedly if the
 
459
source code is converted to/from non-Unicode Japanese encoding. Inhibiting
 
460
non-Unicode identifiers is the simplest way to avoid such problems.</p>
 
461
<p>To use Unicode identifiers, prepend following line to the source code. See also
 
462
"Ports" section to understand its mechanism.</p>
 
463
<div class="listingblock">
 
464
<div class="content">
 
465
<pre><tt># /usr/bin/env sscm -C UTF-8</tt></pre>
 
466
</div></div>
 
467
</div>
 
468
<h2>6. Ports</h2>
 
469
<div class="sectionbody">
 
470
<ul>
 
471
<li>
 
472
<p>
 
473
Each port is associated with a single character encoding when it is open
 
474
</p>
 
475
</li>
 
476
</ul>
 
477
<div class="listingblock">
 
478
<div class="content">
 
479
<pre><tt>sscm&gt; (current-input-port)
 
480
#&lt;iport mb UTF-8 file stdin&gt;</tt></pre>
 
481
</div></div>
 
482
<ul>
 
483
<li>
 
484
<p>
 
485
The encoding of a port is not switched to another once it is open (NOTE: a C extension that operates on low level port can alter it)
 
486
</p>
 
487
</li>
 
488
<li>
 
489
<p>
 
490
The encoding of a port is determined by <tt>%%current-char-codec</tt> on its opening
 
491
</p>
 
492
</li>
 
493
</ul>
 
494
<div class="listingblock">
 
495
<div class="content">
 
496
<pre><tt>$ sscm -C UTF-8
 
497
sscm&gt; (%%current-char-codec)
 
498
"UTF-8"
 
499
 
 
500
sscm&gt; (open-output-file "/tmp/sigscheme.tmp")
 
501
#&lt;oport mb UTF-8 file /tmp/sigscheme.tmp&gt;
 
502
 
 
503
sscm&gt; (with-char-codec "ISO-8859-1"
 
504
        (lambda () (open-output-file "/tmp/sigscheme.tmp")))
 
505
#&lt;oport mb ISO-8859-1 file /tmp/sigscheme.tmp&gt;</tt></pre>
 
506
</div></div>
 
507
<ul>
 
508
<li>
 
509
<p>
 
510
<tt>%%current-char-codec</tt> does not affect already open ports
 
511
</p>
 
512
</li>
 
513
</ul>
 
514
<div class="listingblock">
 
515
<div class="content">
 
516
<pre><tt>sscm&gt; (current-input-port)
 
517
#&lt;iport mb UTF-8 file stdin&gt;
 
518
 
 
519
sscm&gt; (with-char-codec "ISO-8859-1"
 
520
        (lambda ()
 
521
          (list (%%current-char-codec) (current-input-port))))
 
522
("ISO-8859-1" #&lt;iport mb UTF-8 file stdin&gt;)</tt></pre>
 
523
</div></div>
 
524
<ul>
 
525
<li>
 
526
<p>
 
527
Characters output to a port is encoded to a byte stream according to the port's own character encoding regardless of <tt>%%current-char-codec</tt> value
 
528
</p>
 
529
</li>
 
530
</ul>
 
531
<div class="listingblock">
 
532
<div class="content">
 
533
<pre><tt>$ sscm -C ISO-8859-1
 
534
sscm&gt; (current-output-port)
 
535
#&lt;oport mb ISO-8859-1 file stdout&gt;
 
536
 
 
537
sscm&gt; (with-char-codec "UTF-8" (lambda () (write #\x3042)))
 
538
Error: ScmMultibyteCharPort: invalid character</tt></pre>
 
539
</div></div>
 
540
<p>To specify per-file character encoding, prepend following line into the
 
541
file. The <tt>load</tt> procedure detects this line and temporarily switches
 
542
<tt>%%current-char-codec</tt> and the encoding of the reading port until read all
 
543
expressions from the file.</p>
 
544
<div class="listingblock">
 
545
<div class="content">
 
546
<pre><tt>#! /usr/bin/env sscm -C UTF-8</tt></pre>
 
547
</div></div>
 
548
</div>
 
549
<div id="footer">
 
550
<div id="footer-text">
 
551
Last updated 17-May-2008 12:45:34 JST
 
552
</div>
 
553
</div>
 
554
</body>
 
555
</html>