本文整理汇总了C++中StringValueCStr函数的典型用法代码示例。如果您正苦于以下问题:C++ StringValueCStr函数的具体用法?C++ StringValueCStr怎么用?C++ StringValueCStr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringValueCStr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_git_rebase_commit
/*
* call-seq:
* Rebase.commit(author = nil, committer, message = nil)
*
* Commit the current patch. Any conflicts must have been resolved.
*
* If +author+ is +nil+, the existing author for the commit will be
* used. If +message+ is +nil+, the existing message will be used.
*/
static VALUE rb_git_rebase_commit(int argc, VALUE *argv, VALUE self)
{
int error;
git_oid id;
git_rebase *rebase;
git_signature *author = NULL, *committer;
const char *message = NULL;
VALUE rb_options, rb_author, rb_committer, rb_message;
Data_Get_Struct(self, git_rebase, rebase);
rb_scan_args(argc, argv, ":", &rb_options);
Check_Type(rb_options, T_HASH);
rb_author = rb_hash_aref(rb_options, CSTR2SYM("author"));
rb_committer = rb_hash_aref(rb_options, CSTR2SYM("committer"));
rb_message = rb_hash_aref(rb_options, CSTR2SYM("message"));
if (!NIL_P(rb_message)) {
Check_Type(rb_message, T_STRING);
message = StringValueCStr(rb_message);
}
if (NIL_P(rb_committer))
rb_raise(rb_eArgError, "Expected non-nil committer");
else
committer = rugged_signature_get(rb_committer, NULL);
if (!NIL_P(rb_author))
author = rugged_signature_get(rb_author, NULL);
error = git_rebase_commit(&id, rebase, author, committer, NULL, message);
git_signature_free(author);
git_signature_free(committer);
rugged_exception_check(error);
return rugged_create_oid(&id);
}
示例2: parse_rebase_options
static void parse_rebase_options(git_rebase_options *ret, VALUE rb_options)
{
VALUE val;
if (NIL_P(rb_options))
return;
val = rb_hash_aref(rb_options, CSTR2SYM("quiet"));
ret->quiet = RTEST(val);
val = rb_hash_aref(rb_options, CSTR2SYM("inmemory"));
ret->inmemory = RTEST(val);
val = rb_hash_aref(rb_options, CSTR2SYM("rewrite_notes_ref"));
if (!NIL_P(val)) {
Check_Type(val, T_STRING);
ret->rewrite_notes_ref = StringValueCStr(val);
}
rugged_parse_checkout_options(&ret->checkout_options, rb_options);
rugged_parse_merge_options(&ret->merge_options, rb_options);
}
示例3: rb_load_image
/*
* call-seq:
* IplImage::load(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>)
*
* Load an image from file.
* iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image
* iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale
* iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is.
* Currently the following file format are supported.
* * Windows bitmaps - BMP,DIB
* * JPEG files - JPEG,JPG,JPE
* * Portable Network Graphics - PNG
* * Portable image format - PBM,PGM,PPM
* * Sun rasters - SR,RAS
* * TIFF files - TIFF,TIF
*/
VALUE
rb_load_image(int argc, VALUE *argv, VALUE self)
{
VALUE filename, iscolor;
rb_scan_args(argc, argv, "11", &filename, &iscolor);
Check_Type(filename, T_STRING);
int _iscolor;
if (TYPE(iscolor) == T_NIL) {
_iscolor = CV_LOAD_IMAGE_COLOR;
}
else {
Check_Type(iscolor, T_FIXNUM);
_iscolor = FIX2INT(iscolor);
}
IplImage *image;
if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) {
rb_raise(rb_eStandardError, "file does not exist or invalid format image.");
}
return OPENCV_OBJECT(rb_klass, image);
}
示例4: rdwarf_initialize
static VALUE rdwarf_initialize(VALUE self, VALUE filename)
{
rdwarf_t *rd = GetRDwarf(self);
Dwarf_Debug dbg;
Dwarf_Error err;
int fd;
int ret;
SafeStringValue(filename);
filename = rb_str_export_to_enc(filename, rb_filesystem_encoding());
fd = rb_cloexec_open(StringValueCStr(filename), O_RDONLY, 0);
if (fd < 0) {
rb_sys_fail("open");
}
ret = dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &err);
if (ret != DW_DLV_OK) {
rb_raise(rd_eError, "%s", dwarf_errmsg(err));
}
rd->shared_data = rd_shared_data_alloc(dbg, fd, self);
return self;
}
示例5: rxml_node_new_comment
/*
* call-seq:
* XML::Node.new_comment(content = nil) -> XML::Node
*
* Create a new comment node, optionally setting
* the node's content.
*
*/
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
{
VALUE content = Qnil;
xmlNodePtr xnode;
rb_scan_args(argc, argv, "01", &content);
if (NIL_P(content))
{
xnode = xmlNewComment(NULL);
}
else
{
content = rb_obj_as_string(content);
xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
}
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(klass, xnode);
}
示例6: foreach
static VALUE foreach(VALUE self, VALUE filename) {
FILE *file = fopen(StringValueCStr(filename), "r");
if (file == NULL)
rb_raise(rb_eRuntimeError, "File not found");
char *line = NULL;
size_t len = 0;
char *token;
int idx;
VALUE ary;
while (getline(&line, &len, file) != -1) {
ary = rb_ary_new();
token = strtok(line, DELIMITERS);
idx = 0;
while (token != NULL) {
rb_ary_store(ary, idx, rb_str_new(token, strlen(token)));
idx ++;
token = strtok(NULL, DELIMITERS);
}
/* OBJ_FREEZE(ary); */
rb_yield(ary);
/* FL_UNSET((ary), FL_FREEZE); */
/* for(idx = 0; idx < RARRAY_LEN(ary); idx ++) {
rb_ary_store(ary, idx, Qnil);
} */
}
fclose(file);
return Qnil;
}
示例7: rxml_xpath_context_find
/*
* call-seq:
* context.find("xpath") -> XML::XPath::Object
*
* Find nodes matching the specified XPath expression
*/
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
xmlXPathContextPtr xctxt;
xmlXPathObjectPtr xobject;
xmlXPathCompExprPtr xcompexpr;
VALUE result;
Data_Get_Struct(self, xmlXPathContext, xctxt);
if (TYPE(xpath_expr) == T_STRING)
{
VALUE expression = rb_check_string_type(xpath_expr);
xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
}
else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
{
Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
}
else
{
rb_raise(rb_eTypeError,
"Argument should be an intance of a String or XPath::Expression");
}
if (xobject == NULL)
{
/* xmlLastError is different than xctxt->lastError. Use
xmlLastError since it has the message set while xctxt->lastError
does not. */
xmlErrorPtr xerror = xmlGetLastError();
rxml_raise(xerror);
}
result = rxml_xpath_object_wrap(xobject);
rb_iv_set(result, "@context", self);
return result;
}
示例8: rb_git_note_lookup
/*
* call-seq:
* obj.notes(notes_ref = 'refs/notes/commits') -> hash
*
* Lookup a note for +obj+ from +notes_ref+:
* - +notes_ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
*
* Returns a new Hash object.
*
* obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"}
*/
static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
{
git_repository *repo;
const char *notes_ref = NULL;
VALUE rb_notes_ref;
VALUE rb_note_hash;
VALUE owner;
git_note *note;
git_object *object;
int error;
rb_scan_args(argc, argv, "01", &rb_notes_ref);
if (!NIL_P(rb_notes_ref)) {
Check_Type(rb_notes_ref, T_STRING);
notes_ref = StringValueCStr(rb_notes_ref);
}
Data_Get_Struct(self, git_object, object);
owner = rugged_owner(self);
Data_Get_Struct(owner, git_repository, repo);
error = git_note_read(¬e, repo, notes_ref, git_object_id(object));
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
rb_note_hash = rb_hash_new();
rb_hash_aset(rb_note_hash, CSTR2SYM("message"), rugged_git_note_message(note));
rb_hash_aset(rb_note_hash, CSTR2SYM("oid"), rugged_git_note_oid(note));
git_note_free(note);
return rb_note_hash;
}
示例9: rxml_reader_io
/* call-seq:
* XML::Reader.io(io) -> XML::Reader
* XML::Reader.io(io, :encoding => XML::Encoding::UTF_8,
* :options => XML::Parser::Options::NOENT) -> XML::Parser
*
* Creates a new reader by parsing the specified io object.
*
* You may provide an optional hash table to control how the
* parsing is performed. Valid options are:
*
* base_uri - The base url for the parsed document.
* encoding - The document encoding, defaults to nil. Valid values
* are the encoding constants defined on XML::Encoding.
* options - Controls the execution of the parser, defaults to 0.
* Valid values are the constants defined on
* XML::Parser::Options. Mutliple options can be combined
* by using Bitwise OR (|).
*/
static VALUE rxml_reader_io(int argc, VALUE *argv, VALUE klass)
{
xmlTextReaderPtr xreader;
VALUE io;
VALUE options;
char *xbaseurl = NULL;
const char *xencoding = NULL;
int xoptions = 0;
rb_scan_args(argc, argv, "11", &io, &options);
if (!NIL_P(options))
{
VALUE baseurl = Qnil;
VALUE encoding = Qnil;
VALUE parserOptions = Qnil;
Check_Type(options, T_HASH);
baseurl = rb_hash_aref(options, base_uri_SYMBOL);
xbaseurl = NIL_P(baseurl) ? NULL : StringValueCStr(baseurl);
encoding = rb_hash_aref(options, ENCODING_SYMBOL);
xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));
parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
}
xreader = xmlReaderForIO((xmlInputReadCallback) rxml_read_callback, NULL,
(void *) io,
xbaseurl, xencoding, xoptions);
if (xreader == NULL)
rxml_raise(&xmlLastError);
return rxml_reader_wrap(xreader);
}
示例10: initFunc
static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
{
VALUE modules = rb_iv_get(xslt, "@modules");
VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
VALUE args = { Qfalse };
VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
VALUE inst;
nokogiriXsltStylesheetTuple *wrapper;
int i;
for(i = 0; i < RARRAY_LEN(methods); i++) {
VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
xsltRegisterExtFunction(ctxt,
(unsigned char *)StringValueCStr(method_name), uri, method_caller);
}
Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
wrapper);
inst = rb_class_new_instance(0, NULL, obj);
rb_ary_push(wrapper->func_instances, inst);
return (void *)inst;
}
示例11: remove_buddy
static VALUE remove_buddy(VALUE self, VALUE buddy)
{
PurpleAccount *account;
Data_Get_Struct(self, PurpleAccount, account);
PurpleBuddy* pb = purple_find_buddy(account, StringValueCStr(buddy));
if (NULL == pb) {
rb_raise(rb_eRuntimeError, "Failed to remove buddy for %s : %s does not exist", purple_account_get_username(account), StringValueCStr(buddy));
}
char* group = _("Buddies");
PurpleGroup* grp = purple_find_group(group);
if (!grp)
{
grp = purple_group_new(group);
purple_blist_add_group(grp, NULL);
}
purple_blist_remove_buddy(pb);
purple_account_remove_buddy(account, pb, grp);
return Qtrue;
}
示例12: rlink_sentence_init
/*
* call-seq:
* LinkParser::Sentence.new( str, dict ) -> sentence
*
* Create a new LinkParser::Sentence object from the given input string
# using the specified LinkParser::Dictionary.
*
* dict = LinkParser::Dictionary.new
* LinkParser::Sentence.new( "The boy runs", dict ) #=> #<LinkParser::Sentence:0x5481ac>
*/
static VALUE
rlink_sentence_init( VALUE self, VALUE input_string, VALUE dictionary ) {
if ( !check_sentence(self) ) {
struct rlink_sentence *ptr;
Sentence sent;
struct rlink_dictionary *dictptr = rlink_get_dict( dictionary );
if ( !(sent = sentence_create( StringValueCStr(input_string), dictptr->dict )) )
rlink_raise_lp_error();
DATA_PTR( self ) = ptr = rlink_sentence_alloc();
ptr->sentence = sent;
ptr->dictionary = dictionary;
ptr->options = Qnil;
} else {
rb_raise( rb_eRuntimeError,
"Cannot re-initialize a sentence once it's been created." );
}
return self;
}
示例13: Font_initialize
static VALUE
Font_initialize(VALUE self, VALUE rbRealFilePath, VALUE rbSize,
VALUE rbBold, VALUE rbItalic, VALUE rbTtcIndex)
{
const char* path = StringValueCStr(rbRealFilePath);
const int size = NUM2INT(rbSize);
const bool bold = RTEST(rbBold);
const bool italic = RTEST(rbItalic);
const int ttcIndex = NUM2INT(rbTtcIndex);
Font* font;
Data_Get_Struct(self, Font, font);
font->size = size;
font->sdlFont = TTF_OpenFontIndex(path, size, ttcIndex);
if (!font->sdlFont) {
rb_raise(strb_GetStarRubyErrorClass(), "%s (%s)", TTF_GetError(), path);
}
const int style = TTF_STYLE_NORMAL |
(bold ? TTF_STYLE_BOLD : 0) | (italic ? TTF_STYLE_ITALIC : 0);
TTF_SetFontStyle(font->sdlFont, style);
return Qnil;
}
示例14: rb_git_remote_collection_create_anonymous
/*
* call-seq:
* remotes.create_anonymous(url) -> remote
*
* Return a new remote with +url+ in +repository+ , the remote is not persisted:
* - +url+: a valid remote url
*
* Returns a new Rugged::Remote object.
*
* @repo.remotes.create_anonymous('git://github.com/libgit2/libgit2.git') #=> #<Rugged::Remote:0x00000001fbfa80>
*/
static VALUE rb_git_remote_collection_create_anonymous(VALUE self, VALUE rb_url)
{
git_remote *remote;
git_repository *repo;
int error;
VALUE rb_repo = rugged_owner(self);
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_url, T_STRING);
error = git_remote_create_anonymous(
&remote,
repo,
StringValueCStr(rb_url),
NULL);
rugged_exception_check(error);
return rugged_remote_new(rb_repo, remote);
}
示例15: rb_git_get_option
/*
* call-seq:
* Settings[option] -> value
*
* Gets the value of a libgit2 library option.
*/
static VALUE rb_git_get_option(VALUE self, VALUE option)
{
const char *opt;
Check_Type(option, T_STRING);
opt = StringValueCStr(option);
if (strcmp(opt, "mwindow_size") == 0) {
size_t val;
git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &val);
return SIZET2NUM(val);
}
else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
size_t val;
git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &val);
return SIZET2NUM(val);
}
else {
rb_raise(rb_eArgError, "Unknown option specified");
}
}