当前位置: 首页>>代码示例>>C++>>正文


C++ replace函数代码示例

本文整理汇总了C++中replace函数的典型用法代码示例。如果您正苦于以下问题:C++ replace函数的具体用法?C++ replace怎么用?C++ replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse


//.........这里部分代码省略.........
	char w4[WSZ];
	char *buf, *ptr, *optr, *par;

	// malloc can be slow here :?
	if (!(buf = malloc (len + 1))) {
		return false;
	}
	memcpy (buf, data, len + 1);

	r_str_chop (buf);
	if (*buf) {
		w0[0] = '\0';
		w1[0] = '\0';
		w2[0] = '\0';
		w3[0] = '\0';
		w4[0] = '\0';
		ptr = strchr (buf, ' ');
		if (!ptr) {
			ptr = strchr (buf, '\t');
		}
		if (ptr) {
			*ptr = '\0';
			for (++ptr; *ptr == ' '; ptr++) {
				//nothing to see here
			}
			strncpy (w0, buf, WSZ - 1);
			strncpy (w1, ptr, WSZ - 1);

			optr = ptr;
			par = strchr (ptr, '(');
			if (par && strchr (ptr, ',') > par) {
				ptr = strchr (ptr, ')');
				if (ptr) {
					ptr = strchr (ptr, ',');
				}
			} else {
				ptr = strchr (ptr, ',');
			}
			if (ptr) {
				*ptr = '\0';
				for (++ptr; *ptr == ' '; ptr++) {
					//nothing to see here
				}
				strncpy (w1, optr, WSZ - 1);
				strncpy (w2, ptr, WSZ - 1);
				optr = ptr;
				par = strchr (ptr, '(');
				if (par && strchr (ptr, ',') > par) {
					ptr = strchr (ptr, ')');
					if (ptr) {
						ptr = strchr (ptr, ',');
					}
				} else {
					ptr = strchr (ptr, ',');
				}
				if (ptr) {
					*ptr = '\0';
					for (++ptr; *ptr == ' '; ptr++) {
						//nothing to see here
					}
					strncpy (w2, optr, WSZ - 1);
					strncpy (w3, ptr, WSZ - 1);
					optr = ptr;
					// bonus	
					par = strchr (ptr, '(');
					if (par && strchr (ptr, ',') > par) {
						ptr = strchr (ptr, ')');
						if (ptr) {
							ptr = strchr (ptr, ',');
						}
					} else {
						ptr = strchr (ptr, ',');
					}
					if (ptr) {
						*ptr = '\0';
						for (++ptr; *ptr == ' '; ptr++) {
							//nothing to see here
						}
						strncpy (w3, optr, WSZ - 1);
						strncpy (w4, ptr, WSZ - 1);
					}
				}
			}
		} else {
			strncpy (w0, buf, WSZ - 1);
		}
		{
			const char *wa[] = { w0, w1, w2, w3, w4 };
			int nw = 0;
			for (i = 0; i < 5; i++) {
				if (wa[i][0] != '\0') {
					nw++;
				}
			}
			replace (nw, wa, str);
		}
	}
	free (buf);
	return true;
}
开发者ID:PankajKataria,项目名称:radare2,代码行数:101,代码来源:parse_sh_pseudo.c

示例2: replace

void QuadSetTopologyModifier::removeQuadsProcess(const sofa::helper::vector<unsigned int> &indices,
        const bool removeIsolatedEdges,
        const bool removeIsolatedPoints)
{
    if(!m_container->hasQuads()) // this method should only be called when quads exist
    {
#ifndef NDEBUG
        sout << "Error. [QuadSetTopologyModifier::removeQuadsProcess] quad array is empty." << sendl;
#endif
        return;
    }

    if(m_container->hasEdges() && removeIsolatedEdges)
    {
        if(!m_container->hasEdgesInQuad())
            m_container->createEdgesInQuadArray();

        if(!m_container->hasQuadsAroundEdge())
            m_container->createQuadsAroundEdgeArray();
    }

    if(removeIsolatedPoints)
    {
        if(!m_container->hasQuadsAroundVertex())
            m_container->createQuadsAroundVertexArray();
    }

    sofa::helper::vector<unsigned int> edgeToBeRemoved;
    sofa::helper::vector<unsigned int> vertexToBeRemoved;
    helper::WriteAccessor< Data< sofa::helper::vector<Quad> > > m_quad = m_container->d_quad;

    unsigned int lastQuad = m_container->getNumberOfQuads() - 1;
    for(unsigned int i=0; i<indices.size(); ++i, --lastQuad)
    {
        const Quad &t = m_quad[ indices[i] ];
        const Quad &q = m_quad[ lastQuad ];

        // first check that the quad vertex shell array has been initialized
        if(m_container->hasQuadsAroundVertex())
        {
            for(unsigned int v=0; v<4; ++v)
            {
                sofa::helper::vector< unsigned int > &shell = m_container->m_quadsAroundVertex[ t[v] ];
                shell.erase(remove(shell.begin(), shell.end(), indices[i]), shell.end());
                if(removeIsolatedPoints && shell.empty())
                    vertexToBeRemoved.push_back(t[v]);
            }
        }

        if(m_container->hasQuadsAroundEdge())
        {
            for(unsigned int e=0; e<4; ++e)
            {
                sofa::helper::vector< unsigned int > &shell = m_container->m_quadsAroundEdge[ m_container->m_edgesInQuad[indices[i]][e]];
                shell.erase(remove(shell.begin(), shell.end(), indices[i]), shell.end());
                if(removeIsolatedEdges && shell.empty())
                    edgeToBeRemoved.push_back(m_container->m_edgesInQuad[indices[i]][e]);
            }
        }

        if(indices[i] < lastQuad)
        {
            // now updates the shell information of the quad at the end of the array
            if(m_container->hasQuadsAroundVertex())
            {
                for(unsigned int v=0; v<4; ++v)
                {
                    sofa::helper::vector< unsigned int > &shell = m_container->m_quadsAroundVertex[ q[v] ];
                    replace(shell.begin(), shell.end(), lastQuad, indices[i]);
                }
            }

            if(m_container->hasQuadsAroundEdge())
            {
                for(unsigned int e=0; e<4; ++e)
                {
                    sofa::helper::vector< unsigned int > &shell =  m_container->m_quadsAroundEdge[ m_container->m_edgesInQuad[lastQuad][e]];
                    replace(shell.begin(), shell.end(), lastQuad, indices[i]);
                }
            }
        }

        // removes the edgesInQuads from the edgesInQuadsArray
        if(m_container->hasEdgesInQuad())
        {
            m_container->m_edgesInQuad[ indices[i] ] = m_container->m_edgesInQuad[ lastQuad ]; // overwriting with last valid value.
            m_container->m_edgesInQuad.resize( lastQuad ); // resizing to erase multiple occurence of the quad.
        }

        // removes the quad from the quadArray
        m_quad[ indices[i] ] = m_quad[ lastQuad ]; // overwriting with last valid value.
        m_quad.resize( lastQuad ); // resizing to erase multiple occurence of the quad.
    }

    if(!edgeToBeRemoved.empty())
    {
        /// warn that edges will be deleted
        removeEdgesWarning(edgeToBeRemoved);
        propagateTopologicalChanges();
        /// actually remove edges without looking for isolated vertices
//.........这里部分代码省略.........
开发者ID:FabienPean,项目名称:sofa,代码行数:101,代码来源:QuadSetTopologyModifier.cpp

示例3: xmlFile

void Map::CreateMap( vector<vector<Tile*> >& tiles, char* tmxFile, int numSpritesRow )
{
    //Clear out all the tiles
    backTiles.clear();
    backTiles.shrink_to_fit();

	// open the XML map file
	TiXmlDocument xmlFile( tmxFile );
	if(xmlFile.LoadFile()) {
		cout << "Successfully opened the XML map file.\n";
	} else {
		cout << "ERROR: Unable to open the XML map file.\n";
	}

	// parse the XML
	// this code assumes that the layers exist in the XML file in this order: sprites, then collision, then ladders.
	mapWidth = atoi(xmlFile.FirstChildElement("map")->Attribute("width"));
	mapHeight = atoi(xmlFile.FirstChildElement("map")->Attribute("height"));
	int tileSize = atoi(xmlFile.FirstChildElement("map")->Attribute("tilewidth"));
	string tileImageFilename = xmlFile.FirstChildElement("map")->FirstChildElement("tileset")->FirstChildElement("image")->Attribute("source");
	string spriteLayer = xmlFile.FirstChildElement("map")->FirstChildElement("layer")->FirstChildElement("data")->GetText();
	string collisionLayer = xmlFile.FirstChildElement("map")->FirstChildElement("layer")->NextSibling()->FirstChildElement("data")->GetText();
	string ladderLayer = xmlFile.FirstChildElement("map")->FirstChildElement("layer")->NextSibling()->NextSibling()->FirstChildElement("data")->GetText();
	string enemiesLayer = xmlFile.FirstChildElement("map")->FirstChildElement("layer")->NextSibling()->NextSibling()->NextSibling()->FirstChildElement("data")->GetText();

	// convert the CSV strings into vectors of ints
	// these ints are the sprite numbers for each tile. 0 would be the first sprite in the first row, etc.
	replace(spriteLayer.begin(), spriteLayer.end(), ',', ' '); // convert CSV to space-delimited
	stringstream a(spriteLayer);
	vector<int> spriteInts;
	string temp1;
	while(a >> temp1) {
		spriteInts.push_back(atoi(temp1.c_str()));
	}
	replace(collisionLayer.begin(), collisionLayer.end(), ',', ' '); // convert CSV to space-delimited
	stringstream b(collisionLayer);
	vector<int> collisionInts;
	string temp2;
	while(b >> temp2) {
		collisionInts.push_back(atoi(temp2.c_str()));
	}
	replace(ladderLayer.begin(), ladderLayer.end(), ',', ' '); // convert CSV to space-delimited
	stringstream c(ladderLayer);
	vector<int> ladderInts;
	string temp3;
	while(c >> temp3) {
		ladderInts.push_back(atoi(temp3.c_str()));
	}
	replace(enemiesLayer.begin(), enemiesLayer.end(), ',', ' '); // convert CSV to space-delimited
	stringstream d(enemiesLayer);
	vector<int> enemyInts;
	string temp4;
	while(d >> temp4) {
		enemyInts.push_back(atoi(temp4.c_str()));
	}


	// generate the vectors of tiles
	int i = 0;	
	for(int row = 0; row < mapHeight; row++) {
		vector<Tile*> currentRow;
		for(int column = 0; column < mapWidth; column++) {
			int xPosition = (i % mapWidth) * tileSize;
			int yPosition = (i / mapWidth) * tileSize;
			bool collision = collisionInts[i]; // non-zero sprite number indicates collision region
			bool ladder = ladderInts[i]; // non-zero sprite number indicates ladder region
            Game_Enemies enemy;
			if(enemyInts[i] == 377)
				enemy = CORGI;
			else if(enemyInts[i] == 378)
				enemy = HUSKY;
			else if(enemyInts[i] == 379)
				enemy = GREYHOUND;
			else if(enemyInts[i] == 380)
				enemy = SHIBA;
			else if(enemyInts[i] == 381)
				enemy = BULLDOG;
			else
				enemy = NONE;
			string spriteFilePath = tileImageFilename;
			int spritesPerRow = numSpritesRow;
			int spriteXoffset = ((spriteInts[i] - 1) % spritesPerRow) * tileSize;
			int spriteYoffset = ((spriteInts[i] - 1) / spritesPerRow) * tileSize;
			i++;
			currentRow.push_back( new Tile( xPosition, yPosition, collision, ladder, enemy, spriteXoffset, spriteYoffset ) );
		}
		tiles.push_back(currentRow);

	}

	// for debugging: examine the contents of a tile
	cout << "There are " << tiles.size() << " rows, and " << tiles[0].size() << " columns.\n\n";
	int tileToExamine = 1;
	cout << "Details for tile #" << tileToExamine << ":\n\n";
    cout << "xPosition =       " << tiles[tileToExamine / mapWidth][tileToExamine % mapWidth]->GetDestination().x << "\n";
	cout << "yPosition =       " << tiles[tileToExamine / mapWidth][tileToExamine % mapWidth]->GetDestination().y << "\n";
    cout << "collision =       " << tiles[tileToExamine / mapWidth][tileToExamine % mapWidth]->GetCollision() << "\n";
    cout << "ladder =          " << tiles[tileToExamine / mapWidth][tileToExamine % mapWidth]->GetIsLadder() << "\n";
    cout << "enemy =           " << tiles[tileToExamine / mapWidth][tileToExamine % mapWidth]->GetEnemy() << "\n";
	//cout << "spriteFilePath =  " <<  << "\n";
//.........这里部分代码省略.........
开发者ID:dbaker23,项目名称:TacoGato,代码行数:101,代码来源:Map.cpp

示例4: parse

/* Parse a VM configuration file */
static bool parse(home_data *data)
{
    FILE *cfgf = fopen(data->cfgf, "r");
    char *ret = NULL, *sp;
    char buf[1024];

    if (cfgf == NULL) {
        log_debug("Can't open %s\n", data->cfgf);
        return (false);
    }

    data->jvms = (home_jvm **)malloc(256 * sizeof(home_jvm *));

    while ((ret = fgets(buf, 1024, cfgf)) != NULL) {
        char *tmp = strchr(ret, '#');
        int pos;

        /* Clear the string at the first occurrence of '#' */
        if (tmp != NULL)
            tmp[0] = '\0';

        /* Trim the string (including leading '-' chars */
        while ((ret[0] == ' ') || (ret[0] == '\t') || (ret[0] == '-'))
            ret++;
        pos = strlen(ret);
        while (pos >= 0) {
            if ((ret[pos] == '\r') || (ret[pos] == '\n') || (ret[pos] == '\t')
                || (ret[pos] == '\0') || (ret[pos] == ' ')) {
                ret[pos--] = '\0';
            }
            else
                break;
        }
        /* Format changed for 1.4 JVMs */
        sp = strchr(ret, ' ');
        if (sp != NULL)
            *sp = '\0';

        /* Did we find something significant? */
        if (strlen(ret) > 0) {
            char *libf = NULL;
            int x = 0;

            log_debug("Found VM %s definition in configuration", ret);
            while (location_jvm_configured[x] != NULL) {
                char *orig = location_jvm_configured[x];
                char temp[1024];
                char repl[1024];
                int k;

                k = replace(temp, 1024, orig, "$JAVA_HOME", data->path);
                if (k != 0) {
                    log_error("Can't replace home in VM library (%d)", k);
                    return (false);
                }
                k = replace(repl, 1024, temp, "$VM_NAME", ret);
                if (k != 0) {
                    log_error("Can't replace name in VM library (%d)", k);
                    return (false);
                }

                log_debug("Checking library %s", repl);
                if (checkfile(repl)) {
                    libf = strdup(repl);
                    break;
                }
                x++;
            }

            if (libf == NULL) {
                log_debug("Cannot locate library for VM %s (skipping)", ret);
            }
            else {
                data->jvms[data->jnum] = (home_jvm *)malloc(sizeof(home_jvm));
                data->jvms[data->jnum]->name = strdup(ret);
                data->jvms[data->jnum]->libr = libf;
                data->jnum++;
                data->jvms[data->jnum] = NULL;
            }
        }
    }
    return (true);
}
开发者ID:nicobrevin,项目名称:commons-daemon,代码行数:84,代码来源:home.c

示例5: getClassName


//.........这里部分代码省略.........
      numDbColumns = 1;  // 1 for the pseudo-time

    theResponses= std::vector<Response *>(numEle,static_cast<Response *>(nullptr));

    Information eleInfo(1.0);
    int i;
    for(i=0; i<numEle; i++)
      {
        Element *theEle = theDomain->getElement(eleID(i));
        if(theEle == 0)
          { theResponses[i]= 0; }
        else
          {
            theResponses[i] = theEle->setResponse(responseArgs, eleInfo);
            if(theResponses[i] != 0)
              {
	        // from the response type determine no of cols for each
	        Information &eleInfo = theResponses[i]->getInformation();
	        const Vector &eleData = eleInfo.getData();
	        numDbColumns += eleData.Size();
              }
          }
      }

    //
    // now create the columns strings for the data description
    // for each element do a getResponse() 
    //
    std::vector<std::string> dbColumns(numDbColumns);
    static std::string aColumn;

    int counter = 0;
    if(echoTimeFlag == true)
      {
        dbColumns[0] = "time";
        counter = 1;
      }
    
    std::string dataToStore= "";
    const size_t numArgs= getNumArgs();
    for(size_t j=0; j<numArgs; j++)
      {
        dataToStore+= responseArgs[j];
        if(j<(numArgs-1))
          dataToStore+= " ";
      }
    
    for(i=0; i<eleID.Size(); i++)
      {
        int eleTag = eleID(i);
        int numVariables = 0;
        if(theResponses[i]!=nullptr)
          {
            const XC::Information &eleInfo = theResponses[i]->getInformation();
            if(eleInfo.theType == IntType || eleInfo.theType == DoubleType)
              {
	      // create column heading for single data item for element
	      numVariables = 0;
	      //sprintf(aColumn, "Element%d_%s", eleTag, dataToStore);
                aColumn= "Element" + boost::lexical_cast<std::string>(eleTag) + "_" 
		+ dataToStore;
                dbColumns[counter] = aColumn;
	      counter++;
              }
            else if(eleInfo.theType == VectorType) 
	    numVariables = eleInfo.theVector->Size();
            else if(eleInfo.theType == IdType) 
	    numVariables = eleInfo.theID->Size();
            else if(eleInfo.theType == MatrixType) 
	    numVariables = eleInfo.theMatrix->noRows()* eleInfo.theMatrix->noCols();

            // create the column headings for multiple data for the element
            for(int j=1; j<=numVariables; j++)
              {
	      //sprintf(aColumn, "Element%d_%s_%d",eleTag, dataToStore, j);
                aColumn= "Element" + boost::lexical_cast<std::string>(eleTag) + "_" 
		                 + dataToStore + "_"
                                   + boost::lexical_cast<std::string>(j);
                dbColumns[counter] = aColumn;
	      counter++;
              }
          }
      }

    // replace spaces with undescore for tables
    for(int kk=0; kk<numDbColumns; kk++)
      replace(dbColumns[kk],' ','_');

    //
    // call open in the handler with the data description
    //

    theHandler->open(dbColumns);

    // create the vector to hold the data
    data= Vector(numDbColumns);

    initializationDone = true;
    return 0;
  }
开发者ID:lcpt,项目名称:xc,代码行数:101,代码来源:ElementRecorder.cpp

示例6: switch

void UmlOperation::import(File & f)
{
    if (scanning) {
        f.skipBlock();
        return;
    }

    QByteArray s;
    UmlTypeSpec t;

    for (;;) {
        switch (f.read(s)) {
        case -1:
            f.eof();
            throw 0;

        case ')':
            set_ReturnType(t);
            return;

        case ATOM:
            break;

        default:
            f.syntaxError(s);
        }

        // atom
        if (s == "parameters") {
            f.read("(");
            f.read("list");
            f.read("Parameters");
            importParameters(f);
        }
        else if (s == "result") {
            if (f.read(s) != STRING)
                f.syntaxError(s, "return type");

            t.explicit_type = s;
        }
        else if (s == "quidu") {
            if (f.read(s) != STRING)
                f.syntaxError(s, "wrong quidu");

            if (UmlClass::replaceType(t, s, "${type}")) {
                switch (((UmlClass *) parent())->language()) {
                case Cplusplus:
                case AnsiCplusplus:
                case VCplusplus:
                    set_CppDecl(replace(cppDecl(), "${type}", s));
                    set_CppDef(replace(cppDef(), "${type}", s));
                    break;

                case Oracle8:
                    break;

                case Corba:
                    set_IdlDecl(replace(idlDecl(), "${type}", s));
                    break;

                case Java:
                    set_JavaDecl(replace(javaDecl(), "${type}", s));
                    break;

                default:
                    break;
                }
            }
        }
        else if (s == "exceptions")
            importExceptions(f);
        else if (s == "opExportControl")
            set_Visibility(f.readVisibility());
        else
            f.skipNextForm();
    }

}
开发者ID:DoUML,项目名称:douml,代码行数:78,代码来源:UmlOperation.cpp

示例7: QObject

	ConcreteSite::ConcreteSite (const Media::LyricsQuery& query,
			const ConcreteSiteDesc& desc, ICoreProxy_ptr proxy, QObject *parent)
	: QObject (parent)
	, Query_ (query)
	, Desc_ (desc)
	{
		auto replace = [this] (QString str) -> QString
		{
			for (const auto& c : Desc_.Replacements_.keys ())
				str.replace (c, Desc_.Replacements_ [c]);
			return str;
		};

		const auto& artist = replace (query.Artist_.toLower ());
		const auto& album = replace (query.Album_.toLower ());
		const auto& title = replace (query.Title_.toLower ());

		auto urlStr = Desc_.URLTemplate_;
		urlStr.replace ("{artist}", artist);
		urlStr.replace ("{album}", album);
		urlStr.replace ("{title}", title);
		if (!artist.isEmpty ())
			urlStr.replace ("{a}", artist.at (0).toLower ());

		auto cap = [] (QString str) -> QString
		{
			if (!str.isEmpty ())
				str [0] = str [0].toUpper ();
			return str;
		};
		urlStr.replace ("{Artist}", cap (artist));
		urlStr.replace ("{Album}", cap (album));
		urlStr.replace ("{Title}", cap (title));

#ifdef QT_DEBUG
		qDebug () << Q_FUNC_INFO
				<< "requesting"
				<< urlStr
				<< "from"
				<< Desc_.Name_
				<< "for"
				<< artist
				<< album
				<< title;
#endif

		auto nam = proxy->GetNetworkAccessManager ();

		QUrl url { urlStr };
		QNetworkRequest req { url };

		url.setPath ({});
		url.setQueryItems ({});
		req.setRawHeader ("Referer", url.toString ().toUtf8 ());

		auto reply = nam->get (req);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}
开发者ID:mirok0,项目名称:leechcraft,代码行数:65,代码来源:concretesite.cpp

示例8: LOG_DEBUG

int Switch_Manager::DeleteAllWsitch(char* strUrl,char* outPutUrl,char* strSessionID)
{
	LOG_DEBUG("DEBUG - [SWM]: - DeleteAllWsitch fun \n");
	printf("---DeleteAllWsitch fun \n");
	bool bIsReplyflag = false;
		//遍历切流器 时间过长,不加锁
	pthread_mutex_lock(&m_mutexServerList);
	MapSwitchSeverInfo::iterator iterLook = m_mapSwitchServerInfo.begin();
	while(iterLook != m_mapSwitchServerInfo.end())
	{
		//
		SwitchSeverInfo *pFindSeverInfo = iterLook->second;
		if(pFindSeverInfo && pFindSeverInfo->iRunStatus == 0)  //在线的切流器
		{
				//连接server 
			//报文转发
			Stream ptmpRequest;
			int iret = ptmpRequest.ConnectServer(pFindSeverInfo->strServerIPAddr,pFindSeverInfo->iListenPort);
			if(iret != 0)
			{
				//连接失败		
				continue;
			}
			iret = ptmpRequest.Send_str(strUrl);
			if(iret != 0)
			{
				continue;
			}
			char Rcv_buf[1024]={0};
			int iLen = sizeof(Rcv_buf);
			iret = ptmpRequest.Recv_str(Rcv_buf,&iLen);
			if(iret !=0)
				continue;

			memcpy(outPutUrl,Rcv_buf,iLen);
			bIsReplyflag = true;
			outPutUrl[iLen] ='\0';

				cJSON *pcmd = NULL;

					//解析报文数据
			replace(Rcv_buf, "XXEE", "");
			cJSON* pRoot = cJSON_Parse(Rcv_buf);

			int iRet = -1;
			if (pRoot)
			{
				pcmd = cJSON_GetObjectItem(pRoot, "cmd");
				if (pcmd)
				{
					//判断请求类型
					if(strcmp(pcmd->valuestring, "reset_device") == 0)
					{
						iRet = 0;
					}
				}

			}
			if(iRet == 0)
			{
				LOG_INFO_FORMAT("INFO  - [SWM]:切流器[%s] 重置流成功 \n",pFindSeverInfo->strServerIPAddr);
				pFindSeverInfo->iStreamStatus = 0;
				pFindSeverInfo->iCurrentSwitchNumber = 0;
			}
			else
			{
				
				LOG_INFO_FORMAT("INFO  - [SWM]:切流器[%s] 重置流失败 \n",pFindSeverInfo->strServerIPAddr);
				pFindSeverInfo->iStreamStatus = 1;  //流状态异常
			}
		}
		else
			printf("---切流器 不在线 %s \n",pFindSeverInfo->strServerIPAddr);
		
		++iterLook;
	}

	pthread_mutex_unlock(&ManagerFactory::instance()->m_mutexServerList);

	if(!bIsReplyflag)
	{
		ReplyException(strUrl,outPutUrl,Error_ReSet_Device);
		LOG_INFO("INFO  - [SWM]: Delete ALL stream exception \n");
	}

	return 0;

}
开发者ID:yyd01245,项目名称:BBCV_SM_project,代码行数:88,代码来源:Switch_Manager.cpp

示例9: _

void FilesPageHandler::handle(Client &client) {
	Common::String response =
		"<html>" \
		"<head><title>ScummVM</title></head>" \
		"<body>" \
		"<p>{create_directory_desc}</p>" \
		"<form action=\"create\">" \
		"<input type=\"hidden\" name=\"path\" value=\"{path}\"/>" \
		"<input type=\"text\" name=\"directory_name\" value=\"\"/>" \
		"<input type=\"submit\" value=\"{create_directory_button}\"/>" \
		"</form>" \
		"<hr/>" \
		"<p>{upload_file_desc}</p>" \
		"<form action=\"upload?path={path}\" method=\"post\" enctype=\"multipart/form-data\">" \
		"<input type=\"file\" name=\"upload_file-f\" allowdirs multiple/>" \
		"<span>{or_upload_directory_desc}</span>" \
		"<input type=\"file\" name=\"upload_file-d\" directory webkitdirectory multiple/>" \
		"<input type=\"submit\" value=\"{upload_file_button}\"/>" \
		"</form>"
		"<hr/>" \
		"<h1>{index_of_directory}</h1>" \
		"<table>{content}</table>" \
		"</body>" \
		"</html>";
	Common::String itemTemplate = "<tr><td><img src=\"icons/{icon}\"/></td><td><a href=\"{link}\">{name}</a></td><td>{size}</td></tr>\n"; //TODO: load this template too?

																																		  // load stylish response page from the archive
	Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME);
	if (stream)
		response = HandlerUtils::readEverythingFromStream(stream);

	Common::String path = client.queryParameter("path");
	Common::String content = "";

	// show an error message if failed to list directory
	if (!listDirectory(path, content, itemTemplate)) {
		HandlerUtils::setFilesManagerErrorMessageHandler(client, _("ScummVM couldn't list the directory you specified."));
		return;
	}

	//these occur twice:
	replace(response, "{create_directory_button}", _("Create directory"));
	replace(response, "{create_directory_button}", _("Create directory"));
	replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path")));
	replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path")));
	replace(response, "{upload_files_button}", _("Upload files")); //tab
	replace(response, "{upload_file_button}", _("Upload files")); //button in the tab
	replace(response, "{create_directory_desc}", _("Type new directory name:"));
	replace(response, "{upload_file_desc}", _("Select a file to upload:"));
	replace(response, "{or_upload_directory_desc}", _("Or select a directory (works in Chrome only):"));
	replace(response, "{index_of_directory}", Common::String::format(_("Index of %s"), encodeHtmlEntities(getDisplayPath(client.queryParameter("path"))).c_str()));
	replace(response, "{content}", content);
	LocalWebserver::setClientGetHandler(client, response);
}
开发者ID:86400,项目名称:scummvm,代码行数:54,代码来源:filespagehandler.cpp

示例10: replace

String String::replace(CStrRef search, CStrRef replacement) const {
  int count;
  return replace(search, replacement, count, true);
}
开发者ID:Bharat1992,项目名称:hiphop-php,代码行数:4,代码来源:type-string.cpp

示例11: switch

void InterpretedIC::cleanup() {
  if (is_empty()) return; // Nothing to cleanup

  switch (send_type()) {
    case Bytecodes::accessor_send:    // fall through
    case Bytecodes::primitive_send:   // fall through
    case Bytecodes::predicted_send:   // fall through
    case Bytecodes::interpreted_send:
      { // check if the interpreted send should be replaced by a compiled send	 
        klassOop receiver_klass = klassOop(second_word());
        assert(receiver_klass->is_klass(), "receiver klass must be a klass");
        methodOop method = methodOop(first_word());
        assert(method->is_method(), "first word in interpreter IC must be method");
        if (!Bytecodes::is_super_send(send_code())) {
	  // super sends cannot be handled since the sending method holder is unknown at this point.
	  LookupKey key(receiver_klass, selector());
          LookupResult result = lookupCache::lookup(&key);
	  if (!result.matches(method)) {
            replace(result, receiver_klass);
	  }
	}
      }
      break;
    case Bytecodes::compiled_send:
      { // check if the current compiled send is valid
        klassOop receiver_klass = klassOop(second_word());
        assert(receiver_klass->is_klass(), "receiver klass must be a klass");
        jumpTableEntry* entry = (jumpTableEntry*) first_word();
        nmethod* nm = entry->method();
        LookupResult result = lookupCache::lookup(&nm->key);
	if (!result.matches(nm)) {
          replace(result, receiver_klass);
	}
      }
      break;
    case Bytecodes::megamorphic_send:
      // Note that with the current definition of is_empty()
      // this will not be called for normal megamorphic sends
      // since they store only the selector.
      { klassOop receiver_klass = klassOop(second_word());
	if (first_word()->is_smi()) {
	  jumpTableEntry* entry = (jumpTableEntry*) first_word();
          nmethod* nm = entry->method();
          LookupResult result = lookupCache::lookup(&nm->key);
          if (!result.matches(nm)) {
	    replace(result, receiver_klass);
	  }
	} else {
          methodOop method = methodOop(first_word());
          assert(method->is_method(), "first word in interpreter IC must be method");
          if (!Bytecodes::is_super_send(send_code())) {
	    // super sends cannot be handled since the sending method holder is unknown at this point.
	    LookupKey key(receiver_klass, selector());
            LookupResult result = lookupCache::lookup(&key);
	    if (!result.matches(method)) {
              replace(result, receiver_klass);
	    }
          }
	}
      }
      break;
    case Bytecodes::polymorphic_send:
      {
        // %implementation note:
	//   when cleaning up we can always preserve the old pic since the
	//   the only transitions are:
	//     (compiled    -> compiled)
	//     (compiled    -> interpreted)
	//     (interpreted -> compiled)
        //   in case of a super send we do not have to cleanup because
	//   no nmethods are compiled for super sends. 
	if (!Bytecodes::is_super_send(send_code())) {
          objArrayOop pic = pic_array();
          for (int index = pic->length(); index > 0; index -= 2) {
            klassOop klass = klassOop(pic->obj_at(index));
	    assert(klass->is_klass(), "receiver klass must be klass");
            oop first = pic->obj_at(index-1);
	    if (first->is_smi()) {
	      jumpTableEntry* entry = (jumpTableEntry*) first;
              nmethod* nm = entry->method();
              LookupResult result = lookupCache::lookup(&nm->key);
              if (!result.matches(nm)) {
                pic->obj_at_put(index-1, result.value());
	      }
	    } else {
              methodOop method = methodOop(first);
              assert(method->is_method(), "first word in interpreter IC must be method");
	      LookupKey key(klass, selector());
              LookupResult result = lookupCache::lookup(&key);
	      if (!result.matches(method)) {
                pic->obj_at_put(index-1, result.value());
	      }
	    }
          }
	}
      }
   }
}
开发者ID:sebkirche,项目名称:strongtalk,代码行数:98,代码来源:interpretedIC.cpp

示例12: replace

std::string Regex::Match::replace(std::string rp)
{
    ReplaceVector tmp;
    tmp.push_back(rp);
    return replace(tmp);
}
开发者ID:leonardolang,项目名称:mod-khomp-freeswitch,代码行数:6,代码来源:regex.cpp

示例13: main

int main()
{ 
	char insertString[100];
	int caseNum, index, delnum;

	linkedList_h* List;
	List = createLinkedList_h();
	do
	{
		printf("\n----------Linkedlist Menu----------\n");
		printf("\n");
		printf("1. addNode \n2. insertMNode \n3. removeNode \n4. allClear \n5. get \n6. contains \n7. indexOf \n8. size \n9. replace \n0. exit\n");
		printf("\nChoose the number which you want : ");
		scanf("%d", &caseNum);
		switch(caseNum)
		{
			case 1:
				printf("Insert string in the list : ");
	 			scanf("%s", insertString);
    				add(List, insertString);
				printList(List);
				break;
			case 2:
				printf("What is number of index that you insert string? ");
 				scanf("%d",&index);
     				printf("\n");
     				printf("String of inserted index : ");
     				scanf("%s",insertString);
     				insertMNode(List, index, insertString);
				printList(List);
				break;
			case 3:
				printf("\n What number of index that you will delete : ");
				scanf("%d", &delnum);
    				removeNode(List, delnum);
    				printList(List);
				break;
			case 4:
				printf("Delete All\n");
				clear(List);
				printList(List);
				break;
			case 5:
				printf("What is index that you want to see : ");
    				scanf("%d", &index);
    				get(List, index);
				printf("\n");
    				printList(List);
				break;
			case 6:
				printf("If you are curious about what you want, Write string : ");
				scanf("%s", insertString);
				contains(List, insertString);
				break;
			case 7:
				printf("What is word what you want to know?? \n");
				scanf("%s", insertString);
				indexOf(List, insertString);
				break;
			case 8:
				printf("\n");
				printf("Size of List : ");
				size(List);
				break;
			case 9:
				printf("what is the word to be entered? : \n");
				scanf("%s", insertString);
				printf("What is number of index what be replaced? \n");
				scanf("%d", &index);
				replace(List, index, insertString);
				printList(List);
				break;
			case 0:
				printf("EXIT\n");
				break;
			default:
				printf("Wrong number. Please write again : ");
				break;	
		}
	}while(caseNum!=0);
	return 0;
}
开发者ID:aHyunYu,项目名称:C_source_example,代码行数:82,代码来源:listtest3.c

示例14: printf

//处理MSI接口
void *SM_Control::Parse_recv_MSI_thread(void * arg)
{
	SM_Control *this0 = (SM_Control*)arg;
	int len;
	char Rcv_buf[4096];
	cJSON *pcmd = NULL;
	char cJsonBuff[1024 * 2];
	int iRecvLen = 0;
	int accept_fd = 0;
	Sockfd::iterator iterList = this0->m_MsiacceptSocket.begin();
	if(iterList != this0->m_MsiacceptSocket.end())
	{
		accept_fd = *iterList;
		this0->m_MsiacceptSocket.erase(iterList);
		printf("111222---accept_fd = %d\n",accept_fd);
		fflush(stdout);
	}
	while(1)
	{
			if(accept_fd == -1)
			{
				printf("error accept socket in msi\n");
				fflush(stdout);
				break;
			}
			memset(Rcv_buf,0,sizeof(Rcv_buf));
			int length = 0;
			int i_rc = 0, i_count = 0;
			do
			{
				i_rc = recv(accept_fd, Rcv_buf + i_count, 2000 - i_count, 0);
				if (i_rc <= 0)break;//异常关闭
				i_count += i_rc;
			} while (strstr(Rcv_buf, "XXEE") == NULL);
			iRecvLen = i_count;
			if (iRecvLen <= 0) break;
	
			printf("recv:%s \n",Rcv_buf);
			fflush(stdout);
	
					//解析报文数据
			replace(Rcv_buf, "XXEE", "");
			cJSON* pRoot = cJSON_Parse(Rcv_buf);	

			if (pRoot)
			{
				pcmd = cJSON_GetObjectItem(pRoot, "cmd");
				if (pcmd)
				{
					
					//判断请求类型
					if (strcmp(pcmd->valuestring, "stream_bind") == 0)
					{
						printf("--bind_stream request \n");
						fflush(stdout);
						//通过
						cJSON* pUserName = cJSON_GetObjectItem(pRoot, "username");
						char strUserName[128] ={0};
						if(pUserName)
							memcpy(strUserName,pUserName->valuestring,strlen(pUserName->valuestring)+1);
						cJSON* pToken = cJSON_GetObjectItem(pRoot, "token");
						char strToken[128] ={0};
						if(pToken) memcpy(strToken,pToken->valuestring,strlen(pToken->valuestring)+1);
						cJSON* pStreamID = cJSON_GetObjectItem(pRoot, "stream_id");
						int iStreamID = -1;
						if(pStreamID) iStreamID = atoi(pStreamID->valuestring);

						cJSON* pRecallAddr = cJSON_GetObjectItem(pRoot, "recall_addr");
						char strRecallAddr[128] ={0};
						if(pRecallAddr) memcpy(strRecallAddr,pRecallAddr->valuestring,strlen(pRecallAddr->valuestring)+1);

						cJSON* pSerialNo = cJSON_GetObjectItem(pRoot,"serialno");
						
						char strSerialNo[128] ={0};
						if(pSerialNo)
							memcpy(strSerialNo,pSerialNo->valuestring,strlen(pSerialNo->valuestring)+1);

						printf("istreamid=%d usename=%s token=%s \n",iStreamID,strUserName,strToken);
						this0->m_cSM_Manager->Bindagain(strUserName,iStreamID);
						fflush(stdout);
					//	printf("---request parse \n");
						int iChannelInfo=0;
						//调manager 中绑定
						int ret = this0->m_cSM_Manager->Bind_OneStream(iStreamID,strUserName,strToken,&iChannelInfo);
						
						//回复
						/*
							{"cmd":"stream_bind","ret_code":"0","serialno":"c0e1758d697841fa8dad428c23b867a7"}XXEE
						*/

						//查询高标清
/*
						StreamResource pTmpResource;
						memset(&pTmpResource,0,sizeof(pTmpResource));
						char strkey_value[64] = {0};
						sprintf(strkey_value,"%d",iStreamID);
						int iret = DBInterfacer::GetInstance()->FindOneStream(4,"iStreamID",strkey_value,&pTmpResource);
						int iwhetherhd;
						if(iret)
//.........这里部分代码省略.........
开发者ID:yyd01245,项目名称:BBCV_SM_project,代码行数:101,代码来源:SM_Control.cpp

示例15: printf

//返回的是关联的会话
int Switch_Manager::AddOneSwitch(char* strUrl,char* outPutUrl,char* strSessionID,char* inputUrl)
{
	printf("-----AddOneSwitch\n");
	LOG_DEBUG("DEBUG - [SWM]: - AddOneSwitch\n");
	
	//查找可用的sever  找使用率最小的
				//遍历切流器
	printf("-----add switch %s \n",strSessionID);
	SwitchSeverInfo **ppFindSeverInfo = (SwitchSeverInfo **)malloc(sizeof(SwitchSeverInfo *));
	memset(ppFindSeverInfo,0,sizeof(ppFindSeverInfo));

	int iRet = FindOneSwitchServer(strSessionID,ppFindSeverInfo);
	//找到对应服务器
	SwitchSeverInfo *pFindSeverInfo = NULL;
	
	if(iRet == 0 && *ppFindSeverInfo!= NULL)
	{
		//找到正在转发的流
		pFindSeverInfo = *ppFindSeverInfo;
	}
	else
	{
		//新增的转发流
		//需要根据inputip来确定使用哪个sever
		//解析出ip 端口
		int iSrcPort = 0;
		char strSrcIP[128]={0};

		char strSrcPort[32]={0};
		FindDataFromString(inputUrl,strSrcIP,strSrcPort);
		iSrcPort = atoi(strSrcPort);
		//根据IP查找sever
		iRet = FindSwitchServerFromIP(strSrcIP,ppFindSeverInfo);
		if(*ppFindSeverInfo ==NULL)
		{
			//如果没有指定ip则由调度分配
		
			iRet = GetOneSwitchServer(ppFindSeverInfo);
			if(*ppFindSeverInfo ==NULL)
			{
				printf("---no can used sever -----\n");
				
				ReplyException(strUrl,outPutUrl,Error_NO_Sever);
				
				return -1; //没有可以用的Switch_Sever;
			}
		}

		pFindSeverInfo = *ppFindSeverInfo;
	}

	//连接server 
	//报文转发
	Stream ptmpRequest;
	int iret = ptmpRequest.ConnectServer(pFindSeverInfo->strServerIPAddr,pFindSeverInfo->iListenPort);
	if(iret != 0)
	{
		//连接失败
		ReplyException(strUrl,outPutUrl,Error_Connect_Sever);
		return -1;
	}
	iret = ptmpRequest.Send_str(strUrl);
	if(iret != 0)
	{
		ReplyException(strUrl,outPutUrl,Error_Connect_Sever);
		return -1;
	}
	char Rcv_buf[1024]={0};
	int iLen = sizeof(Rcv_buf);
	iret = ptmpRequest.Recv_str(Rcv_buf,&iLen);
	if(iret !=0)
	{
		ReplyException(strUrl,outPutUrl,Error_Recv_Sever);
		return -1;
	}

	memcpy(outPutUrl,Rcv_buf,iLen);
	cJSON *pcmd = NULL;
	//解析报文数据
	replace(Rcv_buf, "XXEE", "");
	cJSON* pRoot = cJSON_Parse(Rcv_buf);
	
	if (pRoot)
	{
		pcmd = cJSON_GetObjectItem(pRoot, "cmd");
		if (pcmd)
		{
	
			//判断请求类型
			if (strcmp(pcmd->valuestring, "add_ads_stream") == 0)
			{
				printf("--add_ads_stream return \n");
				//通过
				cJSON* pSeesid = cJSON_GetObjectItem(pRoot, "sessionid");
				char strSeesionID[128] ={0};
				
				int iSeessionID = 0;
				if(pSeesid){
					iSeessionID = atoi(pSeesid->valuestring);
//.........这里部分代码省略.........
开发者ID:yyd01245,项目名称:BBCV_SM_project,代码行数:101,代码来源:Switch_Manager.cpp


注:本文中的replace函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。