本文整理汇总了C++中StdString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ StdString::substr方法的具体用法?C++ StdString::substr怎么用?C++ StdString::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StdString
的用法示例。
在下文中一共展示了StdString::substr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getClassPathExt
long Universe::getClassPathExt(vector<StdString>& tokens,
const StdString& arg) const {
#define EXT_TOKENS 2
long result = ERR_SUCCESS;
long fpIndex = arg.find_last_of(fileSeparator);
long ssepIndex = arg.find(".som");
if (fpIndex == StdString::npos) { //no new path
//different from CSOM (see also HandleArguments):
//we still want to strip the suffix from the filename, so
//we set the start to -1, in order to start the substring
//from character 0. npos is -1 too, but this is to make sure
fpIndex = -1;
//instead of returning here directly, we have to remember that
//there is no new class path and return it later
result = ERR_FAIL;
} else
tokens[0] = arg.substr(0, fpIndex);
//adding filename (minus ".som" if present) to second slot
ssepIndex =
((ssepIndex != StdString::npos) && (ssepIndex > fpIndex)) ?
(ssepIndex - 1) : arg.length();
tokens[1] = arg.substr(fpIndex + 1, ssepIndex - (fpIndex));
return result;
}
示例2: getDateFormatString
StdString OracleWriter::getDateFormatString(StdString const &oValue, bool bTimestamp) const
{
StdString pattern = "0000-00-00 00:00:00";
if(oValue.length() == 10)
return "YYYY.MM.DD";
if(oValue.length() >= 19 || bTimestamp == false)
return "YYYY.MM.DD HH24:MI:SS";
pattern += ".";
StdString format = "YYYY.MM.DD HH24:MI:SS.";
StdString v = oValue.substr(pattern.length(), oValue.length());
for(size_t i = 0; i < v.length(); i++)
{
if(v[i] >= '0' && v[i] <= '9')
{
format += 'F';
continue;
}
break;
}
return format;
}
示例3: selectorToQuery
StdString SociContainer::selectorToQuery(void)
{
StdString q = getSelector();
if(q.length() == 0)
return q;
if(q[0] == '{' && q != "{}" && q.length() > 1)
q = "select * from "+ q.substr(1, q.length()-2);
else
q = mQuery;
return q;
}
示例4: setSelector
void SociContainer::setSelector(StdString const &oId)
{
Progress prg("Loading from Table ...");
if(oId.length() > 0 && oId[0] == '{') // If it is a table we select it
{
mTablename = oId.substr(1, oId.length()-2);
selectTable(mTablename, false);
}
else
mTablename = "";
super::setSelector(oId);
refreshPreview(selectorToQuery(), mPreviewLimit);
}
示例5: OutputToHTTP
/**
* 計測データをHTTPのGETメソッドのパラメータとして出力します。
* http://example.jp/record.cgi?temp=25.543&humid=45.123 のような形式でアクセスします。
*/
void OutputToHTTP(const SYSTEMTIME &currTime, double temp, double humid)
{
if(outputHTTPURL_.empty()){
return;
}
///@todo ポート指定できるようにする。
///@todo 先頭に http:// と入れても大丈夫なようにする。
const StdString::size_type firstSlashPos = outputHTTPURL_.find_first_of('/');
const StdString destHostName = (firstSlashPos != StdString::npos) ? outputHTTPURL_.substr(0, firstSlashPos) : outputHTTPURL_;
const StdString destURL = (firstSlashPos != StdString::npos) ? outputHTTPURL_.substr(firstSlashPos) : "/";
struct Local
{
static bool connectToHost(SOCKET &sock, const char *hostname)
{
sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(80);
server.sin_addr.S_un.S_addr = inet_addr(hostname);
if(server.sin_addr.S_un.S_addr == 0xffffffff) {
hostent *host = gethostbyname(hostname);
if(host == NULL){
return false;
}
unsigned int **addrptr = (unsigned int **)host->h_addr_list;
for(; *addrptr != NULL; ++addrptr){
server.sin_addr.S_un.S_addr = *(*addrptr);
if(connect(sock, (sockaddr *)&server, sizeof(server)) == 0){
break;
}
}
if(*addrptr == NULL){
return false;
}
}
else{
if (connect(sock, (sockaddr *)&server, sizeof(server)) != 0){
return false;
}
}
return true;
}
};
SOCKET sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock != INVALID_SOCKET) {
// 接続
if(Local::connectToHost(sock, destHostName.c_str())){
// リクエスト作成
char requestParams[1024];
std::sprintf(requestParams, "?temp=%lf&humid=%lf", temp, humid);
std::string request = std::string("GET ") + destURL + requestParams + " HTTP/1.0\r\n\r\n";
// HTTPリクエスト送信
bool error = false;
int n = send(sock, request.c_str(), request.size(), 0);
if(n < 0) {
error = true;
}
// HTTPメッセージ受信
std::string result;
while(n > 0){
char buf[128];
n = recv(sock, buf, sizeof(buf), 0);
if(n < 0) {
error = true;
break;
}
// 受信結果
result.append(buf, n);
}
}
closesocket(sock);
}
}
示例6: createHeader
/*!
\brief Create header of netcdf file
There are some information to fill in header of each netcdf.
*/
void CFile::createHeader(void)
{
CContext* context = CContext::getCurrent();
CContextServer* server = context->server;
if (!allDomainEmpty)
{
StdString filename = getFileOutputName();
// determine splitting format in the file name : firstPart%start_date%middlePart%end_date%lastPart
std::string strStartDate="%start_date%" ;
std::string strEndDate="%end_date%" ;
std::string firstPart ;
std::string middlePart ;
std::string lastPart ;
size_t pos1, pos2 ;
bool hasStartDate=false ;
bool hasEndDate=false ;
bool hasSplit = (!split_freq.isEmpty());
pos1=filename.find(strStartDate) ;
if (pos1!=std::string::npos)
{
firstPart=filename.substr(0,pos1) ;
pos1+=strStartDate.size() ;
hasStartDate=true ;
}
else pos1=0 ;
pos2=filename.find(strEndDate,pos1) ;
if (pos2!=std::string::npos)
{
middlePart=filename.substr(pos1,pos2-pos1) ;
pos2+=strEndDate.size() ;
lastPart=filename.substr(pos2,filename.size()-pos2) ;
hasEndDate=true ;
}
else middlePart=filename.substr(pos1,filename.size()) ;
if (!hasStartDate && !hasEndDate)
{
hasStartDate=true ;
hasEndDate=true;
firstPart=middlePart ;
if (hasSplit) firstPart +="_";
middlePart="-" ;
}
StdOStringStream oss;
if (!split_freq.isEmpty())
{
CDate split_start ;
CDate splitEnd ;
if (!split_start_offset.isEmpty()) split_start=lastSplit + split_start_offset ;
else split_start=lastSplit ;
splitEnd = lastSplit + split_freq ;
if (!split_last_date.isEmpty())
{
CDate splitLastDate=CDate::FromString(split_last_date,*CContext::getCurrent()->getCalendar()) ;
if( splitLastDate < splitEnd) splitEnd=splitLastDate ;
}
if (!split_end_offset.isEmpty()) splitEnd = splitEnd + split_end_offset;
else splitEnd = splitEnd - 1 * Second;
string splitFormat;
if (split_freq_format.isEmpty())
{
if (split_freq.getValue().second != 0) splitFormat = "%y%mo%d%h%mi%s";
else if (split_freq.getValue().minute != 0) splitFormat = "%y%mo%d%h%mi";
else if (split_freq.getValue().hour != 0) splitFormat = "%y%mo%d%h";
else if (split_freq.getValue().day != 0) splitFormat = "%y%mo%d";
else if (split_freq.getValue().month != 0) splitFormat = "%y%mo";
else splitFormat = "%y";
}
else splitFormat = split_freq_format;
oss << firstPart ;
if (hasStartDate) oss << split_start.getStr(splitFormat) ;
oss << middlePart ;
if (hasEndDate) oss << splitEnd.getStr(splitFormat);
oss << lastPart ;
StdString keySuffix("CContext_"+CContext::getCurrent()->getId()+"::CFile_"+getFileOutputName()+"::") ;
context->registryOut->setKey(keySuffix+"splitStart", lastSplit);
context->registryOut->setKey(keySuffix+"splitEnd", splitEnd);
}
else oss<<firstPart<<lastPart ;
bool append = !this->append.isEmpty() && this->append.getValue();
bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic;
//.........这里部分代码省略.........