VALUE string_spec_rb_str2cstr(VALUE self, VALUE str, VALUE return_length) { if(return_length == Qtrue) { long len = 0; char* ptr = rb_str2cstr(str, &len); VALUE ary = rb_ary_new(); rb_ary_push(ary, rb_str_new2(ptr)); rb_ary_push(ary, INT2FIX(len)); return ary; } else { return rb_str_new2(rb_str2cstr(str, NULL)); } }
VALUE rGrok_add_pattern(VALUE self, VALUE name, VALUE pattern) { grok_t *grok = NULL; char *c_name= NULL, *c_pattern = NULL; long namelen = 0, patternlen = 0; c_name = rb_str2cstr(name, &namelen); c_pattern = rb_str2cstr(pattern, &patternlen); Data_Get_Struct(self, grok_t, grok); grok_pattern_add(grok, c_name, namelen, c_pattern, patternlen); return Qnil; }
VALUE rGrok_match(VALUE self, VALUE input) { grok_t *grok = NULL; grok_match_t gm; char *c_input = NULL; long len = 0; int ret = 0; VALUE match = Qnil; Data_Get_Struct(self, grok_t, grok); c_input = rb_str2cstr(input, &len); ret = grok_execn(grok, c_input, (int)len, &gm); VALUE rgm = Qnil; //fprintf(stderr, "%d\n", ret); switch (ret) { case GROK_ERROR_NOMATCH: rgm = Qfalse; break; case GROK_OK: rgm = rGrokMatch_new_from_grok_match(&gm); break; default: rb_raise(rb_eArgError, "Error from grok_execn: %d", ret); rgm = Qnil; } return rgm; }
/* * call-seq: * nodeset.to_a -> [node, ..., node] * * Obtain an array of the nodes in this set. */ VALUE ruby_xml_node_set_to_a(VALUE self) { ruby_xml_node_set *rxnset; VALUE r; Data_Get_Struct(self, ruby_xml_node_set, rxnset); r=ruby_xml_xpath_object_to_a(rxnset->rxpop); #ifdef NODE_DEBUG fprintf(stderr,"node_set_to_a %s\n",rb_str2cstr(rb_ary_to_s(r),0)); #endif return r; }
VALUE rGrok_compile(VALUE self, VALUE pattern) { grok_t *grok; char *c_pattern; long len; int ret; Data_Get_Struct(self, grok_t, grok); c_pattern = rb_str2cstr(pattern, &len); ret = grok_compilen(grok, c_pattern, (int)len); if (ret) { rb_raise(rb_eArgError, "Compile failed: %s", grok->errstr); } return Qnil; }
VALUE rGrok_add_patterns_from_file(VALUE self, VALUE path) { grok_t *grok = NULL; int ret = 0; char *c_path = NULL; long pathlen = 0; c_path = rb_str2cstr(path, &pathlen); Data_Get_Struct(self, grok_t, grok); ret = grok_patterns_import_from_file(grok, c_path); if (ret != GROK_OK) { rb_raise(rb_eArgError, "Failed to add patterns from file %s", c_path); } return Qnil; }
void get_string_ensure(VALUE value, std::string& str) { if (NIL_P(value) != 0) { rb_raise(rb_eRuntimeError, "Bad string value."); } Check_Type(value, T_STRING); long length = 0; char* ch = NULL; ch = rb_str2cstr(value, &length); if (!ch) { rb_raise(rb_eRuntimeError, "Bad string value."); } str = std::string(ch, length); }
static VALUE cTemplate_init(VALUE self, VALUE rb_template_string) { mustache_node_t* c_template; Data_Get_Struct(self, mustache_node_t, c_template); char* c_template_string; long c_template_string_length; mustache_error_t* error = NULL; c_template_string = strdup(rb_str2cstr(rb_template_string, &c_template_string_length)); mustache_build_template(c_template_string, c_template, &error); if (error) { rb_raise(rb_eSyntaxError, error->error_text); } return self; }
// utils impl bool get_string(VALUE value, std::string& str) { if (NIL_P(value) != 0) { return false; } Check_Type(value, T_STRING); long length = 0; char* ch = NULL; ch = rb_str2cstr(value, &length); if (!ch) { return false; } str = std::string(ch, length); return true; }
VALUE string_spec_rb_str2cstr_replace(VALUE self, VALUE str) { char* ptr = rb_str2cstr(str, NULL); ptr[0] = 'f'; ptr[1] = 'o'; ptr[2] = 'o'; ptr[3] = 0; return Qnil; }
/* Method: ImageList#write(file) Purpose: Write all the images to the specified file. If the file format supports multi-image files, and the @images array contains more than one image, then the images will be written as a single multi-image file. Otherwise each image will be written to a separate file. Returns self. */ VALUE ImageList_write(VALUE self, VALUE file) { Image *images, *img; Info *info; const MagickInfo *m; volatile VALUE info_obj; char *filename; long filenameL; unsigned long scene; ExceptionInfo exception; info_obj = rm_info_new(); Data_Get_Struct(info_obj, Info, info); if (TYPE(file) == T_FILE) { OpenFile *fptr; // Ensure file is open - raise error if not GetOpenFile(file, fptr); SetImageInfoFile(info, GetReadFile(fptr)); } else { // Convert arg to string. Catch exceptions. file = rb_rescue(rb_String, file, file_arg_rescue, file); // Copy the filename to the Info and to the Image. filename = rb_str2cstr(file, &filenameL); filenameL = min(filenameL, MaxTextExtent-1); memcpy(info->filename, filename, (size_t)filenameL); info->filename[filenameL] = '\0'; SetImageInfoFile(info, NULL); } // Convert the images array to an images sequence. images = images_from_imagelist(self); // Copy the filename into each images. Set a scene number to be used if // writing multiple files. (Ref: ImageMagick's utilities/convert.c for (scene = 0, img = images; img; img = GetNextImageInList(img)) { img->scene = scene++; strcpy(img->filename, info->filename); } GetExceptionInfo(&exception); (void) SetImageInfo(info, MagickTrue, &exception); rm_check_exception(&exception, images, RetainOnError); (void) DestroyExceptionInfo(&exception); // Find out if the format supports multi-images files. GetExceptionInfo(&exception); m = GetMagickInfo(info->magick, &exception); rm_check_exception(&exception, images, RetainOnError); (void) DestroyExceptionInfo(&exception); // Tell WriteImage if we want a multi-images file. if (imagelist_length(self) > 1L && m->adjoin) { info->adjoin = MagickTrue; } for (img = images; img; img = GetNextImageInList(img)) { (void) WriteImage(info, img); // images will be split before raising an exception rm_check_image_exception(images, RetainOnError); if (info->adjoin) { break; } } rm_split(images); return self; }