void ViCommandMode::execute_search(const Glib::ustring &cmd, char begin ) { // // /{pattern}/{offset}<CR> // search forward for the [count]'th occurrence of // {pattern} and go {offset} lines up or down. // int count = 1; int offset = 0; Glib::ustring pattern; int idx = cmd.find( begin ); if (idx > 0) { Glib::ustring rest = cmd.substr(idx+1); offset = convert<int>(rest); pattern = cmd.substr(0, idx); } else { pattern = cmd; } Direction dir = Forward; if (begin == '?') dir = Backward; g_print("Searching for %s with offset %i\n", pattern.data(), offset); Editor *ed = Application::get()->get_current_editor(); ed->search(pattern, dir); }
/** get a string composed of elements separated by personnal separator, and return in vector * each element */ int mini_parser(char separator, Glib::ustring str, std::vector<string>* vector ) { int res = - 1 ; vector->clear() ; guint last = 0 ; bool cut = false ; if (str!="") { for (guint i=0; i<str.size(); i++) { if ( str[i]==separator ) { cut = true ; vector->insert(vector->end(), str.substr(last,i-last) ); last=i+1 ; } } if (cut) vector->insert(vector->end(), str.substr(last,str.size()-1) ); else vector->insert(vector->end(), str.substr(last,str.size()) ); res = 1 ; } else { Log::err() << "mini_parser <information:> no string value" << std::endl ; } return res ; }
/** * Get the full path, directory, and base file name of this running executable */ bool RegistryTool::getExeInfo(Glib::ustring &fullPath, Glib::ustring &path, Glib::ustring &exeName) { char buf[MAX_PATH+1]; if (!GetModuleFileName(NULL, buf, MAX_PATH)) { fprintf(stderr, "Could not fetch executable file name\n"); return false; } else { //printf("Executable file name: '%s'\n", buf); } fullPath = buf; path = ""; exeName = ""; Glib::ustring::size_type pos = fullPath.rfind('\\'); if (pos != fullPath.npos) { path = fullPath.substr(0, pos); exeName = fullPath.substr(pos+1); } return true; }
// XML backend helper: Split the path into a node key and an attribute key. void Preferences::_keySplit(Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key) { // everything after the last slash attr_key = pref_path.substr(pref_path.rfind('/') + 1, Glib::ustring::npos); // everything before the last slash node_key = pref_path.substr(0, pref_path.rfind('/')); }
int checkStringOffset(Glib::ustring str, int toffset) { //-- Empty string if (str.empty() || StringOps(str).trim().empty()) return -1 ; //-- Before text if (toffset <= 0) return 0 ; //-- After text else if (toffset >= (str.length()-1) ) return 1 ; else { const Glib::ustring& tmpBefore = str.substr(0, toffset) ; const Glib::ustring& tmpAfter = str.substr(toffset, str.length()-1) ; StringOps tmpB(tmpBefore) ; StringOps tmpAft(tmpAfter) ; //-- Before is only spaces, it's before text :) if (tmpB.trim(" \n").empty()) return 0 ; //-- After is only spaces, it's after text :) else if (tmpAft.trim(" \n").empty()) return 1 ; //-- Otherwise it's middle :) else return 2 ; } }
void rise::parser::on_start_element(const Glib::ustring &_name, const AttributeList &_attributes) { Glib::ustring prefix, name = _name; auto pos = _name.find(':'); if(pos != Glib::ustring::npos) { prefix = _name.substr(0, pos); name = _name.substr(pos + 1); } auto *el = doc.get_root_node(); if(!el) el = doc.create_root_node(); else el = context.top()->add_child(name, prefix); context.push(el); for(auto itr = _attributes.begin(); itr != _attributes.end(); ++itr) { Glib::ustring name = itr->name; Glib::ustring value = itr->value; auto pos = name.find(':'); if(pos == Glib::ustring::npos) { if(name == "xmlns") el->set_namespace_declaration(value); else el->set_attribute(name, value); } else { Glib::ustring prefix = name.substr(0, pos); Glib::ustring suffix = name.substr(pos + 1); if(prefix == "xmlns") el->set_namespace_declaration(value, suffix); else el->set_attribute(suffix, value, prefix); } } }
/* * Ellipse text if longer than maxlen, "50% start text + ... + ~50% end text" * Text should be > length 8 or just return the original text */ Glib::ustring gr_ellipsize_text(Glib::ustring const &src, size_t maxlen) { if (src.length() > maxlen && maxlen > 8) { size_t p1 = (size_t) maxlen / 2; size_t p2 = (size_t) src.length() - (maxlen - p1 - 1); return src.substr(0, p1) + "…" + src.substr(p2); } return src; }
equation* mainWindow::createEqFromStr(Glib::ustring str) { Gtk::MessageDialog tempDialog(*this, "Error!"); unsigned int equalPos = commandLine->get_text().find("="); //check for = sign else give a error if(equalPos > 2000000000) { tempDialog.set_secondary_text("No \"=\" found"); tempDialog.run(); return 0; }else{ //Now substring the str form equalPos Glib::ustring leftSide = str.substr(0, equalPos); //now find the function variable unsigned int firstBrace = leftSide.find("("); //if this is zero, no function name is given. if(firstBrace == 0) { tempDialog.set_secondary_text("No function name is given"); tempDialog.run(); return 0; }else{ //if ( is not found error if(firstBrace > 2000000000) { tempDialog.set_secondary_text("Missing \"(\" in function name"); tempDialog.run(); return 0; } Glib::ustring afterBrace = leftSide.substr(firstBrace); if(afterBrace.length() != 3) { tempDialog.set_secondary_text("Syntax error in variable name"); tempDialog.run(); return 0; } Glib::ustring variableName = afterBrace.substr(1,1); Glib::ustring functionName = leftSide.substr(0, firstBrace); Glib::ustring rightSide = str.substr(equalPos+1); equation *tempEq = new equation(); tempEq->setName(functionName); tempEq->setEquation(rightSide); tempEq->setVariable(variableName); return tempEq; } } }
int mainWindow::callFunc(Glib::ustring str) { Gtk::MessageDialog tempDialog(*this, "Error!"); unsigned int leftBrace = str.find("("); unsigned int rightBrace = str.find(")"); if(leftBrace > 2000000000) { tempDialog.set_secondary_text("Missing \"(\""); tempDialog.run(); return SYNTAX_ERROR; }else if(rightBrace > 2000000000){ tempDialog.set_secondary_text("Missing \")\""); tempDialog.run(); return SYNTAX_ERROR; }else if(leftBrace > rightBrace){ tempDialog.set_secondary_text("Syntax error near )"); tempDialog.run(); return SYNTAX_ERROR; }else if(leftBrace == 0){ tempDialog.set_secondary_text("No function name given"); tempDialog.run(); return SYNTAX_ERROR; }else{ Glib::ustring funcName = str.substr(0, leftBrace); Glib::ustring rawArg = str.substr(leftBrace+1, rightBrace-leftBrace-1); if(funcName == "del") { if(this->eqView->removeByName(rawArg) == false) { tempDialog.set_secondary_text("No function by that name!"); tempDialog.run(); } return FUNC_HANDLED; }else{ if(this->eqView->getEqByName(funcName)) { equation *tmpEq = this->eqView->getEqByName(funcName); double number = strtod(rawArg.c_str(),NULL); number = tmpEq->getYFromX(number); char buffer[600]; sprintf(buffer,"%f",number); tempDialog.set_secondary_text(buffer); tempDialog.run(); }else{ return FUNC_NOT_FOUND; } } } }
/* * Try to guess the DOI of the paper from the raw text */ void BibData::guessDoi (Glib::ustring const &graw) { std::string const &raw = graw; boost::regex expression( "\\(?" "(?:" "(?:[Dd][Oo][Ii]:? *)" "|" "(?:[Dd]igital *[Oo]bject *[Ii]denti(?:fi|ямБ)er:? *)" ")" "(" "[^\\.\\s]+" "\\." "[^\\/\\s]+" "\\/" "[^\\s]+" ")" ); std::string::const_iterator start, end; start = raw.begin(); end = raw.end(); boost::match_results<std::string::const_iterator> what; boost::match_flag_type flags = boost::match_default; while(regex_search(start, end, what, expression, flags)) { Glib::ustring wholeMatch = std::string(what[0]); Glib::ustring gstr = std::string(what[1]); // Special case to chop off trailing comma to deal with // "doi: foo, available online" in JCompPhys // Note that commas ARE legal suffix characters in Doi spec // But there's nothing in the spec about regexing them // out of PDFS :-) -jcs if (gstr[gstr.size() - 1] == ',') { gstr = gstr.substr (0, gstr.size() - 1); }; /* * Special case to chop off trailing parenthesis * in (doi:foo.foo/bar) case */ if (wholeMatch[0] == '(' && wholeMatch[wholeMatch.size() - 1] == ')') { gstr = gstr.substr (0, gstr.size() - 1); } setDoi (gstr); return; } }
void Document::renameFromKey () { if (getFileName().empty () || getKey().empty ()) return; Glib::RefPtr<Gio::File> oldfile = Gio::File::create_for_uri(getFileName()); Glib::ustring shortname = oldfile->query_info()->get_display_name(); DEBUG ("Shortname = %1", shortname); Glib::RefPtr<Gio::File> parentdir = oldfile->get_parent(); Glib::ustring::size_type pos = shortname.rfind ("."); Glib::ustring extension = ""; if (pos != Glib::ustring::npos) extension = shortname.substr (pos, shortname.length() - 1); Glib::ustring newfilename = getKey() + extension; DEBUG ("Newfilename = %1", newfilename); Glib::RefPtr<Gio::File> newfile = parentdir->get_child(newfilename); try { oldfile->move(newfile); setFileName (newfile->get_uri ()); } catch (Gio::Error &ex) { Utility::exceptionDialog (&ex, String::ucompose (_("Moving '%1' to '%2'"), oldfile->get_uri (), newfile->get_uri ()) ); } }
bool Document::matchesSearch (Glib::ustring const &search) { /* This is a bit of a hack, I guess, but it's a low-impact way of * implementing the change. If the search term contains a space, I * iteratively decompose it into substrings and pass those onto * this function. If anything doesn't match, we return a failure. */ if (search.find(' ') != Glib::ustring::npos) { Glib::ustring::size_type p1 = 0; Glib::ustring::size_type p2; do { /* Find the next space in the string, if any. */ p2 = search.find(' ', p1); /* Extract the appropriate substring. */ Glib::ustring const searchTerm = search.substr(p1, p2); /* If the term is empty, ignore it and move on. It might just be a * trailing or duplicate space character. */ if (searchTerm.empty()) { break; } /* Now that we have the substring, which is guaranteed to be * free of spaces, we can pass it recursively into this function. * If the term does NOT match, fail the entire comparison right away. */ if (!matchesSearch(searchTerm)) { return false; } p1 = p2 + 1; /* +1 to skip over the space */ } while (p2 != Glib::ustring::npos); /* Terminate at end of string */ return true; /* All matched, so OK. */ } Glib::ustring const searchNormalised = search.casefold(); FieldMap fields = getFields (); FieldMap::iterator fieldIter = fields.begin (); FieldMap::iterator const fieldEnd = fields.end (); for (; fieldIter != fieldEnd; ++fieldIter) { if (fieldIter->second.casefold().find(searchNormalised) != Glib::ustring::npos) return true; } if (notes_.casefold().find(searchNormalised) != Glib::ustring::npos) return true; if (key_.casefold().find(searchNormalised) != Glib::ustring::npos) return true; return false; }
bool bHasSuffix(const Glib::ustring & _rsString, const Glib::ustring & _rsSuffix, bool _bCaseSensitive) { if (_rsSuffix.size() > _rsString.size()) { return false; } Glib::ustring sEnd = _rsString.substr(_rsString.size() - _rsSuffix.size()); if (_bCaseSensitive) { if (_rsSuffix == sEnd) { return true; } } else { if (_rsSuffix.lowercase() == sEnd.lowercase()) { return true; } } return false; }
void ViCommandMode::execute(const Glib::ustring &cmd) { add_history( cmd ); char ch = cmd[0]; Glib::ustring rest = cmd.substr(1); if (ch == '/') { // // Forward search // execute_search(rest, ch); } else if (ch == '?') { // // Backward search // execute_search(rest, ch); } else if (ch == ':') { execute_command(rest); } }
void FORMATEAR(Gtk::Entry* entry) { Glib::ustring texto = entry->get_text(); Glib::ustring primera_letra = texto.substr(0, 1); primera_letra = primera_letra.uppercase(); texto.replace(0, 1, primera_letra); entry->set_text(texto); }
static Glib::ustring fixup_suffix(const Glib::ustring& uri) { // Add .fmp extension automatically if not provided. size_t len = uri.length(); if (len >= 4 && (uri.substr(len - 4) != ".fmp")) return uri + ".fmp"; else return uri; }
void ViCommandMode::map_key( const Glib::ustring &widget_type, const Glib::ustring &key, ExecutableAction *a ) { if (key[0] == ':') m_commandMap[key.substr(1)] = a; else m_keyMap[key] = a; }
Glib::ustring NoteDirectoryWatcherApplicationAddin::get_id(const Glib::ustring & path) { Glib::ustring dir_separator; dir_separator += G_DIR_SEPARATOR; int last_slash = sharp::string_last_index_of(path, dir_separator); int first_period = path.find(".", last_slash); return path.substr(last_slash + 1, first_period - last_slash - 1); }
void UIManager::addLocalBitmapsAsIconFactory() { // Destination Gtk::IconFactory _iconFactory = Gtk::IconFactory::create(); // Iterate over each file in the bitmaps dir std::string bitmapsPath = GlobalRegistry().get(RKEY_BITMAPS_PATH) + "/"; Glib::Dir bitmapsDir(bitmapsPath); for (Glib::DirIterator i = bitmapsDir.begin(); i != bitmapsDir.end(); ++i) { Glib::ustring filename = *i; // Skip directories if (Glib::file_test(bitmapsPath + filename, Glib::FILE_TEST_IS_DIR)) { continue; } // Load the pixbuf into an IconSet try { Gtk::IconSet is( Gdk::Pixbuf::create_from_file(bitmapsPath + filename) ); // Add IconSet to Factory with "darkradiant:" stock prefix Glib::ustring filenameWithoutExtension = filename.substr( 0, filename.rfind(".") ); Gtk::StockID stockID( Glib::ustring::compose( "darkradiant:%1", filenameWithoutExtension ) ); _iconFactory->add(stockID, is); } catch (Gdk::PixbufError& ex) { rWarning() << "Could not load pixbuf from file: " << filename << ": " << ex.what() << std::endl; } catch (Glib::FileError& ex) { rWarning() << "Could not load pixbuf from file: " << filename << ": " << ex.what() << std::endl; } } // Add the IconFactory to the default factory list _iconFactory->add_default(); }
Glib::ustring PluginManager::findDataFile (Glib::ustring const file) { std::vector<Glib::ustring>::iterator it = pythonPaths_.begin (); std::vector<Glib::ustring>::iterator const end = pythonPaths_.end (); for (; it != end; ++it) { Glib::ustring filename = Glib::build_filename (*it, file); if (filename.substr(0,2) == Glib::ustring ("./")) { filename = Glib::get_current_dir () + filename.substr (1, filename.length()); } Glib::RefPtr<Gio::File> uri = Gio::File::create_for_path (filename); DEBUG ("Trying %1", filename); if (uri->query_exists ()) return filename; } return Glib::ustring (); }
Glib::ustring Configuration::get_name_from_path(const Glib::ustring& path) { Glib::ustring name; Glib::ustring::size_type p = path.rfind("/"); if(p == Glib::ustring::npos) { name = path; } else { name = path.substr(p+1); } return name; }
/** * Set the string value of a key/name registry entry */ bool RegistryTool::setStringValue(const Glib::ustring &keyNameArg, const Glib::ustring &valueName, const Glib::ustring &value) { Glib::ustring keyName = keyNameArg; bool ret = false; HKEY rootKey = HKEY_LOCAL_MACHINE; //default root //Trim out the root key if necessary for (KeyTableEntry *entry = keyTable; entry->key; entry++) { if (keyName.compare(0, entry->strlen, entry->str)==0) { rootKey = entry->key; keyName = keyName.substr(entry->strlen); } } //printf("trimmed string: '%s'\n", keyName.c_str()); //Get or create the key gunichar2 *keyw = g_utf8_to_utf16(keyName.data(), -1, 0,0,0); gunichar2 *valuenamew = g_utf8_to_utf16(valueName.data(), -1, 0,0,0); HKEY key; if (RegCreateKeyExW(rootKey, (WCHAR*) keyw, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL)) { fprintf(stderr, "RegistryTool: Could not create the registry key '%s'\n", keyName.c_str()); goto fail; } // Set the value if (RegSetValueExW(key, (WCHAR*) valuenamew, 0, REG_SZ, (LPBYTE) value.data(), (DWORD) (value.size() + 1))) { fprintf(stderr, "RegistryTool: Could not set the value '%s'\n", value.c_str()); goto failkey; } ret = true; failkey: RegCloseKey(key); fail: g_free(keyw); g_free(valuenamew); return ret; }
/** * Get the full path, directory, and base file name of this running executable */ bool RegistryTool::getExeInfo(Glib::ustring &fullPath, Glib::ustring &path, Glib::ustring &exeName) { const int pathbuf = 2048; gunichar2 pathw[pathbuf]; GetModuleFileNameW(NULL, (WCHAR*) pathw, pathbuf); gchar *utf8path = g_utf16_to_utf8(pathw, -1, 0,0,0); fullPath = utf8path; g_free(utf8path); path = ""; exeName = ""; Glib::ustring::size_type pos = fullPath.rfind('\\'); if (pos != fullPath.npos) { path = fullPath.substr(0, pos); exeName = fullPath.substr(pos+1); } return true; }
void tokenizeWords(const Glib::ustring& str, std::vector<Glib::ustring>& container) { ustring::size_type lastPos = str.find_first_not_of(' ', 0); ustring::size_type pos = str.find_first_of(' ', lastPos); while (ustring::npos != pos || ustring::npos != lastPos) { container.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(' ', pos); pos = str.find_first_of(' ', lastPos); } }
void strTo(const Glib::ustring& p_str, T p_out){ int l_pos; unsigned int l_oldpos; std::stringstream l_str; Q l_ret; // Si la cadena no contiene nada, terminamos if(p_str.size() == 0) return; // Puntero de cabecera y cola en la cadena l_oldpos = 0; l_pos = p_str.find("," , 0); // Si hay cadenas while(l_pos > -1){ // Convertimos y añadimos la substring l_str.clear(); l_str << p_str.substr(l_oldpos, l_pos - l_oldpos).c_str(); l_str >> l_ret; *p_out++ = l_ret; // Saltamos , o ", " if(p_str[l_pos + 1] == ' ') l_oldpos = l_pos + 2; else l_oldpos = l_pos + 1; // Buscamos la siguiente "," l_pos = p_str.find("," , l_oldpos); } if(l_oldpos != p_str.size()){ // Convertimos y añadimos la substring l_str.clear(); l_str << p_str.substr(l_oldpos, p_str.size()).c_str(); l_str >> l_ret; *p_out = l_ret; }
virtual void on_end_element ( Glib::Markup::ParseContext& context, const Glib::ustring& element) { if (Glib::str_has_prefix (text_, "<![CDATA[") && Glib::str_has_suffix (text_, "]]>")) { text_ = text_.substr (strlen ("<![CDATA["), text_.length () - strlen ("<![CDATA[" "]]>")); } if (element == "doi") { bib_.setDoi (text_); } else if (element == "article_title") { bib_.setTitle (text_); /* FIXME: assuming given_name precedes surname */ } else if (element == "given_name") { given_name_ = text_; } else if (element == "surname") { if (!given_name_.empty()) { text_ = text_ + ", " + given_name_; given_name_ = ""; } authors_.push_back (text_); } else if (element == "journal_title") { bib_.setJournal (text_); } else if (element == "volume") { bib_.setVolume (text_); } else if (element == "issue") { bib_.setIssue (text_); } else if (element == "first_page") { bib_.setPages (text_); } else if (element == "year") { bib_.setYear (text_); } else if (element == "volume_title") { bib_.addExtra ("BookTitle", text_); } else if (element == "body") { /* End of entry */ Glib::ustring authorString; std::vector<Glib::ustring>::iterator it = authors_.begin (); for (; it != authors_.end(); ++it) { if (it != authors_.begin()) { authorString += " and "; } authorString += *it; } if (!authorString.empty()) bib_.setAuthors (authorString); } }
void ViCommandMode::execute_command(const Glib::ustring &cmd_line) { // TODO: more intelligent parsing Glib::ustring cmd; int idx = cmd_line.find_first_of(' '); if (idx > 0) { m_cmd_params = cmd_line.substr(idx+1); cmd = cmd_line.substr(0, idx); } else { cmd = cmd_line; m_cmd_params = ""; } g_print("Command %s with params '%s'\n", cmd.data(), m_cmd_params.data()); ExecutableAction *act = m_commandMap[cmd]; if (act) { act->execute(); } }
unsigned long XGPacketBuilder::parse_number(Glib::ustring str) { unsigned long l = 0; size_t n = str.find("0x"); if (n != std::string::npos) { l = std::strtol(str.substr(n).c_str(), 0, 16); } else { l = std::strtol(str.c_str(), 0, 10); } return l; }
typename TrieHit<value_t>::ListPtr find_matches (const Glib::ustring & haystack) { TrieStatePtr current_state = m_root; typename TrieHit<value_t>::ListPtr matches( new typename TrieHit<value_t>::List()); int start_index = 0; for (Glib::ustring::size_type i = 0; i < haystack.size(); i++) { gunichar c = haystack[i]; if (!m_case_sensitive) c = Glib::Unicode::tolower(c); if (current_state == m_root) start_index = i; // While there's no matching transition, follow the fail states // Because we're potentially changing the depths (aka length of // matched characters) in the tree we're updating the start_index // accordingly while ((current_state != m_root) && 0 == find_state_transition(current_state, c)) { TrieStatePtr old_state = current_state; current_state = current_state->fail_state(); start_index += old_state->depth() - current_state->depth(); } current_state = find_state_transition (current_state, c); if (0 == current_state) current_state = m_root; // If the state contains a payload: We've got a hit // Return a TrieHit with the start and end index, the matched // string and the payload object if (current_state->payload_present()) { int hit_length = i - start_index + 1; typename TrieHit<value_t>::Ptr hit( new TrieHit<value_t>(start_index, start_index + hit_length, haystack.substr(start_index, hit_length), current_state->payload())); matches->push_back(hit); } } return matches; }
inline Glib::ustring apply_filename_macros(Glib::ustring filename) { //TODO: allow the following two macros only in the game itself: str_replace_all_with(filename, "$(ui-menu-icon-path)", "$(exe-share)/ui/icons/48"); str_replace_all_with(filename, "$(ui-icon-path)", "$(exe-share)/ui/icons"); str_replace_all_with(filename, "$(exe-share)", "$(exe-prefix)/share/$(app-name)"); str_replace_all_with(filename, "$(test-references)", "$(local-folder)/test-references"); str_replace_all_with(filename, "$(tmp)", "$(local-folder)/temp"); str_replace_all_with(filename, "$(local-folder)", Private::Base::local_folder); str_replace_all_with(filename, "$(appdata)", Private::Base::path_appdata); if(filename[0]=='~') filename = "$(home)"+filename.substr(1, filename.length()-1); str_replace_all_with(filename, "$(home)", Private::Base::path_home); str_replace_all_with(filename, "$(exe-prefix)", Private::Base::path_exe_prefix); str_replace_all_with(filename, "$(exe-filename)", Private::Base::path_exe_filename); str_replace_all_with(filename, "$(app-name)", Private::Base::app_name); return filename; }