[macruby-changes] [4437] MacRuby/trunk/pack.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 19 21:22:36 PDT 2010
Revision: 4437
http://trac.macosforge.org/projects/ruby/changeset/4437
Author: watson1978 at gmail.com
Date: 2010-08-19 21:22:34 -0700 (Thu, 19 Aug 2010)
Log Message:
-----------
pack(U) should set an encoding of UTF-8.
Modified Paths:
--------------
MacRuby/trunk/pack.c
Modified: MacRuby/trunk/pack.c
===================================================================
--- MacRuby/trunk/pack.c 2010-08-20 04:07:07 UTC (rev 4436)
+++ MacRuby/trunk/pack.c 2010-08-20 04:22:34 UTC (rev 4437)
@@ -446,6 +446,7 @@
char type;
long items, len, idx, plen;
const char *ptr;
+ int enc_info = 1; /* 0 - BINARY, 1 - US-ASCII, 2 - UTF-8 */
#ifdef NATINT_PACK
int natint; /* native integer */
#endif
@@ -508,6 +509,22 @@
}
switch (type) {
+ case 'U':
+ /* if encoding is US-ASCII, upgrade to UTF-8 */
+ if (enc_info == 1) {
+ enc_info = 2;
+ }
+ break;
+ case 'm': case 'M': case 'u':
+ /* keep US-ASCII (do nothing) */
+ break;
+ default:
+ /* fall back to BINARY */
+ enc_info = 0;
+ break;
+ }
+
+ switch (type) {
case 'A': case 'a': case 'Z':
case 'B': case 'b':
case 'H': case 'h':
@@ -1026,6 +1043,20 @@
}
}
}
+
+ switch (enc_info) {
+ case 1:
+ // TODO
+ // ENCODING_CODERANGE_SET(data, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
+ break;
+ case 2:
+ rb_str_force_encoding(data, rb_encodings[ENCODING_UTF8]);
+ break;
+ default:
+ /* do nothing, keep ASCII-8BIT */
+ break;
+ }
+
return data;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100819/e1963f35/attachment.html>
More information about the macruby-changes
mailing list