本文整理汇总了C++中sql::SQLString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ SQLString::substr方法的具体用法?C++ SQLString::substr怎么用?C++ SQLString::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sql::SQLString
的用法示例。
在下文中一共展示了SQLString::substr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseUri
/* URI formats tcp://[host]:port/schema
unix://socket
pipe://named_pipe
*/
bool parseUri(const sql::SQLString & str, MySQL_Uri& uri)
{
if (!str.compare(0, sizeof(MYURI_SOCKET_PREFIX) - 1, MYURI_SOCKET_PREFIX))
{
uri.setSocket(str.substr(sizeof(MYURI_SOCKET_PREFIX) - 1, sql::SQLString::npos));
return true;
}
if (!str.compare(0, sizeof(MYURI_PIPE_PREFIX) - 1 , MYURI_PIPE_PREFIX))
{
uri.setPipe(str.substr(sizeof(MYURI_PIPE_PREFIX) - 1, sql::SQLString::npos));
return true;
}
sql::SQLString host;
size_t start_sep, end_sep;
/* i wonder how did it work with "- 1"*/
if (!str.compare(0, sizeof(MYURI_TCP_PREFIX) - 1, MYURI_TCP_PREFIX) )
{
host= str.substr(sizeof(MYURI_TCP_PREFIX) - 1, sql::SQLString::npos);
}
else
{
/* allowing to have port and schema specified even w/out protocol
specifier("tcp://") */
host= str.c_str();
}
if (host[0] == MYURI_HOST_BEGIN)
{
end_sep= host.find(MYURI_HOST_END);
/* No closing ] after [*/
if (end_sep == sql::SQLString::npos)
{
return false;
}
uri.setHost(host.substr(1, end_sep - 1));
/* Cutting host to continue w/ port and schema reading */
host= host.substr(end_sep + 1);
}
/* Looking where schema part begins */
start_sep = host.find('/');
if (start_sep != sql::SQLString::npos)
{
if ((host.length() - start_sep) > 1/*Slash*/)
{
uri.setSchema(host.substr(start_sep + 1, host.length() - start_sep - 1));
}
host= host.substr(0, start_sep);
}
else
{
uri.setSchema("");
}
/* Looking where port part begins*/
start_sep = host.find_last_of(':', sql::SQLString::npos);
if (start_sep != sql::SQLString::npos)
{
uri.setPort(atoi(host.substr(start_sep + 1, sql::SQLString::npos).c_str()));
host = host.substr(0, start_sep);
}
else
{
uri.setPort(DEFAULT_TCP_PORT);
}
/* If host was enclosed in [], it has been already set, and "host" variable is
empty */
if (host.length() > 0)
{
uri.setHost(host);
}
return true;
}