icu4r 0.1.3.2006.01.26

Sign up to get free protection for your applications and to get access to all the features.
data/tools/km.rb ADDED
@@ -0,0 +1,425 @@
1
+ module RDoc
2
+ module Page
3
+
4
+
5
+ FONTS = "Arial, Helvetica, sans-serif"
6
+
7
+ STYLE = %{
8
+ body,td,p { font-family: %fonts%;
9
+ color: #000040;
10
+ }
11
+
12
+ .attr-rw { font-size: xx-small; color: #444488 }
13
+
14
+ .title-row { background-color: #00468a;
15
+ color: white;
16
+ }
17
+
18
+ .big-title-font {
19
+ color: white;
20
+ font-weight: bold;
21
+ font-family: %fonts%;
22
+ font-size: large;
23
+ height: 40px;
24
+ padding: 10px 3px 10px 3px;
25
+ }
26
+
27
+ .small-title-font { color: white;
28
+ font-family: %fonts%;
29
+ font-size:10; }
30
+
31
+ .aqua { color: black }
32
+
33
+ .method-name, .attr-name {
34
+ font-family: font-family: %fonts%;
35
+ font-weight: bold;
36
+ font-size: small;
37
+ margin-left: 20px;
38
+ color: #000033;
39
+ }
40
+
41
+ .tablesubtitle, .tablesubsubtitle {
42
+ width: 100%;
43
+ padding: 2px 0px 2px 10px;
44
+ color: black;
45
+ background-color: #CCCCCC;
46
+ border: thin;
47
+ }
48
+
49
+ .name-list {
50
+ margin-left: 5px;
51
+ margin-bottom: 2ex;
52
+ line-height: 105%;
53
+ }
54
+
55
+ .description {
56
+ margin-left: 5px;
57
+ margin-bottom: 2ex;
58
+ line-height: 105%;
59
+ font-size: small;
60
+ }
61
+
62
+ .methodtitle {
63
+ font-size: small;
64
+ font-weight: bold;
65
+ text-decoration: none;
66
+ color: #00468a;
67
+ background-color: #eeeeee;
68
+ }
69
+
70
+ .srclink {
71
+ font-size: small;
72
+ font-weight: bold;
73
+ text-decoration: none;
74
+ color: #0000DD;
75
+ background-color: white;
76
+ }
77
+
78
+ .paramsig {
79
+ font-size: small;
80
+ }
81
+
82
+ .srcbut { float: right }
83
+ a:link {color:#00468a; text-decoration:none;}
84
+ a:visited {color:#004646; text-decoration:none;}
85
+ a:hover {text-decoration:underline}
86
+ }
87
+
88
+
89
+ ############################################################################
90
+
91
+
92
+ BODY = %{
93
+ <html><head>
94
+ <title>%title%</title>
95
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
96
+ <link rel=StyleSheet href="%style_url%" type="text/css" media=screen>
97
+ <script type="text/javascript" language="JavaScript">
98
+ <!--
99
+ function popCode(url) {
100
+ parent.frames.source.location = url
101
+ }
102
+ //-->
103
+ </script>
104
+ </head>
105
+ <body bgcolor="white">
106
+
107
+ !INCLUDE! <!-- banner header -->
108
+
109
+ IF:diagram
110
+ <table width="100%"><tr><td align="center">
111
+ %diagram%
112
+ </td></tr></table>
113
+ ENDIF:diagram
114
+
115
+ IF:description
116
+ <div class="description">%description%</div>
117
+ ENDIF:description
118
+
119
+ IF:requires
120
+ <table cellpadding=5 width="100%">
121
+ <tr><td class="tablesubtitle">Required files</td></tr>
122
+ </table><br>
123
+ <div class="name-list">
124
+ START:requires
125
+ HREF:aref:name:
126
+ END:requires
127
+ ENDIF:requires
128
+ </div>
129
+
130
+ IF:methods
131
+ <table cellpadding=5 width="100%">
132
+ <tr><td class="tablesubtitle">All Methods</td></tr>
133
+ </table><br>
134
+ <div class="name-list">
135
+ START:methods
136
+ HREF:aref:name:,
137
+ END:methods
138
+ </div>
139
+ ENDIF:methods
140
+
141
+
142
+ START:sections
143
+ <div id="section">
144
+ IF:sectitle
145
+ <h2 class="section-title"><a name="%secsequence%">%sectitle%</a></h2>
146
+ IF:seccomment
147
+ <div class="section-comment">
148
+ %seccomment%
149
+ </div>
150
+ ENDIF:seccomment
151
+ ENDIF:sectitle
152
+
153
+ IF:attributes
154
+ <table cellpadding=5 width="100%">
155
+ <tr><td class="tablesubtitle">Attributes</td></tr>
156
+ </table><br>
157
+ <table cellspacing=5>
158
+ START:attributes
159
+ <tr valign="top">
160
+ IF:rw
161
+ <td align="center" class="attr-rw">&nbsp;[%rw%]&nbsp;</td>
162
+ ENDIF:rw
163
+ IFNOT:rw
164
+ <td></td>
165
+ ENDIF:rw
166
+ <td class="attr-name">%name%</td>
167
+ <td>%a_desc%</td>
168
+ </tr>
169
+ END:attributes
170
+ </table>
171
+ ENDIF:attributes
172
+
173
+ IF:classlist
174
+ <table cellpadding=5 width="100%">
175
+ <tr><td class="tablesubtitle">Classes and Modules</td></tr>
176
+ </table><br>
177
+ %classlist%<br>
178
+ ENDIF:classlist
179
+
180
+ !INCLUDE! <!-- method descriptions -->
181
+
182
+ END:sections
183
+
184
+ </body>
185
+ </html>
186
+ }
187
+
188
+ ###############################################################################
189
+
190
+ FILE_PAGE = <<_FILE_PAGE_
191
+ <table width="100%">
192
+ <tr class="title-row">
193
+ <td><table width="100%"><tr>
194
+ <td class="big-title-font" colspan=2><font size=-3><B>File</B><BR></font>%short_name%</td>
195
+ <td align="right"><table cellspacing=0 cellpadding=2>
196
+ <tr>
197
+ <td class="small-title-font">Path:</td>
198
+ <td class="small-title-font">%full_path%
199
+ IF:cvsurl
200
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
201
+ ENDIF:cvsurl
202
+ </td>
203
+ </tr>
204
+ <tr>
205
+ <td class="small-title-font">Modified:</td>
206
+ <td class="small-title-font">%dtm_modified%</td>
207
+ </tr>
208
+ </table>
209
+ </td></tr></table></td>
210
+ </tr>
211
+ </table><br>
212
+ _FILE_PAGE_
213
+
214
+ ###################################################################
215
+
216
+ CLASS_PAGE = %{
217
+ <table width="100%" border=0 cellspacing=0>
218
+ <tr class="title-row">
219
+ <td class="big-title-font">
220
+ <font size=-3><B>%classmod%</B><BR></font>%full_name%
221
+ </td>
222
+ <td align="right">
223
+ <table cellspacing=0 cellpadding=2>
224
+ <tr valign="top">
225
+ <td class="small-title-font">In:</td>
226
+ <td class="small-title-font">
227
+ START:infiles
228
+ HREF:full_path_url:full_path:
229
+ IF:cvsurl
230
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
231
+ ENDIF:cvsurl
232
+ END:infiles
233
+ </td>
234
+ </tr>
235
+ IF:parent
236
+ <tr>
237
+ <td class="small-title-font">Parent:</td>
238
+ <td class="small-title-font">
239
+ IF:par_url
240
+ <a href="%par_url%" class="cyan">
241
+ ENDIF:par_url
242
+ %parent%
243
+ IF:par_url
244
+ </a>
245
+ ENDIF:par_url
246
+ </td>
247
+ </tr>
248
+ ENDIF:parent
249
+ </table>
250
+ </td>
251
+ </tr>
252
+ </table><br>
253
+ }
254
+
255
+ ###################################################################
256
+
257
+ METHOD_LIST = %{
258
+ IF:includes
259
+ <div class="tablesubsubtitle">Included modules</div><br>
260
+ <div class="name-list">
261
+ START:includes
262
+ <span class="method-name">HREF:aref:name:</span>
263
+ END:includes
264
+ </div>
265
+ ENDIF:includes
266
+
267
+ IF:method_list
268
+ START:method_list
269
+ IF:methods
270
+ <table cellpadding=5 width="100%">
271
+ <tr><td class="tablesubtitle">%type% %category% methods</td></tr>
272
+ </table>
273
+ START:methods
274
+ <table width="100%" cellspacing = 0 cellpadding=5 border=0>
275
+ <tr><td class="methodtitle">
276
+ <a name="%aref%">
277
+ IF:callseq
278
+ <b>%callseq%</b>
279
+ ENDIF:callseq
280
+ IFNOT:callseq
281
+ <b>%name%</b>%params%
282
+ ENDIF:callseq
283
+ </a></td></tr>
284
+ </table>
285
+ IF:m_desc
286
+ <div class="description">
287
+ %m_desc%
288
+ </div>
289
+ ENDIF:m_desc
290
+ IF:aka
291
+ <div class="aka">
292
+ This method is also aliased as
293
+ START:aka
294
+ <a href="%aref%">%name%</a>
295
+ END:aka
296
+ </div>
297
+ ENDIF:aka
298
+ IF:sourcecode
299
+ <pre class="source">
300
+ %sourcecode%
301
+ </pre>
302
+ ENDIF:sourcecode
303
+ END:methods
304
+ ENDIF:methods
305
+ END:method_list
306
+ ENDIF:method_list
307
+ }
308
+
309
+ =begin
310
+ =end
311
+
312
+ ########################## Source code ##########################
313
+
314
+ SRC_PAGE = %{
315
+ <html>
316
+ <head><title>%title%</title>
317
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
318
+ <style>
319
+ .ruby-comment { color: green; font-style: italic }
320
+ .ruby-constant { color: #4433aa; font-weight: bold; }
321
+ .ruby-identifier { color: #222222; }
322
+ .ruby-ivar { color: #2233dd; }
323
+ .ruby-keyword { color: #3333FF; font-weight: bold }
324
+ .ruby-node { color: #777777; }
325
+ .ruby-operator { color: #111111; }
326
+ .ruby-regexp { color: #662222; }
327
+ .ruby-value { color: #662222; font-style: italic }
328
+ .kw { color: #3333FF; font-weight: bold }
329
+ .cmt { color: green; font-style: italic }
330
+ .str { color: #662222; font-style: italic }
331
+ .re { color: #662222; }
332
+ </style>
333
+ </head>
334
+ <body bgcolor="white">
335
+ <pre>%code%</pre>
336
+ </body>
337
+ </html>
338
+ }
339
+
340
+ ########################## Index ################################
341
+
342
+ FR_INDEX_BODY = %{
343
+ !INCLUDE!
344
+ }
345
+
346
+ FILE_INDEX = %{
347
+ <html>
348
+ <head>
349
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
350
+ <style>
351
+ <!--
352
+ body {
353
+ font-family: #{FONTS};
354
+ font-size: 11px;
355
+ font-style: normal;
356
+ line-height: 14px;
357
+ color: #000040;
358
+ }
359
+ div.banner {
360
+ background: #0000aa;
361
+ color: white;
362
+ padding: 1;
363
+ margin: 0;
364
+ font-size: 90%;
365
+ font-weight: bold;
366
+ line-height: 1.1;
367
+ text-align: center;
368
+ width: 100%;
369
+ }
370
+ a:link {color:#00468a; text-decoration:none;}
371
+ a:visited {color:#004646; text-decoration:none;}
372
+ a:hover {text-decoration:underline}
373
+
374
+ -->
375
+ </style>
376
+ <base target="docwin">
377
+ </head>
378
+ <body>
379
+ <div class="banner">%list_title%</div>
380
+ START:entries
381
+ <a href="%href%">%name%</a><br>
382
+ END:entries
383
+ </body></html>
384
+ }
385
+
386
+ CLASS_INDEX = FILE_INDEX
387
+ METHOD_INDEX = FILE_INDEX
388
+
389
+ INDEX = %{
390
+ <html>
391
+ <head>
392
+ <title>%title%</title>
393
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
394
+ </head>
395
+
396
+ <frameset cols="20%,*">
397
+ <frameset rows="15%,35%,50%">
398
+ <frame src="fr_file_index.html" title="Files" name="Files">
399
+ <frame src="fr_class_index.html" name="Classes">
400
+ <frame src="fr_method_index.html" name="Methods">
401
+ </frameset>
402
+ <frame src="%initial_page%" name="docwin">
403
+ <noframes>
404
+ <body bgcolor="white">
405
+ Click <a href="html/index.html">here</a> for a non-frames
406
+ version of this page.
407
+ </body>
408
+ </noframes>
409
+ </frameset>
410
+
411
+ </html>
412
+ }
413
+
414
+ # and a blank page to use as a target
415
+ BLANK = %{
416
+ <html><body bgcolor="white"></body></html>
417
+ }
418
+
419
+ def write_extra_pages
420
+ template = TemplatePage.new(BLANK)
421
+ File.open("blank.html", "w") { |f| template.write_html_on(f, {}) }
422
+ end
423
+
424
+ end
425
+ end
data/ubundle.c ADDED
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Document-class: UResourceBundle
3
+ *
4
+ * Resource Bundle -- a collection of resource information pertaining to a given locale.
5
+ * A resource bundle provides a way of accessing locale-specific information in a data
6
+ * file. You create a resource bundle that manages the resources for a given locale and
7
+ * then ask it for individual resources.
8
+ *
9
+ * Resource bundles can contain two main types of resources: complex and simple resources.
10
+ * Complex resources store other resources and can have named or unnamed elements.
11
+ * Tables store named elements, while arrays store unnamed ones.
12
+ * Simple resources contain data which can be string, binary, integer array or a single integer.
13
+ *
14
+ * Current ICU4R API allows only access for top-level resources by key. Found resource value is
15
+ * translated into appropriate ruby value or structure (such as array or hash).
16
+ *
17
+ * See [http://icu.sourceforge.net/userguide/ResourceManagement.html] for additional info
18
+ * about ICU resource management.
19
+ */
20
+ #include "icu_common.h"
21
+ extern VALUE icu_ustr_new(const UChar * ptr, long len);
22
+ extern VALUE rb_cUResourceBundle;
23
+
24
+ /* --- resource bundle methods */
25
+ VALUE icu_bundle_read(UResourceBundle * r)
26
+ {
27
+ VALUE value;
28
+ UResourceBundle * temp;
29
+ UResType res_type = ures_getType(r);
30
+ const UChar * u_buf;
31
+ int32_t len, int_val, i, n;
32
+ const int32_t *int_ar;
33
+ const char * buf, *key;
34
+ UErrorCode status = U_ZERO_ERROR;
35
+
36
+ switch(res_type) {
37
+ case URES_STRING:
38
+ u_buf = ures_getString (r, &len, &status);
39
+ value = icu_ustr_new(u_buf, len);
40
+ break;
41
+
42
+ case URES_INT:
43
+ int_val = ures_getInt (r, &status);
44
+ value = INT2FIX(int_val);
45
+ break;
46
+
47
+ case URES_INT_VECTOR:
48
+ int_ar = ures_getIntVector (r, &len, &status);
49
+ n = ures_getSize( r );
50
+ value = rb_ary_new2(len);
51
+ for( i = 0; i < len ; i++) {
52
+ int_val = int_ar[i];
53
+ rb_ary_store(value, i, INT2FIX(int_val));
54
+ }
55
+ break;
56
+
57
+ case URES_BINARY:
58
+ buf = ures_getBinary(r, &len, &status);
59
+ value = rb_str_new( buf, len);
60
+ break;
61
+
62
+ case URES_TABLE:
63
+ ures_resetIterator(r );
64
+ value = rb_hash_new();
65
+ while(ures_hasNext(r) ){
66
+ temp = ures_getNextResource(r, NULL, &status);
67
+ key = ures_getKey(temp);
68
+ rb_hash_aset(value, rb_str_new2(key), icu_bundle_read(temp));
69
+ ures_close(temp);
70
+ }
71
+ break;
72
+ case URES_ARRAY:
73
+ n = ures_getSize(r);
74
+ value = rb_ary_new2(n);
75
+ for(i =0 ; i < n; i++) {
76
+ temp = ures_getByIndex(r, i, NULL, &status);
77
+ rb_ary_store(value, i, icu_bundle_read(temp));
78
+ }
79
+ break;
80
+
81
+ case URES_NONE:
82
+ default:
83
+ value = Qnil; break;
84
+
85
+ }
86
+ return value;
87
+ }
88
+
89
+ void icu_free_bundle(UResourceBundle * res) {
90
+ ures_close(res);
91
+ }
92
+
93
+ /**
94
+ * call-seq:
95
+ * UResourceBundle.open(package_name, locale)
96
+ *
97
+ * Opens a UResourceBundle, from which users can extract strings by using their corresponding keys.
98
+ *
99
+ * Typically, +package_name+ will refer to a (.dat) file by full file or directory pathname.
100
+ * If +nil+, ICU data will be used.
101
+ *
102
+ * +locale+ specifies the locale for which we want to open the resource.
103
+ * if +nil+, the default locale will be used. If locale == "" root locale will be used.
104
+ *
105
+ * bundle = UResourceBundle.open(File.expand_path("appmsg"), "en")
106
+ *
107
+ */
108
+ VALUE icu_bundle_open(klass, package, locale)
109
+ VALUE klass, package, locale;
110
+ {
111
+
112
+ UErrorCode status = U_ZERO_ERROR;
113
+ UResourceBundle * r;
114
+
115
+ if( package != Qnil ) Check_Type(package, T_STRING);
116
+ if( locale != Qnil ) Check_Type(locale, T_STRING);
117
+
118
+ r = ures_open (package == Qnil ? NULL : RSTRING(package)->ptr,
119
+ locale == Qnil ? NULL : RSTRING(locale)->ptr, &status);
120
+
121
+ if (U_FAILURE(status) ) rb_raise(rb_eRuntimeError, u_errorName(status));
122
+ return Data_Wrap_Struct(klass, 0, icu_free_bundle, r);
123
+ }
124
+
125
+ /**
126
+ * call-seq:
127
+ * UResourceBundle.open_direct(package_name, locale)
128
+ *
129
+ * This function does not care what kind of localeID is passed in.
130
+ * It simply opens a bundle with that name. Fallback mechanism is disabled for the new bundle.
131
+ *
132
+ * currency = UResourceBundle.open_direct(nil, 'CurrencyData') # open ICU currency data :)
133
+ * currency["CurrencyMap"]["GB"] # => GBP
134
+ */
135
+ VALUE icu_bundle_open_direct(klass, package, locale)
136
+ VALUE klass, package, locale;
137
+ {
138
+
139
+ UErrorCode status = U_ZERO_ERROR;
140
+ UResourceBundle * r;
141
+
142
+ if( package != Qnil ) Check_Type(package, T_STRING);
143
+ if( locale != Qnil ) Check_Type(locale, T_STRING);
144
+
145
+ r = ures_openDirect (package == Qnil ? NULL : RSTRING(package)->ptr,
146
+ locale == Qnil ? NULL : RSTRING(locale)->ptr, &status);
147
+
148
+ if (U_FAILURE(status) ) rb_raise(rb_eRuntimeError, u_errorName(status));
149
+ return Data_Wrap_Struct(klass, 0, icu_free_bundle, r);
150
+ }
151
+ /**
152
+ * call-seq:
153
+ * bundle[key] => object or nil
154
+ *
155
+ * Returns a resource in a given bundle that has a given key or +nil+ if not found.
156
+ *
157
+ * Type of returned object depends on ICU type of found resource:
158
+ * ICU restype description: returned value
159
+ * ------------------------------------------------------------------------------
160
+ * URES_STRING 16-bit Unicode strings. UString
161
+ *
162
+ * URES_BINARY binary data. String
163
+ *
164
+ * URES_TABLE tables of key-value pairs. Hash
165
+ *
166
+ * URES_INT a single 28-bit integer. Fixnum
167
+ *
168
+ * URES_ARRAY arrays of resources. Array
169
+ *
170
+ * URES_INT_VECTOR vectors of 32-bit integers. Array of fixnums
171
+ *
172
+ */
173
+ VALUE icu_bundle_aref( bundle, key)
174
+ VALUE bundle, key;
175
+ {
176
+ UErrorCode status = U_ZERO_ERROR;
177
+ UResourceBundle * res , * orig;
178
+ VALUE out;
179
+
180
+ Check_Type(key, T_STRING);
181
+ orig = (UResourceBundle*)DATA_PTR(bundle);
182
+
183
+ res = ures_getByKey(orig, RSTRING(key)->ptr, NULL, &status);
184
+ if( U_FAILURE(status)) {
185
+ if( status == U_MISSING_RESOURCE_ERROR) return Qnil;
186
+ rb_raise(rb_eArgError, u_errorName(status));
187
+ }
188
+ out = icu_bundle_read(res);
189
+ ures_close(res);
190
+ return out;
191
+ }
192
+ /*
193
+ * call-seq:
194
+ * bundle.clone
195
+ *
196
+ * Always throws an exception. Just a paranoia.
197
+ */
198
+ VALUE icu_bundle_clone( bundle)
199
+ VALUE bundle;
200
+ {
201
+ rb_raise(rb_eRuntimeError, "UResourceBundle can't be cloned!");
202
+ }
203
+ void initialize_ubundle(void) {
204
+ rb_cUResourceBundle = rb_define_class("UResourceBundle", rb_cObject);
205
+ rb_define_method(rb_cUResourceBundle, "[]", icu_bundle_aref, 1);
206
+ rb_define_method(rb_cUResourceBundle, "clone", icu_bundle_clone, 0);
207
+ rb_define_singleton_method(rb_cUResourceBundle, "open", icu_bundle_open, 2);
208
+ rb_define_singleton_method(rb_cUResourceBundle, "open_direct", icu_bundle_open_direct, 2);
209
+ }