[macruby-changes] [3703] MacRuby/branches/icu/symbol.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 4 20:12:39 PST 2010
Revision: 3703
http://trac.macosforge.org/projects/ruby/changeset/3703
Author: lsansonetti at apple.com
Date: 2010-03-04 20:12:35 -0800 (Thu, 04 Mar 2010)
Log Message:
-----------
better symbols sanitization
Modified Paths:
--------------
MacRuby/branches/icu/symbol.c
Modified: MacRuby/branches/icu/symbol.c
===================================================================
--- MacRuby/branches/icu/symbol.c 2010-03-05 03:40:56 UTC (rev 3702)
+++ MacRuby/branches/icu/symbol.c 2010-03-05 04:12:35 UTC (rev 3703)
@@ -52,26 +52,32 @@
rb_sym_t *sym = NULL;
- const long chars_len = rb_str_chars_len(str);
+ UChar *chars = NULL;
+ long chars_len = 0;
+ bool need_free = false;
+ rb_str_get_uchars(str, &chars, &chars_len, &need_free);
+
+ long pos = 0;
if (chars_len > 0) {
- UChar c = rb_str_get_uchar(str, 0);
+ UChar c = chars[0];
switch (c) {
case '$':
id = ID_GLOBAL;
- break;
+ goto new_id;
case '@':
- if (chars_len > 1 && rb_str_get_uchar(str, 1) == '@') {
+ if (chars_len > 1 && chars[1] == '@') {
+ pos++;
id = ID_CLASS;
}
else {
id = ID_INSTANCE;
}
+ pos++;
break;
default:
- if (chars_len > 1
- && rb_str_get_uchar(str, chars_len - 1) == '=') {
+ if (chars_len > 1 && chars[chars_len - 1] == '=') {
// Attribute assignment.
id = rb_intern_str(rb_str_substr(str, 0, chars_len - 1));
if (!is_attrset_id(id)) {
@@ -90,6 +96,20 @@
}
}
+ if (pos < chars_len && !isdigit(chars[pos])) {
+ for (; pos < chars_len; pos++) {
+ UChar c = chars[pos];
+ if (isalnum(c) || c == '_' || !isascii(c)) {
+ continue;
+ }
+ break;
+ }
+ }
+ if (pos < chars_len) {
+ id = ID_JUNK;
+ }
+
+new_id:
id |= ++last_id << ID_SCOPE_SHIFT;
id_register:
@@ -98,6 +118,9 @@
CFDictionarySetValue(sym_id, (const void *)name_hash, (const void *)id);
CFDictionarySetValue(id_str, (const void *)id, (const void *)sym);
+ if (need_free) {
+ free(chars);
+ }
return id;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100304/97ba0a93/attachment.html>
More information about the macruby-changes
mailing list