本文整理汇总了C++中Poco::replaceInPlace方法的典型用法代码示例。如果您正苦于以下问题:C++ Poco::replaceInPlace方法的具体用法?C++ Poco::replaceInPlace怎么用?C++ Poco::replaceInPlace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poco
的用法示例。
在下文中一共展示了Poco::replaceInPlace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testReplaceInPlace
void StringTest::testReplaceInPlace()
{
std::string s("aabbccdd");
assert (replaceInPlace(s, std::string("aa"), std::string("xx")) == "xxbbccdd");
}
示例2: main
//.........这里部分代码省略.........
StringTokenizer tokenizer(session.socket().address().toString(), ":", StringTokenizer::TOK_TRIM); // get the request originating address:ip from the session socket initiated by HTPP; tokenize it for IP extraction
//string my_mac = getMAC((tokenizer[0]).c_str()); // call IP to MAC converter
// get response
HTTPResponse res;
istream& is = session.receiveResponse(res); // stream the request
cout << res.getStatus() << " " << res.getReason() << endl; // get the status code of the transaction
// convert the istream to sting for further processing
istreambuf_iterator<char> eos;
string s(istreambuf_iterator<char>(is), eos);
const char * cc = s.c_str();
// instantiate a rapidjson document and fill it up with the response of the negotiation request
rapidjson::Document document;
document.Parse<0>(cc);
string token = document["ConnectionToken"].GetString(); // parse the response and get the connectionToken
//=============================================
//connect to signarR using the connectionToken got previously
HTTPClientSession cs(signalr_service_url, signalr_service_port); // instantiate simple webclient
string what = "/" + signalr_url_endpoint + "/connect?transport=webSockets&connectionToken=" + urlencode(token) + "&UID=" + my_mac + "&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=10"; // compose the request string
HTTPRequest request(HTTPRequest::HTTP_GET, what, "HTTP/1.1"); // the protocol MUST be HTTP/1.1, as described in RFC6455; else the UPGRADE to websocket request will fail
request.set("Host", signalr_service_url); // specify the Host header to be sent
HTTPResponse response; // instantiate a http response
cout << response.getStatus() << " " << response.getReason() << endl;
WebSocket * ws = new WebSocket(cs, request, response); // instantiate a WebSocket transaction to the 'cs' session, sending the 'request' and storing the 'response'
//sample of a message to be sent
payload = "{\"H\":\"myhub\",\"M\":\"Send\",\"A\":[\"" + my_mac + "\",\"invoked from " + replaceInPlace(my_mac, std::string(":"), std::string("-")) + " client\"],\"I\":0}";
// cout << endl << payload << endl ;
ws->sendFrame(payload.data(), payload.size(), WebSocket::FRAME_TEXT); // send the message to signalR using the payload and setting the type of frame to be sent as FRAME_TEXT
flags = 1;
// starting the receiving loop
while( (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE ) // while websocket session open
{
n = ws->receiveFrame(buffer, sizeof(buffer), flags); // n is the received frame
// flags store the response flags of the frame
// 129 = single frame response
// 1 = start of multi-frame response
// 0 = continuation frame of a multi-frame response
// 128 = FIN frame os a multi-frame response
// signalR send data in JSON format, and it send empty messages (empty json document) on a regular basis
if( (n != 2) && flags !=1 ) // filter out empty jsons and multiframe responses (multiframe will be treated further on)
{
cout << "RCV[" << msg_cnt << "]=> " << buffer << " ===== " << unsigned(flags) << endl;
}
if(flags == 1){ // if I get a start frame of a multi-frame response means that I am getting something usefull from signalR
string str(buffer);
out += str;
// due to flag == 1, we are expecting several frames, until we got flag == 128
do{
n = ws->receiveFrame(buffer, sizeof(buffer), flags);
string str(buffer);
out += str; // we add the next frame/frames to the out variable, to construct the whole JSON message
str = "";
memset(buffer, 0, sizeof buffer); // be sure to empty the buffer to don't end up with junk
}while(flags != 128);