int get_next_line(const int fd, char **line) { static char *save = NULL; static char *todel = NULL; int check; int i; check = 1; if (!save || !strchr(save, '\n')) { check = readnl(fd, &save); todel = save; } if (check == -1) return (-1); if (check == 0) save = NULL; i = find_and_replace(save); *line = ft_strdup(save); if (i == 1) save += ft_strlen(save) + 1; else { free(todel); save = NULL; } return (check); }
//-------------------------------------------------------------------------- void htmlpage::print(std::ostream& out, string s) const { (void) find_and_replace(s, "\n", " "); (void) find_and_replace(s, "\t", " "); (void) find_and_replace(s, "'", "’"); out << "<html>" << endl; out << " <head>" << endl; #ifdef LOADSCRIPTS out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/jquery-1.7.1.min.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/jquerysvg/jquery.svg.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/jquerysvg/jquery.svgdom.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_proto.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_jquery_svg_backend.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_mobile.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_ui_inits.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_load_external_file.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_ui_objects.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_ui_builder.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_ui_interact.js\"></script>" << endl; out << " <script type=\"text/javascript\" src=\"http://www.mikesolomon.org/faust/svg/faust_server_communication.js\"></script>" << endl; out << " <link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.mikesolomon.org/faust/svg/faust_css.css\"></link>" << endl; #else out << "<style type=\"text/css\">" << endl; for (unsigned int i = 0; i < stylesheet_len; i++) { out << stylesheet[i]; } out << endl; out << "</style>" << endl; out << " <script type=\"text/javascript\" >" << endl; for (unsigned int i = 0; i < jsscripts_len; i++) { out << jsscripts[i]; } out << endl; out << " </script>" << endl; #endif out << " </head>" << endl; out << " <body>" << endl; out << " <script type=\"text/javascript\">" << endl; out << " _f4u$t.server_update_function = _f4u$t.main('"; out << s; out << "', null, _f4u$t.faust_server_handler);" << endl; out << " </script>" << endl; out << " </body>" << endl; out << "</html>"; }
static void process_msn_cookie(const char *cookie, char **new_cookie) { CookieNodeType *cl; char *cookie_val; char *new_cookie_val = NULL; char *new2_cookie_val = NULL; cl = parse_cookies(cookie); if(!cl) { nag("Error parsing cookies\n"); } else { cookie_val = get_cookie_value(cl, "SRCHHPGUSR"); if(!cookie_val) { nag("No SRCHHPUSR cookie, cookie is %s\n", cookie); } else { new_cookie_val = find_and_replace(cookie_val, "&ADLT=OFF&", "&ADLT=STRICT&"); if(!new_cookie_val) { nag("Error replacing string\n"); } else { new2_cookie_val = find_and_replace(new_cookie_val, "&ADLT=DEMOTE&", "&ADLT=STRICT&"); Free(new_cookie_val); if(!new2_cookie_val) { nag("Error replacing string\n"); } else { if(set_cookie_value(&cl, "SRCHHPGUSR", new2_cookie_val)) { nag("Error setting new cookie value\n"); } else { ustring ucookie = USTRING_INITIALIZER; if(rebuild_cookie(cl, &ucookie)) { nag("Error rebuilding cookie\n"); } else { *new_cookie = Strdup(ucookie.string); } reset_ustring(&ucookie); } Free(new2_cookie_val); } } } } delete_cookie_list(cl); }
void Crossover::calc_nParent() { std::string str = expression; int i = 0; int nFind = 0; do { std::string findStr = "x" + intToString(i); nFind = find_and_replace(str, findStr, ""); if (nFind>0) ++i; } while (nFind > 0); nParent = i; }
// extended label method for option lines // the purpose is to provide a little more visual context to the various options, // and make config-ui interface more human friendly void option_label(const int2& p, const color& c, rs::device& dev, rs::option opt, double max_width, bool enabled, double* value = nullptr) { auto name = find_and_replace(rs_option_to_string((rs_option)opt), "_", " "); // replacing _ with ' ' to reduce visual clutter std::string s(name); auto size = name.size(); // align the string to max. allowed width while (size > 0 && stb_easy_font_width((char*)s.c_str()) > max_width) { s = name.substr(0, size--) + "..."; } // remove option prefixes converting them to visual hints through color: color newC = c; #define STRING_CASE(S, C) std::string S = #S; if (s.compare(0, S.length(), S) == 0) { newC = C; s = find_and_replace(s, S + " ", ""); } color color1 = { 0.6f, 1.0f, 1.0f }; color color2 = { 1.0f, 0.6f, 1.0f }; color color3 = { 1.0f, 1.0f, 0.6f }; color color4 = { 1.0f, 0.6f, 0.6f }; color color5 = { 0.6f, 0.6f, 1.0f }; color color6 = { 0.6f, 1.0f, 0.6f }; STRING_CASE(ZR300, color1) STRING_CASE(F200, color2) STRING_CASE(SR300, color3) STRING_CASE(R200, color4) STRING_CASE(FISHEYE, color5) STRING_CASE(COLOR, color6) if (!enabled) newC = { 0.5f, 0.5f, 0.5f }; auto w = stb_easy_font_width((char*)s.c_str()); label(p, newC, s.c_str()); // if value is required, append it at the end of the string if (value) { std::stringstream sstream; sstream << ": " << *value; int2 newP{ p.x + w, p.y }; label(newP, c, sstream.str().c_str()); } rect bbox{ p.x - 15, p.y - 10, p.x + w + 10, p.y + 5 }; if (bbox.contains(cursor)) { std::string hint = dev.get_option_description(opt); auto hint_w = stb_easy_font_width((char*)hint.c_str()); fill_rect({ cursor.x - hint_w - 7, cursor.y + 5, cursor.x + 7, cursor.y - 17 }, { 1.0f, 1.0f, 1.0f }); fill_rect({ cursor.x - hint_w - 6, cursor.y + 4, cursor.x + 6, cursor.y - 16 }, { 0.0f, 0.0f, 0.0f }); label({ cursor.x - hint_w, cursor.y - 2 }, { 1.f, 1.f, 1.f }, hint.c_str()); } }
void Dictionary::SaveAsJSON() { FILE *f; if(fopen_s(&f, "C:\\Users\\chs\\dictionary.json", "w") == 0) { fputs("Dictionary = {\n", f); for(uint i=0; i<mNumWords; ++i) { char *p = Dictionary::mWord + i * 8; string s = GetDefinition(i, "", "\\n"); find_and_replace(s, "\"", "'"); fprintf_s(f, "\t\"%s\": \"%s\"%s\n", p, s.c_str(), (i < mNumWords - 1) ? "," : ""); } fputs("}\n", f); fclose(f); } }
int replace_var(t_cmd *cmd, t_data *data) { int ret; t_cmd *tmp; tmp = cmd->next; while (tmp != cmd) { if (tmp->word[0] == '!') if ((ret = replace_history(tmp, data->his)) == -1 || ret == -2) return (ret); if (tmp->word[0] == '$') if ((ret = find_and_replace(tmp, data->env, data->var)) == -1 || ret == -2) return (ret); if (tmp->word[0] == '~') if (replace_tild(tmp, data->env, data->home) == -1) return (-1); tmp = tmp->next; } return (0); }
static void process_alltheweb_cookie(const char *cookie, char **new_cookie) { CookieNodeType *cl; char *cookie_val; char *new_cookie_val = NULL; *new_cookie = NULL; cl = parse_cookies(cookie); if(!cl) { nag("Error parsing cookies\n"); } else { cookie_val = get_cookie_value(cl, "PREF"); if(!cookie_val) { nag("No PREF cookie, cookie is %s\n", cookie); } else { new_cookie_val = find_and_replace(cookie_val, ":no=off", ""); if(!new_cookie_val) { nag("Error replacing string\n"); } else { if(set_cookie_value(&cl, "PREF", new_cookie_val)) { nag("Error setting new cookie value\n"); } else { ustring ucookie = USTRING_INITIALIZER; if(rebuild_cookie(cl, &ucookie)) { nag("Error rebuilding cookie\n"); } else { *new_cookie = Strdup(ucookie.string); } reset_ustring(&ucookie); } Free(new_cookie_val); } } } delete_cookie_list(cl); }
static qeocore_type_t *build_object(const qeo_factory_t *factory, json_t *typedesc) { qeocore_type_t *qeoType = NULL; const char *name = NULL; json_t *value = NULL; qeo_retcode_t ret = QEO_EFAIL; bool iret = true; const char *topic = NULL; assert(typedesc != NULL); assert(factory != NULL); do { json_t *type_topic = json_object_get(typedesc, KEY_TOPIC); if ((NULL == type_topic) || !json_is_string(type_topic)) { qeo_log_e("Invalid type_topic (%p)", type_topic); return qeoType; } json_t *properties = json_object_get(typedesc, KEY_PROPERTIES); if ((NULL == properties) || !json_is_object(properties)) { qeo_log_e("Invalid properties (%p)", properties); return qeoType; } topic = json_string_value(type_topic); //Replace all "::" with ".", because there's a mismatch in topic definitions found in the TSM structs, with "." and the QDM topic definitions with "::" find_and_replace((char *) topic, "::", "."); qeoType = qeocore_type_struct_new(topic); if (qeoType == NULL) { qeo_log_e("qeocore_type_struct_new failed for topic:%s", topic); break; } qeo_log_d("Registered new struct with name %s", topic); void *iter = json_object_iter(properties); while (iter) { name = json_object_iter_key(iter); if (name == NULL) { qeo_log_e("name == NULL"); iret = false; break; } value = json_object_iter_value(iter); if (value == NULL) { qeo_log_e("value == NULL"); iret = false; break; } if (!json_is_object(value)) { qeo_log_e("no json object"); iret = false; break; } if (QEO_OK != object_add_member(factory, qeoType, name, value)) { qeo_log_e("object add member failed"); iret = false; break; } iter = json_object_iter_next(properties, iter); } if (true != iret) { break; } if (QEO_OK != qeocore_type_register(factory, qeoType, topic)) { qeo_log_e("failed to register type: %s", topic); } ret = QEO_OK; } while (0); if (ret != QEO_OK) { qeocore_type_free(qeoType); qeoType = NULL; } return qeoType; }
static qeocore_type_t *build_enum(const qeo_factory_t *factory, json_t *typedesc){ qeocore_type_t *qeoType = NULL; qeocore_enum_constants_t vals = DDS_SEQ_INITIALIZER(qeocore_enum_constant_t); const char *enumstr = NULL; DDS_ReturnCode_t ddsret; assert(typedesc != NULL); assert(factory != NULL); do { json_t *type_enum = json_object_get(typedesc, KEY_ENUM); if ((NULL == type_enum) || !json_is_string(type_enum)) { qeo_log_e("Invalid type_enum (%p)", type_enum); return qeoType; } json_t *values = json_object_get(typedesc, KEY_VALUES); if ((NULL == values) || !json_is_object(values)) { qeo_log_e("Invalid values (%p)", values); return qeoType; } enumstr = json_string_value(type_enum); //Replace all "::" with ".", because there's a mismatch in topic definitions found in the TSM structs, with "." and the QDM topic definitions with "::" find_and_replace((char *) enumstr, "::", "."); if ((ddsret = dds_seq_require(&vals, json_object_size(values))) != DDS_RETCODE_OK){ qeo_log_e("dds_seq_require failed (%d)", ddsret); return NULL; } void *iter = json_object_iter(values); while (iter) { json_int_t labelint; const char *name = json_object_iter_key(iter); json_t *label = json_object_iter_value(iter); if (!json_is_integer(label)){ qeo_log_e("not a integer"); } labelint = json_integer_value(label); if (labelint >= json_object_size(values)){ qeo_log_e("Currently we only support 0,1,2..[n-1] as labels"); break; } DDS_SEQ_ITEM(vals, labelint).name = (char *)name; iter = json_object_iter_next(values, iter); } qeoType = qeocore_type_enum_new(enumstr, &vals); if (qeoType == NULL){ qeo_log_e("Cannot register enum"); } dds_seq_cleanup(&vals); } while(0); return qeoType; }
void algorithm_page_name::load_names() { if (!config_ || loaded_) return; bool is_crosslink_table = false; string filename(config_->get_value("titles_file")); if (filename.length() <= 0) { filename = ltw_task_->get_system_config()->get_value("titles_file"); if (filename.length() <= 0) { filename = ltw_task_->get_system_config()->get_value("crosslink_table"); is_crosslink_table = true; } } if (filename.length() <= 0) return; ifstream myfile (filename.c_str()); cerr << "loading file " << filename << endl; int count = 0; if (myfile.is_open()) { while (! myfile.eof()) { string line; getline (myfile, line); if (line.length() == 0 || line.find("Portal:") != string::npos) continue; #ifdef DEBUG if ((count % 5000) == 0) { cerr << "#" << count << ", loading : " << line << endl; } #endif string::size_type pos; pos = line.find_first_of(':'); // if (is_crosslink_table) // pos = line.find(':', ++pos); if (pos != string::npos) { unsigned long doc_id; string wiki_title; doc_id = atol(line.c_str() + pos + 1); if (!is_crosslink_table) { /* * Not gonna check it */ // if (!corpus::instance().exist(doc_id)) // continue; wiki_title = string(line, 0, pos); } else { pos = line.find(':', ++pos); wiki_title = string(line, ++pos); } if (use_utf8_token_matching_ && strchr(wiki_title.c_str(), ' ') != NULL) find_and_replace(wiki_title, string(" "), string("")); std::pair<std::string, std::string> title_pair = wikipedia::process_title(wiki_title, 1/*, !use_utf8_token_matching_*/); //struct wiki_entry a_entry; ANT_link_posting *a_entry = new ANT_link_posting; a_entry->docid = doc_id; a_entry->desc = strdup(title_pair.second.c_str()); a_entry->offset = 0; a_entry->link_frequency = 1; a_entry->doc_link_frequency = 1; //a_entry.id = doc_id; //a_entry.title = title_pair.first; //a_entry.description = title_pair.second; // page_map_t::iterator iter = names_map_.find(title_pair.first); ANT_link_term *index_term = this->find_term_in_list(title_pair.first.c_str()); if (index_term == NULL || string_compare(index_term->term, title_pair.first.c_str(), lowercase_only, use_utf8_token_matching_) != 0) { // if (iter == names_map_.end() || iter->second == NULL) { //wiki_entry_array wea; // if (index_term != NULL) // cerr << title_pair.first << " is a unique term to " << index_term->term << endl; ANT_link_term *term = new ANT_link_term; term->term = strdup(title_pair.first.c_str()); term->total_occurences = 0; term->document_frequency = 9999; term->collection_frequency = 9999; // string& name = title_pair.first; // if (iter != names_map_.end() && iter->second == NULL) // iter->second = term; // else // iter = names_map_.insert(make_pair(name, term)).first; // string::size_type pos = name.find(' '); // if (pos != string::npos) { // string first_term(name, 0, pos); // page_map_t::iterator iner_iter = names_map_.find(first_term); // if (iner_iter == names_map_.end()) // names_map_.insert(make_pair(first_term, (ANT_link_term *)NULL)); // // else // // cerr << "found a match (" << iner_iter->first << ")" << endl; // } //result.second.push_back(a_entry); term->postings.push_back(a_entry); name_array_.push_back(term); ++count; } else { index_term->postings.push_back(a_entry); } } else { cerr << "Error in line : " << line << endl; } // cout << line << endl; } // std::sort(name_array_.begin(), name_array_.end(), ANT_link_term_compare()); myfile.close(); cerr << "loaded " << name_array_.size() << " entries, " << count << " recored" << endl; } // debug // page_map_t::iterator iter = names_map_.begin(); // while (iter != names_map_.end()) { // if (iter->second != NULL) // for (int i = 0; i < iter->second->postings.size(); i++) // cerr << iter->second->postings[i]->docid << ":" // << iter->first << "(" << iter->second->postings[i]->desc << ")" << endl; // else // cerr << "found a match (" << iter->first << ") for the easy indexing" << endl; // ++iter; // } loaded_ = true; }
void SqliteDao::EscapeSingleQuote(string &target){ find_and_replace(target, "'", "''"); }
// FIXME: name makes it look like a Qt-style getter void BootStrap::xmlentities( std::wstring &input ) { find_and_replace( input, m_replacementMap ); }