Exemple #1
0
/*
* call-seq: [](name)
*
* Return the value returned by method +name+.
*/
static VALUE cState_aref(VALUE self, VALUE name)
{
    name = rb_funcall(name, i_to_s, 0);
    if (RTEST(rb_funcall(self, i_respond_to_p, 1, name))) {
        return rb_funcall(self, i_send, 1, name);
    } else {
        return rb_ivar_get(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)));
    }
}
Exemple #2
0
static VALUE
rb_yaml_resolver_add_type(VALUE self, SEL sel, VALUE key, VALUE handler)
{
    if (!NIL_P(key)) {
	rb_yaml_resolver_t *r = RYAMLResolver(self);
	CFDictionarySetValue(r->tags, (const void *)rb_intern_str(key),
		(const void *)handler);
    }
    return Qnil;
}
Exemple #3
0
/*
* call-seq: []=(name, value)
*
* Set the attribute name to value.
*/
static VALUE cState_aset(VALUE self, VALUE name, VALUE value)
{
    VALUE name_writer;

    name = rb_funcall(name, i_to_s, 0);
    name_writer = rb_str_cat2(rb_str_dup(name), "=");
    if (RTEST(rb_funcall(self, i_respond_to_p, 1, name_writer))) {
        return rb_funcall(self, i_send, 2, name_writer, value);
    } else {
        rb_ivar_set(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)), value);
    }
    return Qnil;
}
Exemple #4
0
static VALUE
sym_step_i(VALUE i, void *arg)
{
    VALUE *iter = arg;

    if (FIXNUM_P(iter[0])) {
	iter[0] -= INT2FIX(1) & ~FIXNUM_FLAG;
    }
    else {
	VALUE one = INT2FIX(1);
	iter[0] = rb_vm_call(iter[0], selMINUS,1, &one);
    }
    if (iter[0] == INT2FIX(0)) {
	rb_yield(ID2SYM(rb_intern_str(i)));
	iter[0] = iter[1];
    }
    return Qnil;
}
Exemple #5
0
void
rb_attr(VALUE klass, ID id, int read, int write, int ex)
{
    const char *name;
    ID attriv;
    VALUE aname;
    int noex;

    if (!ex) {
	noex = NOEX_PUBLIC;
    }
    else {
	if (SCOPE_TEST(NOEX_PRIVATE)) {
	    noex = NOEX_PRIVATE;
	    rb_warning((SCOPE_CHECK(NOEX_MODFUNC)) ?
		       "attribute accessor as module_function" :
		       "private attribute?");
	}
	else if (SCOPE_TEST(NOEX_PROTECTED)) {
	    noex = NOEX_PROTECTED;
	}
	else {
	    noex = NOEX_PUBLIC;
	}
    }

    if (!rb_is_local_id(id) && !rb_is_const_id(id)) {
	rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id));
    }
    name = rb_id2name(id);
    if (!name) {
	rb_raise(rb_eArgError, "argument needs to be symbol or string");
    }
    aname = rb_sprintf("@%s", name);
    rb_enc_copy(aname, rb_id2str(id));
    attriv = rb_intern_str(aname);
    if (read) {
	rb_add_method(klass, id, NEW_IVAR(attriv), noex);
    }
    if (write) {
	rb_add_method(klass, rb_id_attrset(id), NEW_ATTRSET(attriv), noex);
    }
}
Exemple #6
0
VALUE
rb_id2str(ID id)
{
    LOCK();
    VALUE sym = (VALUE)CFDictionaryGetValue(id_str, (const void *)id);
    UNLOCK();
    if (sym != 0) {
//printf("lookup %ld -> %s\n", id, rb_sym2name(sym));
	return sym;
    }

    if (is_attrset_id(id)) {
	// Attribute assignment.
	ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;

	while ((sym = rb_id2str(id2)) == 0) {
	    if (!is_local_id(id2)) {
//printf("lookup %ld -> FAIL\n", id);
		return 0;
	    }
	    id2 = (id & ~ID_SCOPE_MASK) | ID_CONST;
	}

	VALUE str = rb_str_dup(RSYM(sym)->str);
	rb_str_cat(str, "=", 1);
	rb_intern_str(str);

	// Retry one more time.
	LOCK();
	sym = (VALUE)CFDictionaryGetValue(id_str, (const void *)id);
	UNLOCK();
	if (sym != 0) {
//printf("lookup %ld -> %s\n", id, rb_sym2name(sym));
	    return sym;
	}
    }
//printf("lookup %ld -> FAIL\n", id);
    return 0;
}
Exemple #7
0
void
rb_attr(VALUE klass, ID id, int read, int write, int ex)
{
    VALUE attriv;
    VALUE aname;
    rb_method_flag_t noex;

    if (!ex) {
	noex = NOEX_PUBLIC;
    }
    else {
	if (SCOPE_TEST(NOEX_PRIVATE)) {
	    noex = NOEX_PRIVATE;
	    rb_warning((SCOPE_CHECK(NOEX_MODFUNC)) ?
		       "attribute accessor as module_function" :
		       "private attribute?");
	}
	else if (SCOPE_TEST(NOEX_PROTECTED)) {
	    noex = NOEX_PROTECTED;
	}
	else {
	    noex = NOEX_PUBLIC;
	}
    }

    aname = rb_id2str(rb_check_attr_id(id));
    if (NIL_P(aname)) {
	rb_raise(rb_eArgError, "argument needs to be symbol or string");
    }
    attriv = (VALUE)rb_intern_str(rb_sprintf("@%"PRIsVALUE, aname));
    if (read) {
	rb_add_method(klass, id, VM_METHOD_TYPE_IVAR, (void *)attriv, noex);
    }
    if (write) {
	rb_add_method(klass, rb_id_attrset(id), VM_METHOD_TYPE_ATTRSET, (void *)attriv, noex);
    }
}
Exemple #8
0
static VALUE
sym_each_i(VALUE v, void *arg)
{
    rb_yield(ID2SYM(rb_intern_str(v)));
    return Qnil;
}
Exemple #9
0
VALUE symbol_spec_rb_intern_str(VALUE self, VALUE str) {
  return ID2SYM(rb_intern_str(str));
}
Exemple #10
0
static VALUE
rsym_imp_initWithCoder(void *rcv, SEL sel, void *coder)
{
    return ID2SYM(rb_intern_str(rb_str_NSCoder_decode(coder, RSYM_NSCODER_KEY)));
}
Exemple #11
0
static VALUE
rsym_swapcase(VALUE sym, SEL sel)
{
    return ID2SYM(rb_intern_str(rstr_swapcase(RSYM(sym)->str, sel)));
}
Exemple #12
0
static VALUE
rsym_capitalize(VALUE sym, SEL sel)
{
    return ID2SYM(rb_intern_str(rstr_capitalize(RSYM(sym)->str, sel)));
}
Exemple #13
0
static ID
rb_intern_uchars(const UChar *chars, const size_t chars_len, VALUE str)
{
    const unsigned long name_hash = rb_str_hash_uchars(chars, chars_len);
    LOCK();
    ID id = (ID)CFDictionaryGetValue(sym_id, (const void *)name_hash); 
    UNLOCK();
    if (id != 0) {
	goto return_id;
    }
 
    if (str == Qnil) {
	str = rb_unicode_str_new(chars, chars_len);
    }

    rb_sym_t *sym = NULL;
    long pos = 0;
    if (chars_len > 0) {
	UChar c = chars[0];
	switch (c) {
	    case '$':
		id = ID_GLOBAL;
		goto new_id;

	    case '@':
		if (chars_len > 1 && chars[1] == '@') {
		    pos++;
		    id = ID_CLASS;
		}
		else {
		    id = ID_INSTANCE;
		}
		pos++;
		break;

	    default:
		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)) {
			id = rb_id_attrset(id);
			goto id_register;
		    }
		    id = ID_ATTRSET;
		}
		else if (iswupper(c)) {
		    id = ID_CONST;
		}
		else {
		    id = ID_LOCAL;
		}
		break;
	}
    }

    if (pos < chars_len && !isdigit(chars[pos])) {
	for (; pos < chars_len; pos++) {
	    if (!is_identchar(chars[pos])) {
		break;
	    }
	}
    }
    if (pos < chars_len) {
	id = ID_JUNK;
    }

new_id:
    id |= ++last_id << ID_SCOPE_SHIFT;

id_register:
//printf("register %s hash %ld id %ld\n", RSTRING_PTR(str), name_hash, id);
    sym = sym_alloc(str, id);
    LOCK();
    CFDictionarySetValue(sym_id, (const void *)name_hash, (const void *)id);
    CFDictionarySetValue(id_str, (const void *)id, (const void *)sym);
    UNLOCK();

return_id:
    return id;
}
Exemple #14
0
ID
rb_intern3(const char *name, long len, rb_encoding *enc)
{
    VALUE str = rb_enc_str_new(name, len, enc);
    return rb_intern_str(str);
}
Exemple #15
0
static void
SearchFont(VALUE rbFilePathOrName,
           VALUE* volatile rbRealFilePath, int* ttcIndex)
{
  *rbRealFilePath = Qnil;
  if (ttcIndex != NULL) {
    *ttcIndex = -1;
  }
  *rbRealFilePath = strb_GetCompletePath(rbFilePathOrName, false);
  if (!NIL_P(*rbRealFilePath)) {
    return;
  }
  volatile VALUE rbFontNameSymbol =
    ID2SYM(rb_intern_str(rbFilePathOrName));
  FontFileInfo* info = fontFileInfos;
  while (info) {
    if (info->rbFontNameSymbol == rbFontNameSymbol) {
      *rbRealFilePath = rb_str_new2(rb_id2name(SYM2ID(info->rbFileNameSymbol)));
#ifdef WIN32
      volatile VALUE rbTemp =
        rb_str_new2(rb_id2name(SYM2ID(rbWindowsFontDirPathSymbol)));
      *rbRealFilePath = rb_str_concat(rb_str_cat2(rbTemp, "\\"), *rbRealFilePath);
#endif
      if (ttcIndex != NULL) {
        *ttcIndex = info->ttcIndex;
      }
      return;
    }
    info = info->next;
  }
#ifdef HAVE_FONTCONFIG_FONTCONFIG_H
  if (!FcInit()) {
    FcFini();
    rb_raise(strb_GetStarRubyErrorClass(), "can't initialize fontconfig library");
    return;
  }
  int nameLength = RSTRING_LEN(rbFilePathOrName) + 1;
  char name[nameLength];
  strncpy(name, StringValueCStr(rbFilePathOrName), nameLength);
  char* delimiter = strchr(name, ',');
  char* style = NULL;
  if (delimiter) {
    *delimiter = '\0';
    style = delimiter + 1;
    char* nameTail = delimiter - 1;
    while (*nameTail == ' ') {
      *nameTail = '\0';
      nameTail--;
    }
    while (*style == ' ') {
      style++;
    }
  }
  FcPattern* pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL);
  if (style && 0 < strlen(style)) {
    FcPatternAddString(pattern, FC_STYLE, (FcChar8*)style);
  }
  FcObjectSet* objectSet = FcObjectSetBuild(FC_FAMILY, FC_FILE, NULL);
  FcFontSet* fontSet = FcFontList(NULL, pattern, objectSet);
  if (objectSet) {
    FcObjectSetDestroy(objectSet);
  }
  if (pattern) {
    FcPatternDestroy(pattern);
  }
  if (fontSet) {
    for (int i = 0; i < fontSet->nfont; i++) {
      FcChar8* fileName = NULL;
      if (FcPatternGetString(fontSet->fonts[i], FC_FILE, 0, &fileName) ==
          FcResultMatch) {
        FcChar8* fontName = FcNameUnparse(fontSet->fonts[i]);
        *rbRealFilePath = rb_str_new2((char*)fileName);
        volatile VALUE rbFontName = rb_str_new2((char*)fontName);
        free(fontName);
        fontName = NULL;
        if (ttcIndex != NULL && strchr(StringValueCStr(rbFontName), ',')) {
          *ttcIndex = 0;
        }
      }
    }
    FcFontSetDestroy(fontSet);
  }
  FcFini();
  if (!NIL_P(*rbRealFilePath)) {
    return;
  }
#endif
  return;
}