本文整理汇总了C++中STR2CSTR函数的典型用法代码示例。如果您正苦于以下问题:C++ STR2CSTR函数的具体用法?C++ STR2CSTR怎么用?C++ STR2CSTR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STR2CSTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: aspell_correct_lines
/**
* This method will check an array of strings for misspelled words.
* This method needs a block to work proper. Each misspelled word is yielded,
* a correct word as result from the block is assumed.
* Common use:
*
* a = Aspell.new(...)
* text = ...
* a.correct_lines(text) { |badword|
* puts "Error: #{badword}\n"
* puts a.suggest(badword).join(" | ")
* gets #the input is returned as right word
* }
*
* @param ary the array of strings to check.
* @result an array holding all lines with corrected words.
*/
static VALUE aspell_correct_lines(VALUE self, VALUE ary) {
VALUE result = ary;
if (rb_block_given_p()) {
//create checker
AspellSpeller *speller = get_speller(self);
AspellDocumentChecker * checker = get_checker(speller);
AspellToken token;
//some tmp values
VALUE vline, sline;
VALUE word, rword;
char *line;
int count=RARRAY_LEN(ary);
int c=0;
//create new result array
result = rb_ary_new();
//iterate over array
while(c<count) {
int offset=0;
//fetch line
vline = RARRAY_PTR(ary)[c];
//save line
sline = rb_funcall(vline, rb_intern("dup"), 0);
//c representation
line = STR2CSTR(vline);
//process line
aspell_document_checker_process(checker, line, -1);
//iterate over all misspelled words
while (token = aspell_document_checker_next_misspelling(checker), token.len != 0) {
//extract word by start/length qualifier
word = rb_funcall(vline, rb_intern("[]"), 2, INT2FIX(token.offset), INT2FIX(token.len));
//get the right word from the block
rword = rb_yield(word);
//nil -> do nothing
if(rword == Qnil) continue;
//check for string
if (TYPE(rword) != T_STRING) rb_raise(cAspellError, "%s", "Need a String to substitute");
//chomp the string
rb_funcall(rword, rb_intern("chomp!"), 0);
//empty string -> do nothing
if(strlen(STR2CSTR(rword)) == 0) continue;
//remember word for later suggestion
aspell_speller_store_replacement(speller, STR2CSTR(word), -1, STR2CSTR(rword), -1);
//substitute the word by replacement
rb_funcall(sline, rb_intern("[]="), 3, INT2FIX(token.offset+offset), INT2FIX(token.len), rword);
//adjust offset
offset += strlen(STR2CSTR(rword))-strlen(STR2CSTR(word));
//printf("replace >%s< with >%s< (offset now %d)\n", STR2CSTR(word), STR2CSTR(rword), offset);
}
//push the substituted line to result
rb_ary_push(result, sline);
c++;
}
//free checker
delete_aspell_document_checker(checker);
} else {
rb_raise(cAspellError, "%s", "No block given. How to correct?");
}
return result;
}
示例2: count_amps
//
// function to count the number of events for which amplitudes were generated.
//
//
VALUE count_amps(VALUE __self, VALUE __file_name){
char *filename = STR2CSTR(__file_name);
ifstream in_file;
in_file.open(filename);
int event = 0;
complex<float> amp;
while(!in_file.eof()){
event++;
in_file.read((char*)&,sizeof(amp));
}
return rb_int_new(event-1);
}
示例3: get_gsl_rng_type
static const gsl_rng_type* get_gsl_rng_type(VALUE t)
{
switch (TYPE(t)) {
case T_STRING:
return get_gsl_rng_type_name(STR2CSTR(t));
break;
case T_FIXNUM:
return get_gsl_rng_type_int(FIX2INT(t));
break;
default:
rb_raise(rb_eTypeError, "String or Fixnum expected");
}
}
示例4: aspell_correct_file
/**
* Simple utility function to correct a file.
* The file gets read, content will be checked and write back.
* Please note: This method will change the file! - no backup and of course: no warranty!
* @param filename the name of the file as String.
* @exception Exception due to lack of read/write permissions.
*/
static VALUE aspell_correct_file(VALUE self, VALUE filename) {
if (rb_block_given_p()) {
VALUE content = rb_funcall(rb_cFile, rb_intern("readlines"), 1, filename);
VALUE newcontent = aspell_correct_lines(self, content);
VALUE file = rb_file_open(STR2CSTR(filename), "w+");
rb_funcall(file, rb_intern("write"), 1, newcontent);
rb_funcall(file, rb_intern("close"), 0);
} else {
rb_raise(cAspellError, "%s", "No block given. How to correct?");
}
return self;
}
示例5: rb_gsl_permutation_printf
static VALUE rb_gsl_permutation_printf(int argc, VALUE *argv, VALUE obj)
{
gsl_permutation *h;
int status;
Data_Get_Struct(obj, gsl_permutation, h);
if (argc == 0) {
status = gsl_permutation_fprintf(stdout, h, "%u\n");
} else {
Check_Type(argv[0], T_STRING);
status = gsl_permutation_fprintf(stdout, h, STR2CSTR(argv[0]));
}
return INT2FIX(status);
}
示例6: wrap_ma_set_custom_themes
// service.setCustomThemes(regexps)
// @param regexps string
// @return nil
static VALUE wrap_ma_set_custom_themes(VALUE self, VALUE vstring) {
const char *cstring;
geoword::MAPtr *pServicePtr;
Data_Get_Struct(self, geoword::MAPtr, pServicePtr);
Check_Type(vstring, T_STRING);
cstring = STR2CSTR(vstring);
if (*cstring != '\0') {
(*pServicePtr)->setCustomThemes(cstring);
} else {
(*pServicePtr)->resetCustomThemes();
}
return Qnil;
}
示例7: rb_luxiobtree_get
VALUE rb_luxiobtree_get(VALUE self, VALUE _key)
{
LuxIO *ptr;
Data_Get_Struct(self, LuxIO, ptr);
char *key = STR2CSTR(_key);
Lux::IO::data_t lux_key = {key, strlen(key)};
Lux::IO::data_t *lux_val = ptr->bt->get(&lux_key);
if (lux_val) {
return rb_str_new2((char *)lux_val->data);
}
return Qnil;
}
示例8: rb_luxiobtree_open
VALUE rb_luxiobtree_open(VALUE self, VALUE _filename, VALUE _flag)
{
LuxIO *ptr;
Data_Get_Struct(self, LuxIO, ptr);
char *filename = STR2CSTR(_filename);
int flag = NUM2INT(_flag);
ptr->bt = new Lux::IO::Btree(Lux::IO::CLUSTER);
if (ptr->bt->open(filename, flag)){
return Qtrue;
}
return Qnil;
}
示例9: rb_yp_match
VALUE
rb_yp_match(VALUE self, VALUE domain, VALUE map, VALUE inkey)
{
int res;
char *val;
int vallen;
if( domain == Qnil ) {
domain = rb_yp_get_default_domain(self);
};
res = yp_match(STR2CSTR(domain), STR2CSTR(map),
STR2CSTR(inkey), RSTRING(inkey)->len,
&val, &vallen);
rb_yp_check_yperr(res);
if( vallen > 0 ) {
return rb_tainted_str_new(val, vallen);
}
else {
return Qnil;
};
};
示例10: aspell_s_new
/**
* Ctor for aspell objects:
* Aspell.new(language, jargon, size, encoding)
* Please note: All parameters are optional. If a parameter is omitted, a default value is assumed from
* the environment (eg lang from $LANG). To retain default values, you can use nil
* as value: to set only size: Aspell.new(nil, nil, "80")
* @param language ISO639 language code plus optional ISO 3166 counry code as string (eg: "de" or "us_US")
* @param jargon a special jargon of the selected language
* @param size the size of the dictionary to chose (if there are options)
* @param encoding the encoding to use
* @exception Exception if the specified dictionary is not found.
*/
static VALUE aspell_s_new(int argc, VALUE *argv, VALUE klass) {
VALUE vlang, vjargon, vsize, vencoding;
const char *tmp;
//aspell values
AspellCanHaveError * ret;
AspellSpeller * speller;
AspellConfig * config;
//create new config
config = new_aspell_config();
//extract values
rb_scan_args(argc, argv, "04", &vlang, &vjargon, &vsize, &vencoding);
//language:
if (RTEST(vlang)) set_option(config, "lang", STR2CSTR(vlang));
//jargon:
if (RTEST(vjargon)) set_option(config, "jargon", STR2CSTR(vjargon));
//size:
if (RTEST(vsize)) set_option(config, "size", STR2CSTR(vsize));
//encoding:
if (RTEST(vencoding)) set_option(config, "encoding", STR2CSTR(vencoding));
//create speller:
ret = new_aspell_speller(config);
delete_aspell_config(config);
if (aspell_error(ret) != 0) {
tmp = strdup(aspell_error_message(ret));
delete_aspell_can_have_error(ret);
rb_raise(cAspellError, "%s", tmp);
}
speller = to_aspell_speller(ret);
//wrap pointer
return Data_Wrap_Struct(klass, 0, aspell_free, speller);
}
示例11: connectionToString
static VALUE connectionToString(VALUE self)
{
VALUE result = rb_str_new2("(CLOSED)");
ConnectionHandle *connection = NULL;
Data_Get_Struct(self, ConnectionHandle, connection);
if(connection->handle != 0)
{
VALUE database = rb_iv_get(self, "@database"),
user = rb_iv_get(self, "@user"),
file = rb_iv_get(database, "@file");
char text[256];
sprintf(text, "%[email protected]%s (OPEN)", STR2CSTR(user), STR2CSTR(file));
result = rb_str_new2(text);
}
return(result);
}
示例12: rb_gsl_odeiv_step_type_get
static const gsl_odeiv_step_type* rb_gsl_odeiv_step_type_get(VALUE tt)
{
const gsl_odeiv_step_type *T;
int type;
char name[64];
switch (TYPE(tt)) {
case T_FIXNUM:
type = FIX2INT(tt);
switch (type) {
case GSL_ODEIV_STEP_RK2: T = gsl_odeiv_step_rk2; break;
case GSL_ODEIV_STEP_RK4: T = gsl_odeiv_step_rk4; break;
case GSL_ODEIV_STEP_RKF45: T = gsl_odeiv_step_rkf45; break;
case GSL_ODEIV_STEP_RKCK: T = gsl_odeiv_step_rkck; break;
case GSL_ODEIV_STEP_RK8PD: T = gsl_odeiv_step_rk8pd; break;
case GSL_ODEIV_STEP_RK2IMP: T = gsl_odeiv_step_rk2imp; break;
case GSL_ODEIV_STEP_RK4IMP: T = gsl_odeiv_step_rk4imp; break;
case GSL_ODEIV_STEP_BSIMP: T = gsl_odeiv_step_bsimp; break;
case GSL_ODEIV_STEP_GEAR1: T = gsl_odeiv_step_gear1; break;
case GSL_ODEIV_STEP_GEAR2: T = gsl_odeiv_step_gear2; break;
case GSL_ODEIV_STEP_RK2SIMP: T = gsl_odeiv_step_rk2simp; break;
default:
rb_raise(rb_eArgError, "wrong argument type (Fixnum expected)");
break;
}
break;
case T_STRING:
strcpy(name, STR2CSTR(tt));
if (str_tail_grep(name, "rk2") == 0) T = gsl_odeiv_step_rk2;
else if (str_tail_grep(name, "rk4") == 0) T = gsl_odeiv_step_rk4;
else if (str_tail_grep(name, "rkf45") == 0) T = gsl_odeiv_step_rkf45;
else if (str_tail_grep(name, "rkck") == 0) T = gsl_odeiv_step_rkck;
else if (str_tail_grep(name, "rk8pd") == 0) T = gsl_odeiv_step_rk8pd;
else if (str_tail_grep(name, "rk2imp") == 0) T = gsl_odeiv_step_rk2imp;
else if (str_tail_grep(name, "rk4imp") == 0) T = gsl_odeiv_step_rk4imp;
else if (str_tail_grep(name, "bsimp") == 0) T = gsl_odeiv_step_bsimp;
else if (str_tail_grep(name, "gear1") == 0) T = gsl_odeiv_step_gear1;
else if (str_tail_grep(name, "gear2") == 0) T = gsl_odeiv_step_gear2;
else if (str_tail_grep(name, "rk2simp") == 0) T = gsl_odeiv_step_rk2simp;
else {
rb_raise(rb_eArgError, "wrong argument type %s", name);
}
break;
default:
rb_raise(rb_eArgError, "wrong argument type %s (String or Fixnum expected)",
rb_class2name(CLASS_OF(tt)));
break;
}
return T;
}
示例13: proj_initialize
static VALUE proj_initialize(VALUE self, VALUE proj_params){
_wrap_pj* wpj;
int size = RARRAY(proj_params)->len;
char** c_params = (char **) malloc(size*sizeof(char *));
VALUE *ptr = RARRAY(proj_params)->ptr;
int i;
for (i=0; i < size; i++, ptr++)
c_params[i]= STR2CSTR(*ptr);
Data_Get_Struct(self,_wrap_pj,wpj);
wpj->pj = pj_init(size,c_params);
if(wpj->pj == 0)
rb_raise(rb_eArgError,"invalid initialization parameters");
free(c_params);
return self;
}
示例14: wrap_ma_get_geoword_entries
// service.getGeowordEntries(str)
// @param str string
// @return array of Geoword
static VALUE wrap_ma_get_geoword_entries(VALUE self, VALUE vstring) {
const char *cstring;
geoword::MAPtr *pServicePtr;
Data_Get_Struct(self, geoword::MAPtr, pServicePtr);
Check_Type(vstring, T_STRING);
cstring = STR2CSTR(vstring);
std::map<ID, geoword::Geoword> geowords = (*pServicePtr)->getGeowordEntries(cstring);
VALUE rb_geowords = rb_hash_new();
for (std::map<ID, geoword::Geoword>::iterator it = geowords.begin(); it != geowords.end(); it++) {
rb_hash_aset(rb_geowords, INT2FIX((*it).first), _geoword_to_ruby_hash(&((*it).second)));
}
return rb_geowords;
}
示例15: rh_new
VALUE rh_new(VALUE tds_socket, VALUE sqlstring)
{
VALUE oSybRes;
SYBRESULT *sybres;
sybres = ALLOC(SYBRESULT);
Data_Get_Struct(tds_socket, TDSSOCKET, sybres->tds);
sybres->sqlstring=STR2CSTR(sqlstring);
oSybRes = Data_Wrap_Struct(cResultHandle, 0, rh_free, sybres);
rb_obj_call_init(oSybRes, 0, 0);
return oSybRes;
} // rh_new