mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add husky server.cpp into demo
This commit is contained in:
parent
b2d6fbbbe5
commit
9cf476086f
@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
sh start.sh
|
||||
echo "stop ..."
|
||||
sh stop.sh
|
||||
echo "start ..."
|
||||
sh start.sh
|
||||
|
||||
|
@ -26,8 +26,12 @@ class ServerDemo: public IRequestHandler
|
||||
public:
|
||||
virtual bool do_GET(const HttpReqInfo& httpReq, string& strSnd)
|
||||
{
|
||||
//HttpReqInfo info = httpReq;
|
||||
strSnd = httpReq.toString();
|
||||
string sentence, tmp;
|
||||
vector<string> words;
|
||||
httpReq.GET("key", tmp);
|
||||
URLDecode(tmp, sentence);
|
||||
_segment.cut(sentence, words);
|
||||
vecToString(words, strSnd);
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
|
@ -16,6 +16,65 @@ namespace Husky
|
||||
static const char* const KEY_PATH = "PATH";
|
||||
static const char* const KEY_PROTOCOL = "PROTOCOL";
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
inline BYTE toHex(BYTE x)
|
||||
{
|
||||
return x > 9 ? x -10 + 'A': x + '0';
|
||||
}
|
||||
|
||||
inline BYTE fromHex(BYTE x)
|
||||
{
|
||||
return isdigit(x) ? x-'0' : x-'A'+10;
|
||||
}
|
||||
|
||||
inline void URLEncode(const string &sIn, string& sOut)
|
||||
{
|
||||
for( size_t ix = 0; ix < sIn.size(); ix++ )
|
||||
{
|
||||
BYTE buf[4];
|
||||
memset( buf, 0, 4 );
|
||||
if( isalnum( (BYTE)sIn[ix] ) )
|
||||
{
|
||||
buf[0] = sIn[ix];
|
||||
}
|
||||
//else if ( isspace( (BYTE)sIn[ix] ) ) //貌似把空格编码成%20或者+都可以
|
||||
//{
|
||||
// buf[0] = '+';
|
||||
//}
|
||||
else
|
||||
{
|
||||
buf[0] = '%';
|
||||
buf[1] = toHex( (BYTE)sIn[ix] >> 4 );
|
||||
buf[2] = toHex( (BYTE)sIn[ix] % 16);
|
||||
}
|
||||
sOut += (char *)buf;
|
||||
}
|
||||
};
|
||||
|
||||
inline void URLDecode(const string &sIn, string& sOut)
|
||||
{
|
||||
for( size_t ix = 0; ix < sIn.size(); ix++ )
|
||||
{
|
||||
BYTE ch = 0;
|
||||
if(sIn[ix]=='%')
|
||||
{
|
||||
ch = (fromHex(sIn[ix+1])<<4);
|
||||
ch |= fromHex(sIn[ix+2]);
|
||||
ix += 2;
|
||||
}
|
||||
else if(sIn[ix] == '+')
|
||||
{
|
||||
ch = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = sIn[ix];
|
||||
}
|
||||
sOut += (char)ch;
|
||||
}
|
||||
}
|
||||
|
||||
class HttpReqInfo
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user