这篇教程C++ substr函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中substr函数的典型用法代码示例。如果您正苦于以下问题:C++ substr函数的具体用法?C++ substr怎么用?C++ substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了substr函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ifvoid StateGraphViewerPanel::OnMouseOver(std::string const &NodeID){ auto const Unescaped = wxURI::Unescape(NodeID).ToStdString(); auto const SpacePos = Unescaped.find(' '); auto const NodeType = Unescaped.substr(0, SpacePos); std::shared_ptr<Displayable const> NodeDisplayable; if (NodeType == "value") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto const &Value = *reinterpret_cast<seec::cm::Value const *>(ID); NodeDisplayable = std::make_shared<DisplayableValue>(Value); } else if (NodeType == "dereference") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto const &Ptr = *reinterpret_cast<seec::cm::ValueOfPointer const *>(ID); NodeDisplayable = std::make_shared<DisplayableDereference>(Ptr); } else if (NodeType == "function") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto &Fn = *reinterpret_cast<seec::cm::FunctionState *>(ID); NodeDisplayable = std::make_shared<DisplayableFunctionState>(Fn); } else if (NodeType == "local") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto const &Local = *reinterpret_cast<seec::cm::LocalState const *>(ID); NodeDisplayable = std::make_shared<DisplayableLocalState>(Local); } else if (NodeType == "param") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto const &Param = *reinterpret_cast<seec::cm::ParamState const *>(ID); NodeDisplayable = std::make_shared<DisplayableParamState>(Param); } else if (NodeType == "global") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(NodeData); auto const &GV = *reinterpret_cast<seec::cm::GlobalVariable const *>(ID); NodeDisplayable = std::make_shared<DisplayableGlobalVariable>(GV); } else if (NodeType == "area") { auto const NodeData = Unescaped.substr(SpacePos + 1); auto const Comma1 = NodeData.find(','); if (Comma1 == std::string::npos) { wxLogDebug("Bad area node data: %s", wxString{NodeData}); return; } auto const Comma2 = NodeData.find(',', Comma1 + 1); if (Comma2 == std::string::npos) { wxLogDebug("Bad area node data: %s", wxString{NodeData}); return; } auto const StrStart = NodeData.substr(0, Comma1); auto const StrEnd = NodeData.substr(Comma1 + 1, Comma2 - Comma1); auto const StrID = NodeData.substr(Comma2 + 1); auto const Start = seec::callbackfs::ParseImpl<uint64_t>::impl(StrStart); auto const End = seec::callbackfs::ParseImpl<uint64_t>::impl(StrEnd); auto const ID = seec::callbackfs::ParseImpl<uintptr_t>::impl(StrID); auto const &Ptr = *reinterpret_cast<seec::cm::ValueOfPointer const *>(ID); NodeDisplayable = std::make_shared<DisplayableReferencedArea> (Start, End, Ptr); } else if (NodeType != "null"){ wxLogDebug("Bad node: %s", wxString{Unescaped}); return; } // If the node was Displayable, push the event to the GUI thread. MouseOverDisplayableEvent Ev { SEEC_EV_MOUSE_OVER_DISPLAYABLE, this->GetId(), std::move(NodeDisplayable) }; Ev.SetEventObject(this); this->GetEventHandler()->AddPendingEvent(Ev);}
开发者ID:mheinsen,项目名称:seec,代码行数:86,
示例2: while/** * This follows the Java URI algorithm: * 1. All "." segments are removed. * 2. If a ".." segment is preceded by a non-".." segment * then both of these segments are removed. This step * is repeated until it is no longer applicable. * 3. If the path is relative, and if its first segment * contains a colon character (':'), then a "." segment * is prepended. This prevents a relative URI with a path * such as "a:b/c/d" from later being re-parsed as an * opaque URI with a scheme of "a" and a scheme-specific * part of "b/c/d". (Deviation from RFC 2396) */void URI::normalize(){ std::vector< std::vector<int> > segments; //## Collect segments if (path.size()<2) return; bool abs = false; int pos=0; int len = (int) path.size(); if (path[0]=='/') { abs = true; pos++; } while (pos < len) { int pos2 = find(path, '/', pos); if (pos2 < 0) { std::vector<int> seg = substr(path, pos, path.size()-pos); //printf("last segment:%s/n", toStr(seg).c_str()); segments.push_back(seg); break; } if (pos2>pos) { std::vector<int> seg = substr(path, pos, pos2-pos); //printf("segment:%s/n", toStr(seg).c_str()); segments.push_back(seg); } pos = pos2; pos++; } //## Clean up (normalize) segments bool edited = false; std::vector< std::vector<int> >::iterator iter; for (iter=segments.begin() ; iter!=segments.end() ; ) { std::vector<int> s = *iter; if (sequ(s,".")) { iter = segments.erase(iter); edited = true; } else if (sequ(s, "..") && iter != segments.begin() && !sequ(*(iter-1), "..")) { --iter; //back up, then erase two entries iter = segments.erase(iter); iter = segments.erase(iter); edited = true; } else ++iter; } //## Rebuild path, if necessary if (edited) { path.clear(); if (abs) { path.push_back('/'); } std::vector< std::vector<int> >::iterator iter; for (iter=segments.begin() ; iter!=segments.end() ; ++iter) { if (iter != segments.begin()) path.push_back('/'); std::vector<int> seg = *iter; for (unsigned int i = 0; i<seg.size() ; i++) path.push_back(seg[i]); } }}
开发者ID:Spin0za,项目名称:inkscape,代码行数:93,
示例3: ifvoidMultivariateModel::UpdateModel(const Realizations &R, int Type, const std::vector<std::string, std::allocator<std::string>> Names){ /// Given a list of names (which in fact corresponds to the variables that have potentially changed), /// the function updates the parameters associated to these names /// Possible parameters to update, depending on the name being in "vect<> Names" bool ComputeG = false; bool ComputeDelta = false; bool ComputeBasis = false; bool ComputeA = false; bool ComputeSpaceShift = false; bool ComputeBlock_ = false; bool IndividualOnly = (Type > -1); /// Parameters to update, depending on the names called for(auto it = Names.begin(); it != Names.end(); ++it) { std::string Name = it->substr(0, it->find_first_of("#")); if(Name == "None") { continue; } else if(Name == "Ksi" or Name == "Tau") { continue; } else if("G" == Name) { IndividualOnly = false; ComputeBasis = true; ComputeA = true; ComputeSpaceShift = true; ComputeBlock_ = true; } else if("Delta" == Name) { IndividualOnly = false; ComputeBasis = true; ComputeA = true; ComputeSpaceShift = true; ComputeBlock_ = true; } else if("Beta" == Name) { IndividualOnly = false; ComputeA = true; ComputeSpaceShift = true; } else if("S" == Name) { ComputeSpaceShift = true; } else if("All" == Name) { ComputeSubjectTimePoint(R, -1); IndividualOnly = false; ComputeG = true; ComputeDelta = true; ComputeBasis = true; ComputeA = true; ComputeSpaceShift = true; ComputeBlock_ = true; } else { std::cerr << "The realization does not exist in the multivariate model > update model" << std::endl; } } // TODO : To parse it even faster, update just the coordinates within the names if(IndividualOnly) ComputeSubjectTimePoint(R, Type); if(ComputeG) m_G = exp(R.at("G", 0)); if(ComputeDelta) ComputeDeltas(R); if(ComputeBasis) ComputeOrthonormalBasis(); if(ComputeA) ComputeAMatrix(R); if(ComputeSpaceShift) ComputeSpaceShifts(R); if(ComputeBlock_) ComputeBlock(R);}
开发者ID:Symcies,项目名称:RiemAlzh,代码行数:84,
示例4: help_func/* * Function to print help. The help argument is in argv[0] here. */static voidhelp_func(int argc, char *argv[]){ struct help_file hfile; struct help_pos match, last_match; const char *line; char key[100]; int level; int i, has_sub_topics; memset(&hfile, 0, sizeof(hfile)); memset(&match, 0, sizeof(match)); memset(&last_match, 0, sizeof(last_match)); if (argc == 0) { /* only 'help' - show intro */ if ((argv[0] = strdup("intro")) == NULL) err(1, NULL); argc = 1; } optind = 0; match.pos = -1; last_match.pos = -1; for (;;) { /* read next line */ if ((line = help_next_line(&hfile)) == NULL) { /* EOF */ level = 999; goto stop; } if (line[0] != '^' || line[1] == '^') continue; if (sscanf(line + 1, "%d%99s", &level, key) != 2) errx(1, "error in help file '%s'", line); if (level < optind) { stop: /* next higher level entry - stop this level */ if (match.pos == -1) { /* not found */ goto not_found; } /* go back to the match */ help_file_seek(&hfile, &match); last_match = match; memset(&match, 0, sizeof(match)); match.pos = -1; /* go to next key */ if (++optind >= argc) break; } if (level == optind) { if (substr(argv[optind], key)) { if (match.pos != -1) { printf("Ambiguous topic."); goto list_topics; } help_file_tell(&hfile, &match); } } } /* before breaking above we have seeked back to the matching point */ for (;;) { if ((line = help_next_line(&hfile)) == NULL) break; if (line[0] == '#') continue; if (line[0] == '^') { if (line[1] == '^') continue; break; } if (strncmp(line, "$MAIN", 5) == 0) { help_get_0topics(&hfile); continue; } printf("%s", line); } exit(0); not_found: printf("Topic not found."); list_topics: printf(" Use one of:/natmconfig help"); for (i = 0; i < optind; i++) printf(" %s", argv[i]); printf(" ["); /* list all the keys at this level *///.........这里部分代码省略.........
开发者ID:AhmadTux,项目名称:freebsd,代码行数:101,
示例5: mainint main(){ int userid; int allgood=0; char sline[LINELEN], line[LINELEN]; MYSQL_RES *res; MYSQL_ROW row; char email[255]; char title[255]; char content[4096]; //FIXME char query[4096]; // too // extract email addr while(!feof(stdin)) { fgets(line, LINELEN, stdin); substr(sline, line, 0, 6); if(!strcmp(sline, "From: ")) { emailtrim(line, email); if (allgood==1) break; else allgood=1; } substr(sline, line, 0, 8); if(!strcmp(sline, "Subject:")) { substr(title, line, 8, strlen(line)-8); if(allgood==1) break; else allgood=1; } } //skip headers while(!feof(stdin)) { fgets(line, LINELEN, stdin); if(!strcmp(line, "/n")) break; } while(!feof(stdin)) { fgets(line, LINELEN, stdin); if(strcmp(sline, line)) strncat(content, line, 4096); strcpy(sline, line); } if(strlen(email) > 254 || strlen(title) > 254 || strlen(content) > 4094) { fprintf(stderr, "one or more fields are too long"); return(1); } printf("mail: %s/n", email); printf("cim: %s/n", title); printf("stuff: %s/n", content); //return(0); if(!(sock = mysql_real_connect(&demo_db, HOST, USERNAME, PASSWD, DBNAME, 0, MYSQL_UNIX_ADDR,0))) { printf("Connecting failed: %s/n", mysql_error(&demo_db)); return(1); } sprintf(query, "SELECT id FROM users WHERE email='%s'", email); if(mysql_query(sock, query)) { printf("Query failed: %s/n", mysql_error(&demo_db)); return(1); } res=mysql_store_result(&demo_db); /* Download result from server */ if(!(row=mysql_fetch_row(res))) /* Get a row from the results */ { printf("no such user/n"); return(1); } userid = atoi(row[0]); mysql_free_result(res); /* Release memory used to store results. */ sprintf(query, "INSERT INTO posts (userid, title, content, modositas, letrehozas) VALUES (%d, '%s', '%s', NOW(), NOW())", userid, addslashes(title), addslashes(content)); if(mysql_query(sock, query)) { printf("Query failed: %s/n", mysql_error(&demo_db)); return(1); } mysql_close(&demo_db); return(0);}
开发者ID:vmiklos,项目名称:openblog,代码行数:94,
示例6: parse_body_infoBool parse_body_info(char * body_info, BStateInfo *bsinfo){ char s1[10],s2[10],s3[10],temp[BUFSIZE1]; s1[0] = s2[0] = s3[0] = temp[0] = '/0' ; substr(temp,body_info,1,strlen(body_info)-2); sscanf(temp,"%s %s %s",s1,s2,s3); if (s1[0] == '/0') { return FALSE ; } if(!strcmp(s1,"view_mode")) { if (s2[0] == 'h') /* high */ bsinfo->quality = VQ_high ; else if (s2[0] == 'l') /* low */ bsinfo->quality = VQ_low ; else bsinfo->quality = VQ_Error ; if (s3[0] == 'n' ) { /* normal or narrow */ if (s3[1] == 'o') /* normal */ bsinfo->width = VW_Normal ; else if (s3[1] == 'a') bsinfo->width = VW_Narrow ; else bsinfo->width = VW_Error ; } else if (s3[0] == 'w') /* wide */ bsinfo->width = VW_Wide ; else bsinfo->width = VW_Error ; } else if(!strcmp(s1,"stamina")) { if (s2[0] == '/0') bsinfo->short_stamina = Stamina_Error ; else bsinfo->short_stamina = atof(s2); if (s3[0] == '/0') bsinfo->long_stamina = Stamina_Error ; else bsinfo->long_stamina = atof(s3); } else if (!strcmp(s1,"speed")) { if (s2[0] == '/0') bsinfo->speed = Speed_Error ; else bsinfo->speed = atof(s2) ; } else if (!strcmp(s1,"kick")) { if (s2[0] == '/0') bsinfo->kick = Kick_Error ; else bsinfo->kick = atoi(s2) ; } else if (!strcmp(s1,"dash")) { if (s2[0] == '/0') bsinfo->dash = Kick_Error ; else bsinfo->dash = atoi(s2) ; } else if (!strcmp(s1,"turn")) { if (s2[0] == '/0') bsinfo->turn = Turn_Error ; else bsinfo->turn = atoi(s2) ; } else if (!strcmp(s1,"say")) { if (s2[0] == '/0') bsinfo->say = Say_Error ; else bsinfo->say = atoi(s2) ; } else return FALSE ; return TRUE ;}
开发者ID:BackupTheBerlios,项目名称:soop,代码行数:75,
示例7: sendMessageint sendMessage(MESSAGE *m) { int i, bcc = 0, error = 0; char ocp[3], oc[3], cmd[3], head[7], message[m->message_length]; /* convert HEX to string */ if (m->message_type == 'A') { convert(cmd, m->command); } else { convert(ocp, m->op_code_page); convert(oc, m->op_code); } if (getDebug() > 0) { puts(">>>> >>> >> >"); puts("I: Preparing message:"); } /* create head string */ sprintf(head, "%c%c%c%c%c%s", m->soh, m->reserve, m->destination, m->source, m->message_type, int2strhex(m->message_length, 2) ); if (getDebug() > 0) { printf(" * Head = ["); print(7, head); printf("]/n"); } /* create message string */ if (m->message_type == 'A') /* command */ sprintf(message, "%c%s%c", m->stx, cmd, m->etx ); else if (m->message_type == 'C') /* get current parameter */ sprintf(message, "%c%s%s%c", m->stx, ocp, oc, m->etx ); else if (m->message_type == 'E') /* set parameter message */ sprintf(message, "%c%s%s%s%c", m->stx, ocp, oc, m->value, m->etx ); if (getDebug() > 0) { printf(" * Message = ["); print(m->message_length, message); printf("]/n"); } /* count check code */ for (i=1; i<7; i++) bcc ^= head[i]; for (i=0; i<m->message_length; i++) bcc ^= message[i]; if (getDebug() > 0) { printf(" * Check code = [%#x]/n", bcc); printf(" * Delimiter = [%#x]/n", m->cr); } m->msg = calloc(19, sizeof(char)); sprintf(m->msg, "%s%s%c%c", head, message, bcc, m->cr); m->replay = NULL; send_message(m->msg, &m->replay); if (getDebug() > 0 && m->replay == NULL) perror("E: No replay!"); else if (getDebug() > 1 && m->replay != NULL) { REPLAY r; r.initReplay = initReplay; r.initReplay(&r, &m->replay); r.printReplay = printReplay; r.printReplay(&r); } if (m->replay == NULL || strcmp(substr(m->replay, 8, 2), "00") != 0) error = -1; if (getDebug() > 0 ) puts("< << <<< <<<<"); return error;}
开发者ID:jtyr,项目名称:neclcd,代码行数:99,
示例8: switch const Selector::MatchResult AttributeSelector::Match(const Node* node) const { switch (m_operator) { case SelectorOperator::Exists: { if (node->HasAttribute(m_attributeNameRef)) { return MatchResult(node); } } break; case SelectorOperator::ValueContains: { auto attributeValue = node->GetAttributeValue(m_attributeNameRef); if (attributeValue.size() == 0) { return nullptr; } // Just do a search auto searchResult = attributeValue.find(m_attributeValueRef); // Simply return whether or not we got any matches. if (searchResult != boost::string_ref::npos) { return MatchResult(node); } } break; case SelectorOperator::ValueEquals: { auto attributeValue = node->GetAttributeValue(m_attributeNameRef); auto oneSize = attributeValue.size(); auto twoSize = m_attributeValueRef.size(); if (oneSize == 0 || oneSize != twoSize) { return nullptr; } if (oneSize >= 4) { if ((attributeValue[0] == m_attributeValueRef[0]) && (attributeValue[1] == m_attributeValueRef[1]) && (attributeValue[oneSize - 1] == m_attributeValueRef[oneSize - 1]) && (attributeValue[oneSize - 2] == m_attributeValueRef[oneSize - 2])) { if (std::memcmp(attributeValue.begin(), m_attributeValueRef.begin(), oneSize) == 0) { return MatchResult(node); } } } else { if (std::memcmp(attributeValue.begin(), m_attributeValueRef.begin(), oneSize) == 0) { return MatchResult(node); } } return nullptr; } break; case SelectorOperator::ValueHasPrefix: { auto attributeValue = node->GetAttributeValue(m_attributeNameRef); auto subSize = m_attributeValueRef.size(); if (attributeValue.size() == 0 || attributeValue.size() <= subSize) { return nullptr; } auto sub = attributeValue.substr(0, subSize); subSize = sub.size(); if (subSize == m_attributeValueRef.size()) { if (subSize >= 4) { if ((sub[0] == m_attributeValueRef[0]) && (sub[1] == m_attributeValueRef[1]) && (sub[subSize - 1] == m_attributeValueRef[subSize - 1]) && (sub[subSize - 2] == m_attributeValueRef[subSize - 2])) { if (std::memcmp(sub.begin(), m_attributeValueRef.begin(), subSize) == 0) { return MatchResult(node); } } }//.........这里部分代码省略.........
开发者ID:TechnikEmpire,项目名称:GQ,代码行数:101,
示例9: ifstd::vector<cleaver::AbstractScalarField*>NRRDTools::segmentationToIndicatorFunctions(std::string filename, double sigma) { // read file using ITK if (filename.find(".nrrd") != std::string::npos) { itk::NrrdImageIOFactory::RegisterOneFactory(); } else if (filename.find(".mha") != std::string::npos) { itk::MetaImageIOFactory::RegisterOneFactory(); } ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(filename); reader->Update(); ImageType::Pointer image = reader->GetOutput(); //determine the number of labels in the segmentations ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New(); imageCalculatorFilter->SetImage(reader->GetOutput()); imageCalculatorFilter->Compute(); auto maxLabel = static_cast<size_t>(imageCalculatorFilter->GetMaximum()); auto minLabel = static_cast<size_t>(imageCalculatorFilter->GetMinimum()); std::vector<cleaver::AbstractScalarField*> fields; //extract images from each label for an indicator function for (size_t i = minLabel, num = 0; i <= maxLabel; i++, num++) { //pull out this label ThreshType::Pointer thresh = ThreshType::New(); thresh->SetInput(image); thresh->SetOutsideValue(0); thresh->ThresholdOutside(static_cast<double>(i) - 0.001, static_cast<double>(i) + 0.001); thresh->Update(); //change the values to be from 0 to 1 MultiplyImageFilterType::Pointer multiplyImageFilter = MultiplyImageFilterType::New(); multiplyImageFilter->SetInput(thresh->GetOutput()); multiplyImageFilter->SetConstant(1. / static_cast<double>(i)); multiplyImageFilter->Update(); //do some blurring GaussianBlurType::Pointer blur = GaussianBlurType::New(); blur->SetInput(multiplyImageFilter->GetOutput()); blur->SetVariance(sigma * sigma); blur->Update(); //find the average value between ImageCalculatorFilterType::Pointer calc = ImageCalculatorFilterType::New(); calc->SetImage(blur->GetOutput()); calc->Compute(); float mx = calc->GetMaximum(); float mn = calc->GetMinimum(); auto md = (mx + mn) / 2.f; //create a distance map with that minimum value as the levelset DMapType::Pointer dm = DMapType::New(); dm->SetInput(blur->GetOutput()); dm->SetInsideValue(md + 0.1f); dm->SetOutsideValue(md -0.1f); dm->Update(); //MultiplyImageFilterType::Pointer mult = // MultiplyImageFilterType::New(); //mult->SetInput(blur->GetOutput()); //mult->SetConstant(-20. / (mx - mn)); //mult->Update(); /*SubtractImageFilterType::Pointer subtractFilter = SubtractImageFilterType::New(); subtractFilter->SetInput1(mult->GetOutput()); subtractFilter->SetConstant2(1.); subtractFilter->Update();*/ //convert the image to a cleaver "abstract field" auto img = dm->GetOutput(); auto region = img->GetLargestPossibleRegion(); auto numPixel = region.GetNumberOfPixels(); float *data = new float[numPixel]; auto x = region.GetSize()[0], y = region.GetSize()[1], z = region.GetSize()[2]; fields.push_back(new cleaver::FloatField(data, x, y, z)); auto beg = filename.find_last_of("/") + 1; auto name = filename.substr(beg, filename.size() - beg); auto fin = name.find_last_of("."); name = name.substr(0, fin); std::stringstream ss; ss << name << i; fields[num]->setName(ss.str()); itk::ImageRegionConstIterator<ImageType> imageIterator(img, region); size_t pixel = 0; while (!imageIterator.IsAtEnd()) { // Get the value of the current pixel float val = static_cast<float>(imageIterator.Get()); ((cleaver::FloatField*)fields[num])->data()[pixel++] = -val; ++imageIterator; } auto spacing = img->GetSpacing(); ((cleaver::FloatField*)fields[num])->setScale( cleaver::vec3(spacing[0], spacing[1], spacing[2])); //NRRDTools::saveNRRDFile(fields[num], "a" + std::to_string(num)); } return fields;}
开发者ID:pip010,项目名称:Cleaver2,代码行数:93,
示例10: Run//.........这里部分代码省略......... }); Then("the output is as expected", [&]() { auto stringVal = m_actualOutput.str(); auto startOfTime = stringVal.find('['); auto endOfTime = stringVal.find(']'); stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1); AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture/n/t/t/tThen: then /n/tFinally: finally/n/nFinished!/nRan: 1/nSucceeded: 1/n")); }); When("running a test fixture with a Given When Then Finally and the Then fails with an std::exception", [&]() { m_output->Begin(); m_output->BeginFixture("fixture"); m_output->BeginTest(); m_output->BeginGiven("given"); m_output->EndGiven("given"); m_output->BeginWhen("when"); m_output->EndWhen("then"); m_output->BeginThen("then"); m_output->OnError(std::runtime_error("error")); m_output->EndThen("then"); m_output->BeginFinally("finally"); m_output->EndFinally("finally"); m_output->EndTest(); m_output->EndFixture("fixture"); m_output->Finish(1, 0); }); Then("the output is as expected", [&]() { auto stringVal = m_actualOutput.str(); auto startOfTime = stringVal.find('['); startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime; auto endOfTime = stringVal.find(']'); endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1; stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1); AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture/n/tGiven: given/n/t/tWhen: when/n/t/t/tThen: then/n/tFailed: std::exception was thrown [what(): error]/n/tFinally: finally/n/nFinished!/nRan: 1/nSucceeded: 0/n")); }); When("running a test fixture with a Given When Then Finally and the Then fails with an unknown error", [&]() { m_output->Begin(); m_output->BeginFixture("fixture"); m_output->BeginTest(); m_output->BeginGiven("given"); m_output->EndGiven("given"); m_output->BeginWhen("when"); m_output->EndWhen("then"); m_output->BeginThen("then"); m_output->OnUnknownError(); m_output->EndThen("then"); m_output->BeginFinally("finally"); m_output->EndFinally("finally"); m_output->EndTest(); m_output->EndFixture("fixture"); m_output->Finish(1, 0); }); Then("the output is as expected", [&]() { auto stringVal = m_actualOutput.str(); auto startOfTime = stringVal.find('['); startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;
开发者ID:JerYme,项目名称:UnitTest11,代码行数:67,
示例11: HRF//.........这里部分代码省略.........STRING_T *tempname = NULL, *cseq = NULL, *fullseq = NULL, *buffer = NULL, *restype = NULL;STRING_T *temp = NULL, *amberhome = NULL;STRING_T *resout = NULL, *strname = NULL;INT_T nres, nresh, i, hxmul, count, chain, begin, end;FILE_T *infile, *outfile;STRING_T *__st0001__ = NULL;CURHASH_T __cht0001__;CURHASH_T __cht0002__;CURHASH_T __cht0003__;CURHASH_T __cht0004__;CURHASH_T __cht0005__;HRF( &hxht, "arna", 3 ) = 2.810000E+00;HRF( &hxht, "aprna", 3 ) = 3.000000E+00;HRF( &hxht, "lbdna", 3 ) = 3.380000E+00;HRF( &hxht, "abdna", 3 ) = 3.380000E+00;HRF( &hxht, "sbdna", 3 ) = - 3.380000E+00;HRF( &hxht, "adna", 3 ) = 2.560000E+00;HRF( &hxrep, "arna", 3 ) = 3.270000E+01;HRF( &hxrep, "aprna", 3 ) = 3.000000E+01;HRF( &hxrep, "lbdna", 3 ) = 3.600000E+01;HRF( &hxrep, "abdna", 3 ) = 3.600000E+01;HRF( &hxrep, "sbdna", 3 ) = 3.600000E+01;HRF( &hxrep, "adna", 3 ) = 3.270000E+01;NAB_strcpy( &temp, wc_complement( seq, STEMP( __st0001__, NAB_strcat( *acid_type, "amber94.rlb" ) ), acid_type ) );NAB_strcpy( &cseq, "" );for( i = length( temp );i >= 1;i -- ){NAB_strcpy( &cseq, NAB_strcat( cseq, substr( temp, i, 1 ) ) );}NAB_strcpy( &fullseq, NAB_strcat( *seq, cseq ) );nresh = length( *seq );nres = length( fullseq );if( !( NAB_strcpy( &amberhome, getenv( "AMBERHOME" ) ) ) ){fprintf( stderr, "AMBERHOME not defined./n" );exit( 1 );}NAB_strcpy( &temp, NAB_strcat( amberhome, NAB_strcat( "/dat/fd_data/", NAB_strcat( *helix_type, ".dat" ) ) ) );infile = fopen( temp, "r" );if( infile == NULL ){fprintf( stderr, "Unable to open data file %s; exiting/n", temp );exit( 1 );}outfile = fopen( "nab_tmp.pdb", "w" );while( NAB_strcpy( &buffer, NAB_getline( infile ) ) ){sscanf( buffer, "%s %lf %lf %lf %s", NAB_readstring( &tempname ), &temp_r, &temp_phi, &temp_zz, NAB_readstring( &restype ) );if( ( EQ( restype, "A" ) ) || ( EQ( restype, "a" ) ) ){HRF( &ade_r, tempname, 3 ) = temp_r;
开发者ID:tgorkovets,项目名称:MYSOFT,代码行数:67,
示例12: jx_sqlUpsert/* ------------------------------------------------------------- */LGL jx_sqlUpsert (BOOL update, PUCHAR table , PJXNODE pSqlParms , PUCHAR where){ LONG attrParm; LONG i; UCHAR sqlTempStmt[32766]; PUCHAR stmt = sqlTempStmt; PJXNODE pNode; PUCHAR comma = ""; PUCHAR name, value; SQLSMALLINT length; SQLHDBC hdbctmp; SQLHSTMT hstmttmp; SQLRETURN rc; PJXSQL pSQL = jx_sqlNewStatement (NULL); SQLCHUNK sqlChunk[32]; SHORT sqlChunkIx =0; PUCHAR sqlNullPtr = NULL; // First get the columen types - by now we use a select to mimic that // allocate a statement handle pSQL->rc = SQLAllocHandle(SQL_HANDLE_STMT, pConnection->hdbc , &hstmttmp); if (pSQL->rc != SQL_SUCCESS ) { SQLError( pConnection->henv, pConnection->hdbc , hstmttmp, pConnection->sqlState , &pConnection->sqlCode, pConnection->sqlMsgDta , sizeof(pConnection->sqlMsgDta), &length); substr ( jxMessage , pConnection->sqlMsgDta , length); return ON; // we have an error } stmt = sqlTempStmt; stmt += sprintf (stmt , "select "); comma = ""; pNode = jx_GetNode(pSqlParms, "/"); while (pNode) { name = jx_GetNodeNamePtr (pNode); stmt += sprintf (stmt , "%s%s" , comma , name); comma = ","; pNode = jx_GetNodeNext(pNode); } stmt += sprintf (stmt , " from %s where 1=0" , table); // prepare the statement */ pSQL->rc = SQLPrepare(hstmttmp , sqlTempStmt, SQL_NTS); if (pSQL->rc != SQL_SUCCESS ) { SQLError( pConnection->henv, pConnection->hdbc , hstmttmp, pConnection->sqlState , &pConnection->sqlCode, pConnection->sqlMsgDta , sizeof(pConnection->sqlMsgDta), &length); substr ( jxMessage , pConnection->sqlMsgDta , length); SQLFreeStmt(hstmttmp, SQL_CLOSE); return ON; // we have an error } // Now we have the colume definitions - now build the update statement: // allocate a statement handle pSQL->rc = SQLAllocHandle(SQL_HANDLE_STMT, pConnection->hdbc , &pSQL->hstmt); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); SQLFreeStmt(hstmttmp, SQL_CLOSE); return ON; // we have an error } // This need to allow update attrParm = SQL_INSENSITIVE; pSQL->rc = SQLSetStmtAttr (pSQL->hstmt, SQL_ATTR_CURSOR_SENSITIVITY , &attrParm , 0); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); return ON; // we have an error } if (update) { buildUpdate (hstmttmp, sqlTempStmt , table, pSqlParms , where); } else { buildInsert (hstmttmp, sqlTempStmt , table, pSqlParms , where); } // prepare the statement that provides the coloumn types pSQL->rc = SQLPrepare(pSQL->hstmt , sqlTempStmt, SQL_NTS); if (pSQL->rc != SQL_SUCCESS ) { check_error (pSQL); SQLFreeStmt(hstmttmp, SQL_CLOSE); return ON; // we have an error } // Take the description from the "select" and use it on the "update" pNode = jx_GetNode(pSqlParms, "/"); for (i=1; pNode; i++) { JXCOL Col; memset (&Col , 0 , sizeof(JXCOL)); value = jx_GetNodeValuePtr (pNode , NULL); pSQL->rc = SQLDescribeCol (//.........这里部分代码省略.........
开发者ID:ataylorkt,项目名称:noxDB,代码行数:101,
示例13: do_cmdstatic __inline__ void do_cmd(char * s){ static char * cmd = do_cmdbuf; uint8_t index; char * args, * p; static char * can_addr; int8_t rc; int16_t value=0; char * raw_byte; short * raw_short; if (s[0] == 0) return; /* parse the command line, seperating the command from arguments */ cmd[0] = 0; index = 0; while ((index < sizeof(do_cmdbuf)) && s[index] && (s[index] != '=')) { cmd[index] = s[index]; index++; } if (index < sizeof(do_cmdbuf)) { cmd[index] = 0; args = &s[index]; while (*args && (*args == '=')) args++; if (*args == 0) args = NULL; } else { cmd[sizeof(do_cmdbuf)-1] = 0; args = NULL; } if (cmd[0] == 0) { return; } // 11bit CAN frame ? if (strcmp(cmd[0],'t') == 0) { //char *pnew = malloc(4); char *pnew = MEM_ALLOC(4); can_addr = substr(cmd, 1, 3, pnew);// printf("pnew: %s/n", pnew);// printf("CMD: %s/n", cmd);// printf("CAN ADDR: %s/n", can_addr); MEM_FREE(pnew); //can_addr = substring(1, 4, cmd, can_addr, sizeof can_addr); //can_addr = sort_of_works_substr(cmd, 1, 3); //free(pnew); // Layout of normal driving screen: // // |----------------|---------| // | BIG NUMBERS | BATTERY | // |--------|-------| ICON | // |3.45 V | 31 C | | // |--------------------------| // // All this information is extracted right here from single CAN-frame with address 630h // // Summary values of interest @ C++ subsys_to_drv函数代码示例 C++ substitute函数代码示例
|