String strutil_findurl(String& str, String& url) { static URLDetector s_detector; // the return value: the part of the text before the URL String before; int len; int pos = s_detector.FindURL(str, len); if ( pos == -1 ) { // no URLs found str.swap(before); str.clear(); url.clear(); } else // found an URL { before = str.substr(0, pos); url = str.substr(pos, len); str.erase(0, pos + len); } return before; }
void FrameFactory::updateGenre(TextIdentificationFrame *frame) const { StringList fields = frame->fieldList(); StringList newfields; for(StringList::Iterator it = fields.begin(); it != fields.end(); ++it) { String s = *it; int end = s.find(")"); if(s.startsWith("(") && end > 0) { // "(12)Genre" String text = s.substr(end + 1); bool ok; int number = s.substr(1, end - 1).toInt(&ok); if(ok && number >= 0 && number <= 255 && !(ID3v1::genre(number) == text)) newfields.append(s.substr(1, end - 1)); if(!text.isEmpty()) newfields.append(text); } else { // "Genre" or "12" newfields.append(s); } } if(newfields.isEmpty()) fields.append(String::null); frame->setText(newfields); }
bool getNthToken (const String & str, const size_t n, size_t & pos, size_t & endpos, String & token, const unicode_char_t * sepChars) { size_t desired_first_nonspace = 0; size_t space = 0; //check for trivial case if(n == 0) desired_first_nonspace = pos; else { for (size_t i = 0; i < n; ++i) { //find the first whitespace character space = str.find_first_of ( sepChars, pos ); if (space == std::string::npos) return false; //now find the next non-whitespace character after it desired_first_nonspace = str.find_first_not_of( sepChars, space ); if (desired_first_nonspace == std::string::npos) return false; pos = desired_first_nonspace; } } //find the end of the token const size_t first_space = str.find_first_of (sepChars, desired_first_nonspace ); //now get that token if (first_space != std::string::npos) token = str.substr (desired_first_nonspace, first_space - desired_first_nonspace); else token = str.substr (desired_first_nonspace); endpos = desired_first_nonspace; return true; }
bool Path::CreateDirRecursive(String path) { String path1; while(!path.empty()) { String segment = path; size_t offset = path.find(Path::sep); if(offset != -1) { segment = path.substr(0, offset); if(path.size() > (offset + 1)) path = path.substr(offset + 1); else path.clear(); } else { path.clear(); } if(!path1.empty()) path1 += Path::sep; path1 += segment; // Create if not existing if(IsDirectory(path1) || path1.empty()) continue; if(!CreateDir(path1)) return false; } return true; }
/** * @return path of parent directory, ending with a slash. * Returns empty string on error. */ static String FileGetParentDirectory(const String& fullPath) { String path = fullPath; // Get path to parent directory. // The path name may end with a slash. char lastChar = path[path.size() - 1]; if (lastChar == '/') { // In this case, strip off the ending slash. path = path.substr(0, path.size() - 1); } // Get last slash. int pos = path.findLastOf('/'); if (String::npos == pos) { return ""; } lprintfln("@@@@@@@ FileGetParentDirectory: %s", (path.substr(0, pos + 1)).c_str()); // Return parent path, including the slash. return path.substr(0, pos + 1); }
void EditorHelp::_class_desc_select(const String& p_select) { // print_line("LINK: "+p_select); if (p_select.begins_with("#")) { //_goto_desc(p_select.substr(1,p_select.length())); emit_signal("go_to_help","class_name:"+p_select.substr(1,p_select.length())); return; } else if (p_select.begins_with("@")) { String m = p_select.substr(1,p_select.length()); if (m.find(".")!=-1) { //must go somewhere else emit_signal("go_to_help","class_method:"+m.get_slice(".",0)+":"+m.get_slice(".",0)); } else { if (!method_line.has(m)) return; class_desc->scroll_to_line(method_line[m]); } } }
void AnimationPlayerEditor::_file_selected(String p_file) { ERR_FAIL_COND(!player); Ref<Resource> res = ResourceLoader::load(p_file,"Animation"); ERR_FAIL_COND(res.is_null()); ERR_FAIL_COND( !res->is_type("Animation") ); if (p_file.find_last("/")!=-1) { p_file=p_file.substr( p_file.find_last("/")+1, p_file.length() ); } if (p_file.find_last("\\")!=-1) { p_file=p_file.substr( p_file.find_last("\\")+1, p_file.length() ); } if (p_file.find(".")!=-1) p_file=p_file.substr(0,p_file.find(".")); undo_redo->create_action("Load Animation"); undo_redo->add_do_method(player,"add_animation",p_file,res); undo_redo->add_undo_method(player,"remove_animation",p_file); if (player->has_animation(p_file)) { undo_redo->add_undo_method(player,"add_animation",p_file,player->get_animation(p_file)); } undo_redo->add_do_method(this,"_animation_player_changed",player); undo_redo->add_undo_method(this,"_animation_player_changed",player); undo_redo->commit_action(); }
RenderWindow* GTKGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) { if (autoCreateWindow) { ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); if (opt == mOptions.end()) OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find full screen options!", "GTKGLSupport::createWindow"); bool fullscreen = (opt->second.currentValue == "Yes"); opt = mOptions.find("Video Mode"); if (opt == mOptions.end()) OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find video mode options!", "GTKGLSupport::createWindow"); String val = opt->second.currentValue; String::size_type pos = val.find('x'); if (pos == String::npos) OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid Video Mode provided", "GTKGLSupport::createWindow"); unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); return renderSystem->createRenderWindow(windowTitle, w, h, 32, fullscreen); } else { // XXX What is the else? return NULL; } }
//----------------------------------------------------------------------------// RenderedString DefaultRenderedStringParser::parse( const String& input_string, const Font* initial_font, const ColourRect* initial_colours) { RenderedString rs; size_t epos, spos = 0; while ((epos = input_string.find('\n', spos)) != String::npos) { appendSubstring(rs, input_string.substr(spos, epos - spos), initial_font, initial_colours); rs.appendLineBreak(); // set new start position (skipping the previous \n we found) spos = epos + 1; } if (spos < input_string.length()) appendSubstring(rs, input_string.substr(spos), initial_font, initial_colours); return rs; }
//----------------------------------------------------------------------- void DynLib::load() { // Log library load LogManager::getSingleton().logMessage("Loading library " + mName); String name = mName; #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_NACL // dlopen() does not add .so to the filename, like windows does for .dll if (name.find(".so") == String::npos) name += ".so"; #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE // dlopen() does not add .dylib to the filename, like windows does for .dll if (name.substr(name.length() - 6, 6) != ".dylib") name += ".dylib"; #elif OGRE_PLATFORM == OGRE_PLATFORM_WIN32 // Although LoadLibraryEx will add .dll itself when you only specify the library name, // if you include a relative path then it does not. So, add it to be sure. if (name.substr(name.length() - 4, 4) != ".dll") name += ".dll"; #endif mInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() ); if( !mInst ) OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, "Could not load dynamic library " + mName + ". System Error: " + dynlibError(), "DynLib::load" ); }
FileName FileName::removeBlockName() const { size_t first = rfind(AT); if (first != npos) { String block = substr(0, first); size_t second = block.find(COMMA); if (second == npos) { if (!isdigit(block[0])){ return substr(first + 1); } } else { String prefix = block.substr(0, second); block = block.substr(second + 1); if (!isdigit(block[0])) return prefix + substr(first); } } return *this; }
//----------------------------------------------------------------------- StringVector StringUtil::split( const String& str, const String& delims, unsigned int maxSplits, bool preserveDelims) { StringVector ret; // Pre-allocate some space for performance ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case unsigned int numSplits = 0; // Use STL methods size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); if(preserveDelims) { // Sometimes there could be more than one delimiter in a row. // Loop until we don't find any more delims size_t delimStart = pos, delimPos; delimPos = str.find_first_not_of(delims, delimStart); if (delimPos == String::npos) { // Copy the rest of the string ret.push_back( str.substr(delimStart) ); } else { ret.push_back( str.substr(delimStart, delimPos - delimStart) ); } } start = pos + 1; } // parse up to next real data start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
// FIXME method naming String GetPerServerString(const String& orig, const ServerID& sid) { int32 dot_pos = orig.rfind("."); String prefix = orig.substr(0, dot_pos); String ext = orig.substr(dot_pos+1); char buffer[1024]; sprintf(buffer, "%s-%04d.%s", prefix.c_str(), (uint32)sid, ext.c_str()); return buffer; }
static bool HHVM_FUNCTION(putenv, const String& setting) { int pos = setting.find('='); if (pos >= 0) { String name = setting.substr(0, pos); String value = setting.substr(pos + 1); g_context->setenv(name, value); return true; } return false; }
bool GTKGLSupport::checkMinGLVersion(const String& v) const { int major, minor; Gdk::GL::query_version(major, minor); std::string::size_type pos = v.find("."); int cmaj = atoi(v.substr(0, pos).c_str()); int cmin = atoi(v.substr(pos + 1).c_str()); return ( (major >= cmaj) && (minor >= cmin) ); }
explicit SpaceObjectReference(const String& humanReadable) { String::size_type where=humanReadable.find(":"); if (where==String::npos) { mObject=ObjectReference::null(); mSpace=SpaceID::null(); throw std::invalid_argument("Unable to find colon separator in SpaceObjectReference"); } else { mSpace=SpaceID(humanReadable.substr(0,where)); mObject=ObjectReference(humanReadable.substr(where+1)); } }
//-------------------------------------------------------------------------------------------------// RenderWindow* GLXGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) { RenderWindow *window = 0; if (autoCreateWindow) { ConfigOptionMap::iterator opt; ConfigOptionMap::iterator end = mOptions.end(); NameValuePairList miscParams; bool fullscreen = false; uint w = 800, h = 600; if((opt = mOptions.find("Full Screen")) != end) fullscreen = (opt->second.currentValue == "Yes"); if((opt = mOptions.find("Display Frequency")) != end) miscParams["displayFrequency"] = opt->second.currentValue; if((opt = mOptions.find("Video Mode")) != end) { String val = opt->second.currentValue; String::size_type pos = val.find('x'); if (pos != String::npos) { w = StringConverter::parseUnsignedInt(val.substr(0, pos)); h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); } } if((opt = mOptions.find("FSAA")) != end) miscParams["FSAA"] = opt->second.currentValue; if((opt = mOptions.find("VSync")) != end) miscParams["vsync"] = opt->second.currentValue; if((opt = mOptions.find("sRGB Gamma Conversion")) != end) miscParams["gamma"] = opt->second.currentValue; #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS opt = mOptions.find("Fixed Pipeline Enabled"); if (opt == mOptions.end()) OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Can't find Fixed Pipeline enabled options!", "Win32GLSupport::createWindow"); bool enableFixedPipeline = (opt->second.currentValue == "Yes"); renderSystem->setFixedPipelineEnabled(enableFixedPipeline); #endif window = renderSystem->_createRenderWindow(windowTitle, w, h, fullscreen, &miscParams); } return window; }
void EvalObjectData::o_setArray(CArrRef props) { for (ArrayIter it(props); !it.end(); it.next()) { String k = it.first(); if (!k.empty() && k.charAt(0) == '\0') { int subLen = k.find('\0', 1) + 1; String cls = k.substr(1, subLen - 2); String key = k.substr(subLen); if (cls == "*") cls = o_getClassName(); props->load(k, o_lval(key, Variant(), cls)); } } DynamicObjectData::o_setArray(props); }
/* ('a', 0) => 'a' ('a', 1) => 'a' ('a/b', 0) => 'a' ('a/b', 1) => 'b' */ String ExtractMergedValue(const String& val) const { const String::size_type pos = val.find_first_of('/'); if (pos != String::npos) { Require(String::npos == val.find_first_of('/', pos + 1)); return Index == 0 ? val.substr(0, pos) : val.substr(pos + 1); } else { return val; } }
String ValueNode_Bone::unique_name(String name)const { if (!find(name)) return name; // printf("%s:%d making unique name for '%s'\n", __FILE__, __LINE__, name.c_str()); size_t last_close(name.size()-1); int number = -1; String prefix; do { if (name.substr(last_close) != ")") break; size_t last_open(name.rfind('(')); if (last_open == String::npos) break; if (last_open+2 > last_close) break; String between(name.substr(last_open+1, last_close - (last_open+1))); String::iterator iter; for (iter = between.begin(); iter != between.end(); iter++) if (!isdigit(*iter)) break; if (iter != between.end()) break; prefix = name.substr(0, last_open); number = atoi(between.c_str()); } while (0); if (number == -1) { prefix = name + " "; number = 2; } do { name = prefix + "(" + strprintf("%d", number++) + ")"; } while (find(name)); // printf("%s:%d unique name is '%s'\n", __FILE__, __LINE__, name.c_str()); return name; }
static bool findFileWrapper(const String& file, void* ctx) { ResolveIncludeContext* context = (ResolveIncludeContext*)ctx; assert(context->path.isNull()); Stream::Wrapper* w = Stream::getWrapperFromURI(file); if (!dynamic_cast<FileStreamWrapper*>(w)) { if (w->stat(file, context->s) == 0) { context->path = file; return true; } } // handle file:// if (file.substr(0, 7) == s_file_url) { return findFileWrapper(file.substr(7), ctx); } // TranslatePath() will canonicalize the path and also check // whether the file is in an allowed directory. String translatedPath = File::TranslatePathKeepRelative(file); if (file[0] != '/') { if (HPHP::Eval::FileRepository::findFile(translatedPath.get(), context->s)) { context->path = translatedPath; return true; } return false; } if (RuntimeOption::SandboxMode || !RuntimeOption::AlwaysUseRelativePath) { if (HPHP::Eval::FileRepository::findFile(translatedPath.get(), context->s)) { context->path = translatedPath; return true; } } string server_root(SourceRootInfo::GetCurrentSourceRoot()); if (server_root.empty()) { server_root = string(g_vmContext->getCwd()->data()); if (server_root.empty() || server_root[server_root.size() - 1] != '/') { server_root += "/"; } } String rel_path(Util::relativePath(server_root, translatedPath.data())); if (HPHP::Eval::FileRepository::findFile(rel_path.get(), context->s)) { context->path = rel_path; return true; } return false; }
void TranslationServer::load_translations() { String locale = get_locale(); bool found = _load_translations("locale/translations"); //all if (_load_translations("locale/translations_"+locale.substr(0,2))) found=true; if ( locale.substr(0,2) != locale ) { if (_load_translations("locale/translations_"+locale)) found=true; } }
void AnimationPlayerEditor::_dialog_action(String p_file) { switch (current_option) { case RESOURCE_LOAD: { ERR_FAIL_COND(!player); Ref<Resource> res = ResourceLoader::load(p_file, "Animation"); ERR_FAIL_COND(res.is_null()); ERR_FAIL_COND(!res->is_type("Animation")); if (p_file.find_last("/") != -1) { p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); } if (p_file.find_last("\\") != -1) { p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); } if (p_file.find(".") != -1) p_file = p_file.substr(0, p_file.find(".")); undo_redo->create_action(TTR("Load Animation")); undo_redo->add_do_method(player, "add_animation", p_file, res); undo_redo->add_undo_method(player, "remove_animation", p_file); if (player->has_animation(p_file)) { undo_redo->add_undo_method(player, "add_animation", p_file, player->get_animation(p_file)); } undo_redo->add_do_method(this, "_animation_player_changed", player); undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); break; } case RESOURCE_SAVE: { String current = animation->get_item_text(animation->get_selected()); if (current != "") { Ref<Animation> anim = player->get_animation(current); ERR_FAIL_COND(!anim->cast_to<Resource>()) RES current_res = RES(anim->cast_to<Resource>()); _animation_save_in_path(current_res, p_file); } } } }
BlobLocator* Database::newLocator(const String& name, const String& path) { if (path.empty()) NIT_THROW(EX_INVALID_PARAMS); size_t pos; pos = path.find('/'); bool ok = true; if (pos == path.npos) ok = false; String dbName; String tblName; String blobColumn; String idColumn = "rowid"; if (ok) { tblName = path.substr(0, pos); blobColumn = path.substr(pos+1); pos = tblName.find('.'); if (pos != tblName.npos) { dbName = tblName.substr(0, pos); tblName = tblName.substr(pos + 1); } pos = blobColumn.find('.'); if (pos != blobColumn.npos) { idColumn = blobColumn.substr(pos + 1); blobColumn = blobColumn.substr(0, pos); } } ok = ok && !tblName.empty(); ok = ok && !blobColumn.empty(); ok = ok && !idColumn.empty(); if (!ok) NIT_THROW_FMT(EX_INVALID_PARAMS, "invalid db locator path: '%s: %s'", name.c_str(), path.c_str()); return new BlobLocator(name, this, tblName, blobColumn, idColumn, dbName); }
StringList StringList::split(const String &s, const String &pattern) { StringList l; int previousOffset = 0; for(int offset = s.find(pattern); offset != -1; offset = s.find(pattern, offset + 1)) { l.append(s.substr(previousOffset, offset - previousOffset)); previousOffset = offset + 1; } l.append(s.substr(previousOffset, s.size() - previousOffset)); return l; }
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String& p_path) { if (!filesystem || scanning) return NULL; String f = GlobalConfig::get_singleton()->localize_path(p_path); if (!f.begins_with("res://")) return NULL; f=f.substr(6,f.length()); f=f.replace("\\","/"); if (f==String()) return filesystem; if (f.ends_with("/")) f=f.substr(0,f.length()-1); Vector<String> path = f.split("/"); if (path.size()==0) return NULL; EditorFileSystemDirectory *fs=filesystem; for(int i=0;i<path.size();i++) { int idx=-1; for(int j=0;j<fs->get_subdir_count();j++) { if (fs->get_subdir(j)->get_name()==path[i]) { idx=j; break; } } if (idx==-1) { return NULL; } else { fs=fs->get_subdir(idx); } } return fs; }
void PluginManager::loadList(const String& filename_list) { String::size_type next_start = 0; while(next_start < filename_list.size()) { String::size_type comma_idx = filename_list.find(',', next_start); String filename = comma_idx == String::npos ? filename_list.substr(next_start) : filename_list.substr(next_start, comma_idx - next_start); load(filename); if (comma_idx == String::npos) break; next_start = comma_idx + 1; } }
void SCsTranslator::processSentenceLevel1(pANTLR3_BASE_TREE node) { unsigned int nodesCount = node->getChildCount(node); assert(nodesCount == 3); pANTLR3_BASE_TREE node_obj = (pANTLR3_BASE_TREE)node->getChild(node, 0); pANTLR3_BASE_TREE node_pred = (pANTLR3_BASE_TREE)node->getChild(node, 1); pANTLR3_BASE_TREE node_subj = (pANTLR3_BASE_TREE)node->getChild(node, 2); pANTLR3_COMMON_TOKEN tok_pred = node_pred->getToken(node_pred); if (tok_pred->type != ID_SYSTEM) { THROW_EXCEPT(Exception::ERR_PARSE, String("Invalid predicate '") + ((const char*) node_pred->getText(node_pred)->chars) + "' in simple sentence", mParams.fileName, tok_pred->getLine(tok_pred)); } sElement *el_obj = parseElementTree(node_obj); sElement *el_subj = parseElementTree(node_subj); // determine arc type sc_type type = sc_type_edge_common; String pred = GET_NODE_TEXT(node_pred); size_t n = pred.find_first_of("#"); if (n != pred.npos) type = _getArcPreffixType(pred.substr(0, n)); _addEdge(el_obj, el_subj, type, false, pred); }
String trimContentData(String const & path) { if (path.size() < 2) return String(); return path.substr(2, path.size() - 3); }
void FileDialog::set_current_path(const String& p_path) { if (!p_path.size()) return; int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") ); if (pos==-1) { set_current_file(p_path); } else { String dir=p_path.substr(0,pos); String file=p_path.substr(pos+1,p_path.length()); set_current_dir(dir); set_current_file(file); } }