std::string Mission::getDescription(Player* player) const { int32_t value; player->getStorageValue(storageID, value); if (!mainDescription.empty()) { std::string desc = mainDescription; replaceString(desc, "|STATE|", std::to_string(value)); replaceString(desc, "\\n", "\n"); return desc; } if (ignoreEndValue) { for (int32_t current = endValue; current >= startValue; current--) { if (value >= current) { auto sit = descriptions.find(current); if (sit != descriptions.end()) { return sit->second; } } } } else { for (int32_t current = endValue; current >= startValue; current--) { if (value == current) { auto sit = descriptions.find(current); if (sit != descriptions.end()) { return sit->second; } } } } return "An error has occurred, please contact a gamemaster."; }
static int textAlreadyAdded(char *text) { int i; char *clean; if (strcmpignorecase("msgid \"\"", text) == 0) { return TRUE; } clean = replaceString(text, "msgid \"", ""); clean[strlen(clean) - 1] = '\0'; clean = replaceString(clean, "\\", ""); clean = replaceString(clean, "\\", ""); for (i=0;i<poIndex;i++) { if (strcmpignorecase(added[i], text) == 0) { return TRUE; } } if (checkExists(clean) == FALSE) { return TRUE; } STRNCPY(added[poIndex], text, MAX_LINE_LENGTH); poIndex++; return FALSE; }
std::ofstream &exportSubScript(std::ofstream &stream, Script &script, const std::string &subName) { SubScript &subScript = script.subScripts[subName]; if(subName == "execute" && subScript.script.empty()) return stream; // HACK: special sub is not actually a sub... -jpk if (subName != "special") { stream << "sub " << subName << std::endl; } if(subName == "main") { stream << " call createpaths" << std::endl; for(unsigned int i = 0; i < script.initialization.size(); ++i) stream << " " << replaceString(script.initialization[i], script.properties.strings, script.stringProperties.defaults) << std::endl; } for(unsigned int i = 0; i < subScript.script.size(); ++i) stream << " " << replaceString(subScript.script[i], script.properties.strings, script.stringProperties.defaults) << std::endl; // HACK: special sub is not actually a sub... -jpk if (subName != "special") { stream << "endSub" << std::endl; } return stream; }
std::string Mission::getDescription(Player* player) { std::string value; player->getStorage(storageId, value); if(state.size()) { std::string ret = state; replaceString(ret, "|STATE|", value); return ret; } if(atoi(value.c_str()) >= endValue) { std::string ret = states.rbegin()->second; replaceString(ret, "|STATE|", value); return ret; } for(int32_t i = endValue; i >= startValue; --i) { player->getStorage(storageId, value); if(atoi(value.c_str()) != i) continue; std::string ret = states[i - startValue]; replaceString(ret, "|STATE|", value); return ret; } return "Couldn't retrieve any mission description, please report to a gamemaster."; }
/**@brief A function to start a runLog in the named directory * @param dirName The name of the directory to start the runLog, runLog name *will be runLog_[NAME_OF_PROGRAM] * */ void startARunLog(const std::string &dirName) { rLog_.setFilenameAndOpen( files::make_path(dirName,"runLog_" + replaceString(replaceString(commands_.getProgramName(), "./", ""), " ", "-")+ "_" + getCurrentDate() + ".txt").string(), timer_.start_); rLog_.startRunLog(commands_); }
string trimString(string const &text) { string ret = replaceString(text, " ", ""); ret = replaceString(ret, "\t", ""); ret = replaceString(ret, "\r", ""); ret = replaceString(ret, "\n", ""); return ret; }
SLAString getSharedLibSuffix() { SLAString libSuffix(Poco::SharedLibrary::suffix()); #if defined(_DEBUG) libSuffix = replaceString(libSuffix, "d.", "_Debug."); #else libSuffix = replaceString(libSuffix, ".", "_Release."); #endif return libSuffix; }
char * handSanitizer(char *fix) {//returns a string that is dynamically alcolated. fix = replaceString("--","+",fix); fix = replaceString(" ","",fix); fix = replaceString("-", "+-",fix); fix = replaceString("X", "x",fix); fix = replaceString("^+-", "^-",fix); fix = replaceString("++-", "+-", fix); fix = replaceString("*+-", "*-",fix); fix = replaceString("(+-", "(-",fix); fix = replaceString(")(",")*(",fix); if(strncmp(fix,"+-",2)==0){ size_t len = strlen(fix);//original length memcpy(fix,&fix[1],len);//cpy to fix starting at fix[1], for orig len-1 fix = (char *) realloc(fix,len);//realloc space to be smaller } if(strncmp(fix,"+",1)==0){//same as above size_t len = strlen(fix); memcpy(fix,&fix[1],len); fix = (char *) realloc(fix,len); } printf("Reformatted Equation: %s",fix); return fix; }
std::string getExporterFileName( std::string const& fileName ) { std::string sourceName = "Exported from: "; sourceName += fileName; // these symbols can't be in the meta data replaceString( sourceName, "=", "_" ); replaceString( sourceName, ";", "_" ); replaceString( sourceName, "\\", "/" ); return sourceName; }
qpid::types::Variant::Map getConfigTree() { qpid::types::Variant::Map tree; if (augeas==NULL) augeas_init(); if (augeas == NULL) { AGO_ERROR() << "cannot initialize augeas"; return tree; } char **matches; std::stringstream path; path << "/files"; path << getConfigPath(MODULE_CONFDIR).string(); path << "/"; std::string prefix = path.str(); path << "/*"; int num = aug_match(augeas, path.str().c_str(), &matches); for (int i=0; i < num; i++) { const char *val; aug_get(augeas, matches[i], &val); if (val != NULL) { std::vector<std::string> elements; std::string match = matches[i]; AGO_TRACE() << "getConfigTree:augeas match result[" << i << "]:" << match << ": " << val; replaceString(match, prefix, ""); replaceString(match, ".conf", ""); elements = split(match, '/'); if (elements.size() != 3) { AGO_ERROR() << "augeas match ignored: does not split by / in three parts: " << match; continue; } std::string file = elements[0]; std::string section = elements[1]; std::string option = elements[2]; AGO_TRACE() << "File: " << file << " Section: " << section << " Option: " << option; qpid::types::Variant::Map fileMap; qpid::types::Variant::Map sectionMap; if (!(tree[file].isVoid())) { fileMap = tree[file].asMap(); } if (!(fileMap[section].isVoid())) { sectionMap = fileMap[section].asMap(); } sectionMap[option] = val; fileMap[section] = sectionMap; tree[file] = fileMap; } free((void *) matches[i]); } free(matches); return tree; }
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ std::string DatabaseConnection::escapeString(const std::string& _string) { std::string str(_string); // Escape the project name std::string searchString("\'"); std::string replaceString("\'\'"); std::string::size_type pos = 0; while ((pos = str.find(searchString, pos)) != std::string::npos) { str.replace(pos, searchString.size(), replaceString); pos += replaceString.size(); } searchString = "\"\""; pos = 0; while ((pos = str.find(searchString, pos)) != std::string::npos) { str.replace(pos, searchString.size(), replaceString); pos += replaceString.size(); } return str; }
void replaceStringInFile(const char *filename, const string &toFind, const string &replaceWith) { FILE *f = fopen(filename, "r"); if (f == NULL) { int e = errno; string message = "Cannot open file '"; message.append(filename); message.append("' for reading"); throw FileSystemException(message, e, filename); } string content(readAll(fileno(f))); fclose(f); f = fopen(filename, "w"); if (f == NULL) { int e = errno; string message = "Cannot open file '"; message.append(filename); message.append("' for writing"); throw FileSystemException(message, e, filename); } content = replaceString(content, toFind, replaceWith); fwrite(content.data(), 1, content.size(), f); fclose(f); }
bool CHostTracker::isNavigatedToBadLink() { bool isBadLink = true; rho::StringW navUrl = replaceString(m_szNavigatedUrl, L"%20", L" "); //replace back slash in badlink url to front slash rho::StringW badUrl = replaceString(m_szBadLinkUrl, L"\\", L"/"); LOG(INFO) + "CHostTracker::run navigated url"+ navUrl.c_str(); LOG(INFO) + "CHostTracker::run badlink url"+ badUrl.c_str(); if(std::string::npos == navUrl.find(badUrl)) { isBadLink = false; } return isBadLink; }
void convert::replaceStringInFile(const std::string& oldfilename, const std::string& newfilename, const std::string& oldstring, const std::string& newstring) { std::string s = readStringFromFile(oldfilename); if (s.length() <= 0) { return; } replaceString(s, oldstring, newstring); writeStringToFile(s, newfilename); }
void nameFunction(t_tree node) { if (node == NULL) return; if (nameCurrentPrimitive != NULL) { if (strcmp(node->Node.Function.Name, "main") == 0) { replaceString(&node->Node.Function.Name, nameCurrentPrimitive->Node.Primitive.Name); node->Node.Function.Variables = nameCurrentPrimitive->Node.Primitive.Variables; nameCurrentPrimitive->Node.Primitive.Variables = NULL; namePrimitiveVariables(node->Node.Function.Variables); } else joinStrings(&node->Node.Function.Name, nameCurrentPrimitive->Node.Primitive.Name, node->Node.Function.Name); } checkIdExists(node->Node.Function.Name, node->LineNr, node->Node.Function.Type, NAME_TABLE_FUNCTION); scope = FindId(node->Node.Function.Name, scope); nameVariable(node->Node.Function.Variables); nameStmnt(node->Node.Function.Stmnts); scope = scope->parent; namePrimitive(node->Node.Function.Next); }
std::string FileCacheExt::createCacheFileName(const std::string& originalFileName) const { std::string serverAddress = osgDB::getServerAddress(originalFileName); std::string cacheFileName(_fileCachePath); cacheFileName.append("/"); if (serverAddress.empty()) { cacheFileName.append(originalFileName); osg::notify(osg::NOTICE) << "FileCache::_fileCachePath ==" << _fileCachePath << std::endl; } else { int size = _serverAddress.size(); std::string rFile = originalFileName.substr(size + 1, originalFileName.size() - size - 1); replaceString(rFile,"/", "%2F", -1); std::string eName = tryConvertStringFromEscapeToUTF8(rFile); std::string localFile = cacheFileName; localFile.append(eName); if (osgDB::fileExists(localFile)) return localFile; std::string gbkString(""); tryConvertStringFromUTF8ToGB2312(localFile, gbkString); if (osgDB::fileExists(gbkString)) return gbkString; return originalFileName; } osg::notify(osg::NOTICE) << "FileCache::createCacheFileName(" << originalFileName << ") = " << cacheFileName << std::endl; return cacheFileName; }
std::string ModelMaker::replaceAllString(std::string& fullString, std::string toReplace, std::string replaceWith){ std::string returnString = fullString; while(returnString.find(toReplace) != std::string::npos) { returnString = replaceString(returnString, toReplace, replaceWith); } return returnString; }
/**@brief Construct the setUp with the generic argc and argv * * @param argc The number of arguments * @param argv The array of char pointers of the arguments * */ programSetUp(int argc, char *argv[]) : commands_(commandLineArguments(argc, argv)) { commands_.arguments_["-program"] = argv[0]; // get rid of the ./ if program is being called from current dir, it can // mess things up latter programName_ = replaceString(argv[0], "./", ""); init(); }
string replaceAll(const string &str, const string &toFind, const string &replaceWith) { string result = str; while (result.find(toFind) != string::npos) { result = replaceString(result, toFind, replaceWith); } return result; }
int main(void) { char text[] = "I have a dream and have 1 dreame * ding word."; printf("%s\n", text); replaceString(text, "1", "one"); printf("%s\n", text); replaceString(text, "a", ""); printf("%s\n", text); replaceString(text, " ", ""); printf("%s\n", text); return 0; }
/** Escapes in the given string some characters that in XML are given an special meaning. The characters replaced are the following ones: ' is replaced with &apos " is replaced with " & is replaced with & < is replaced with < > is replaced with > @param data: string to be escaped */ void BasicGenerator::escapeXMLCharacters(string &data) { replaceString(data, "'", "'"); replaceString(data, "\"", """ ); replaceString(data, "&", "&"); replaceString(data, "<", "<" ); replaceString(data, ">" , ">"); replaceString(data, "\r\n" , "\n"); replaceString(data, "\r" , "\n"); replaceString(data, "\b" , "\n"); }
bool AccessList::addExpression(const std::string& expression) { ExpressionList::iterator it; for(it = expressionList.begin(); it != expressionList.end(); ++it){ if((*it) == expression){ return false; } } std::string outExp; std::string metachars = ".[{}()\\+|^$"; for(std::string::const_iterator it = expression.begin(); it != expression.end(); ++it){ if(metachars.find(*it) != std::string::npos){ outExp += "\\"; } outExp += (*it); } replaceString(outExp, "*", ".*"); replaceString(outExp, "?", ".?"); try{ if(outExp.length() > 0){ expressionList.push_back(outExp); if(outExp.substr(0,1) == "!"){ if(outExp.length() > 1){ //push 'NOT' expressions upfront so they are checked first regExList.push_front(std::make_pair(boost::regex(outExp.substr(1)), false)); } } else{ regExList.push_back(std::make_pair(boost::regex(outExp), true)); } } } catch(...){ // } return true; }
/** format a string to output*/ std::string Help::formatOutString(std::string s, size_t columnWidth, int indentLevel, int numLineBreaks, bool stripLineBreaks) { //std::cout << s + "<break>\n"; std::string indent = ""; for (int i = -1; i < indentLevel; i++) { indent += RevBayesCore::RbUtils::PAD; } // -- remove any pre-formatting that may come from the xml-file s = replaceString(s, "\t", " "); if (stripLineBreaks) { s = replaceString(s, "\n", " "); } s = stripConsecutiveSpace(s); // do nothing if string is empty if (s.length() <= 0) { return ""; } // remove space at beginning if (std::isspace(s.at(0))) { s.erase(0, 1); } //-- apply the formatting style we want // wrap text s = wrapText(s, indent, columnWidth); // apply line breaks at end for (int i = 0; i < numLineBreaks; i++) { s += "\n"; } //std::cout << s + "<break>\n"; return s; }
/*------------------------------------------------------------ * �ѵ�ɬ��ë���继�������ƻ�֧�£� �꼰�ֳ��ƥ���£� *------------------------------------------------------------*/ static int TITLE_getConfigOneLine( FILE *fp, char *line, int linelen) { char buf[1024]; int startflg = FALSE; int linenum=0; line[0] = '\0'; while( fgets( buf, sizeof( buf ), fp )){ linenum ++; if( buf[0] == '#' )continue; /* comment */ if( buf[0] == '\n' )continue; /* none */ /* ��ë�������� */ /* ���� tab ë " " �� �徧���� */ replaceString( buf, '\t' , ' ' ); /* ��ʸ�������� */ deleteCharFromString( buf, " "); if( buf[0] == '{' ) { if( startflg == TRUE ) { print( "titleconfig:����û�йرա�{��ȴ������: %d \n",linenum); /* } */ return -1; } startflg = TRUE; } else if( buf[0] == '}' ) { if( startflg == FALSE) { print( "titleconfig:����û�йرա�{��ȴ������: %d \n",linenum); /* } */ return -1; } return 1; } else { /* "{"ƥ�ȱ�����Ȼ������� }*/ if( startflg == TRUE ) { if( strlen( line) != 0 ) { if( line[strlen(line) -1] != ',' ) { strcatsafe( line, linelen, ","); } } /* �������继������*/ chompex( buf ); strcatsafe( line,linelen, buf); } /* ���ֻ�"{"ƥ��Ԫ���Ȼ�ئ�������������������ƥ߯�� }*/ else { chompex( buf ); strcatsafe( line,linelen, buf); return 1; } } } /* �����������ɵ��Ƿ�EOF ѱ��Ԫ��ئ�������� */ return 0; }
std::string getExporterName( std::string const& shortName ) { std::stringstream exporterName; std::string shortNameSafe = shortName; replaceString( shortNameSafe, "\"", "" ); exporterName << "Exocortex Crate for " << shortNameSafe << "," << EC_QUOTE(crate_ver) << "," << EC_QUOTE(alembic_ver) << "," << EC_QUOTE(hdf5_ver); return exporterName.str(); }
/** * Open a web view for a certain title * compose the url and display * @param The article title for which we want to open a wikipedia definition. * @return false if some error occur. */ bool WebScreen::openWebView(MAUtil::String title) { MAUtil::String url = "http://en.wikipedia.org/wiki/" + title; // Replace spaces. replaceString(url," ","%20"); // Display the article. maWidgetSetProperty(mWebView,MAW_WEB_VIEW_URL,url.c_str() ); }
char * getMetadataString(const char *format, metadata_t *mdata) { char *tmp, *str; if (mdata == NULL) { printf("%s: getMetadataString(): Internal error: NULL metadata_t\n", __progname); abort(); } if (format == NULL) return (NULL); str = xstrdup(format); if (strstr(format, ARTIST_PLACEHOLDER) != NULL) { tmp = replaceString(str, ARTIST_PLACEHOLDER, metadata_get_artist(mdata)); xfree(str); str = tmp; } if (strstr(format, TITLE_PLACEHOLDER) != NULL) { tmp = replaceString(str, TITLE_PLACEHOLDER, metadata_get_title(mdata)); xfree(str); str = tmp; } if (strstr(format, STRING_PLACEHOLDER) != NULL) { tmp = replaceString(str, STRING_PLACEHOLDER, metadata_get_string(mdata)); xfree(str); str = tmp; } if (strstr(format, TRACK_PLACEHOLDER) != NULL) { tmp = replaceString(str, TRACK_PLACEHOLDER, metadata_get_filename(mdata)); xfree(str); str = tmp; } return (str); }
void testLoadPluginLibraries(const std::string& subcommand) { const auto cmd = subcommand + " -h"; // Nonexistent file. // ================= { std::regex output(RE_ANY + "(Failed to load library x)\n"); // These are all valid ways of specifying libraries. testCommand("-L x " + cmd, EXIT_FAILURE, output); testCommand("-Lx " + cmd, EXIT_FAILURE, output); testCommand("--library x " + cmd, EXIT_FAILURE, output); testCommand("--library=x " + cmd, EXIT_FAILURE, output); testCommand("-L x --library y " + cmd, EXIT_FAILURE, output); testCommand("-Lx --library=y -L z " + cmd, EXIT_FAILURE, output); } // Load an actual library, including the file extension. // ===================================================== // OSIM_ACTUATORS_LIB_PATH is a preprocessor definition that is defined // when compiling this executable. std::string lib = MAKE_STRING(OSIM_ACTUATORS_LIB_PATH); // Get rid of the quotes surrounding `lib`. std::string expectLib = lib.substr(1, lib.size() - 2); #ifdef _WIN32 // When the library name gets printed back to us, the // forward slashes are converted to backslashes. We have to // escape backslash for the C++ parser, so '\\' is actually '\'. expectLib = replaceString(expectLib, "/", "\\"); #endif { StartsWith output("Loaded library " + expectLib); testCommand("-L " + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("-L" + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("--library " + lib + " " + cmd, EXIT_SUCCESS, output); testCommand("--library=" + lib + " " + cmd, EXIT_SUCCESS, output); } // Load multiple libraries. // ======================== { // Well, in this case, we just load the same library multiple times. testCommand("-L " + lib + " --library " + lib + " " + cmd, EXIT_SUCCESS, StartsWith("Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n")); testCommand("-L" + lib + " --library=" + lib + " -L " + lib + " " + cmd, EXIT_SUCCESS, StartsWith("Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n" "Loaded library " + expectLib + "\n")); } }
bool queryCallback(void *p_context, int p_placeholder, DBBuffer& p_output) { QueryMetadata *t_query_metadata; t_query_metadata = (QueryMetadata *)p_context; DBString t_parameter_value; t_parameter_value = t_query_metadata -> arguments[p_placeholder - 1]; void *t_escaped_string; t_escaped_string = NULL; size_t t_escaped_string_length; t_escaped_string_length = 0; if (t_parameter_value . isbinary) { // According to documentation in sqlitedecode.cpp, this is the required size of output buffer t_escaped_string = malloc(2 + (257 * t_parameter_value . length) / 254); t_escaped_string_length = sqlite_encode_binary((const unsigned char *)t_parameter_value . sptr, t_parameter_value . length, (unsigned char *)t_escaped_string); } else { if (t_parameter_value . length != 0) { // Null terminate the value char *t_value; t_value = (char *)malloc(t_parameter_value . length + 1); memcpy(t_value, t_parameter_value . sptr, t_parameter_value . length); t_value[t_parameter_value . length] = '\0'; // Escape quotes by manually replacing then with the string "''" t_escaped_string = replaceString(t_value, "\'\0", "\'\'\0"); t_escaped_string_length = strlen((const char *)t_escaped_string); free(t_value); } } p_output . ensure(t_escaped_string_length + 2); memcpy(p_output . getFrontier(), "'", 1); p_output . advance(1); if (t_escaped_string != NULL) { memcpy(p_output . getFrontier(), t_escaped_string, t_escaped_string_length); p_output . advance(t_escaped_string_length); } memcpy(p_output . getFrontier(), "'", 1); p_output . advance(1); free(t_escaped_string); return true; }
void SegmentationImpl::loadInputGroundTruthLabelMapping() { std::string fileName = replaceString(inputSettings()->color(), inputSettings()->colorMatch(), inputSettings()->groundTruthLabelMappingReplace()); std::ifstream fs(fileName.c_str()); if (fs.good()) { inputGroundTruthLabelMapping_ = loadArray<uint>(fileName); } else { LINFO << "Skipping to load non-exisitant label mapping file '" << fileName << "'."; inputGroundTruthLabelMapping_.clear(); } }