void Replace(char * o_string, char * s_string, char * r_string) { char buffer[MAX]; //a buffer to execute replace char * ch; // Store the pointer returned from strstr if(!(ch = strstr(o_string, s_string))) //exit condition return; strncpy(buffer, o_string, ch-o_string); //copy all the content before the first occurrence of the search string to buffer buffer[ch-o_string] = 0; //prepare the buffer for appending by adding a null to the end of it sprintf(buffer+(ch - o_string), "%s%s", r_string, ch + strlen(s_string)); //append using sprintf function o_string[0] = 0; //empty o_string for copying strcpy(o_string, buffer); return Replace(o_string, s_string, r_string);//pass recursively to replace other occurrences }
JString JStringManager::Get ( const JCharacter* id, const JCharacter* map[], const JSize size ) const { JString s = Get(id); Replace(&s, map, size); return s; }
bool OrderedTask::Relocate(const unsigned position, const Waypoint& waypoint) { if (position >= TaskSize()) return false; OrderedTaskPoint *new_tp = task_points[position]->Clone(task_behaviour, ordered_behaviour, &waypoint); bool success = Replace(*new_tp, position); delete new_tp; return success; }
void String::Replace(const String& replaceThis, const String& replaceWith, bool caseSensitive) { size_t nextPos = 0; while (nextPos < Length()) { size_t pos = Find(replaceThis, nextPos, caseSensitive); if (pos == NPOS) break; Replace(pos, replaceThis.Length(), replaceWith); nextPos = pos + replaceWith.Length(); } }
void AST_Node_Item::ExecReplaceCurrent(void) { if (this->down.isValid() == false) { if (rule4Replace!="") value = Replace(value, rule4Replace); return; } CountPtr<AST_Node_Item> currentNode = this->down; std::map<std::string, std::string> mapFounded; std::ostringstream os; while (currentNode.isValid()) { if (mtk::s_trim(rule4Replace, ' ') !="") { int contador = 0; std::string symbol = currentNode->name; while (mapFounded.find(symbol) != mapFounded.end()) { ++contador; symbol = MTK_SS(currentNode->name << "#" << contador); } mapFounded[symbol] = currentNode->value; } else os << currentNode->value; currentNode = currentNode->next; } if (rule4Replace !="") this->value = Replace(mapFounded, rule4Replace); else this->value = os.str(); }
int main(int argc,char *argv[]) { int i; while(1) { printf("КвЛАны:\n1.┤Ы┐ф╬─╝■ 2.¤н╩Й╬─╝■─┌╚П\n" "3.▓т╚влл 4.╔Й│§лл 5.┐й▒┤лл 6.ляИ─лл\n" "7.▓жНм┤« 8.╠Т┤Щ┤«\n" "9.┤Т┼╠═╦│Ш 0.и┼кЩ▒Я╝Г\n"); scanf("%d%*c",&i); switch(i) { case 1: Open(); break; case 2: Disply(); system("pause"); break; case 3: Insert(); break; case 4: Delete(); break; case 5: Copy(); break; case 6: Modify(); break; case 7: Search(); break; case 8: Replace(); break; case 9: Save(); break; case 0: GiveIn(); break; } system("cls"); } system("pause"); return 0; }
void fgStringTest(const FgArgs &) { Construct(); Copy(); Assign(); Append(); Comparisons(); Encoding(); Replace(); Compare(); Split(); StartsWith(); }
void Console::Write(const String& str) { // Add a new line if not empty if (!mOutput.empty()) { mOutput += "\n"; } // Sanitise the input String sanitisedStr(str); sanitisedStr = Replace(sanitisedStr, "<", "<"); sanitisedStr = Replace(sanitisedStr, ">", ">"); // Add the string mOutput += sanitisedStr; // Set the inner RML and scroll down if (mText) { mText->SetInnerRML(mOutput.c_str()); mConsole->SetScrollTop(mConsole->GetScrollHeight()); } }
//--------------------------------------------------------------------------- void __fastcall TFormMain::Replace(TObject *Sender) { if (RichEdit1->SelLength == 0) Find(Sender); else { RichEdit1->SelText = ReplaceDialog1->ReplaceText; Find(Sender); } if (ReplaceDialog1->Options.Contains(frReplaceAll)) while (RichEdit1->SelLength !=0) Replace(Sender); }
// 解码Html特殊字符 void DecodeHtmlSpecialChars(std::wstring& strText) { Replace(strText, _T("'"), _T("'")); Replace(strText, _T("""), _T("\"")); Replace(strText, _T("<"), _T("<")); Replace(strText, _T(">"), _T(">")); Replace(strText, _T(" "), _T(" ")); Replace(strText, _T("&"), _T("&")); }
void GetWindowsPath(char* remotePath) { WCHAR remotePathW[MAX_PATH], *ws = remotePathW; size_t si, so = 0, lo = sizeof(remotePathW); Replace('/', '\\'); // UTF-8-MAC to UCS-2 char *as = GetBuffer(); while (*as && lo > so) { utf8_decodestr((const u_int8_t *)as, 12, (u_int16_t *)ws, &so, lo -= so, 0, UTF_PRECOMPOSED, &si); as += si; ws += so/2; } *ws = 0; WideCharToMultiByte(CP_ACP, 0, remotePathW, -1, remotePath, MAX_PATH, 0, 0); }
void Binarization::BinarizeLocally(unsigned char *buffer_in, unsigned char *buffer_out, bool inverse) { Replace(buffer_in, GetBuffer(BUFFER_INTERMEDIATE)); step_width_ = width_ / segment_num_; step_height_ = height_ / segment_num_; for(int i = 0; i < segment_num_ - 1; i++) { for(int j = 0; j < segment_num_ - 1; j++) BinarizeLocalArea(buffer_in, buffer_out, i * step_height_, (i + 1) * step_height_ - 1, j * step_width_, (j + 1) * step_width_ - 1, inverse); BinarizeLocalArea(buffer_in, buffer_out, i * step_height_, (i + 1) * step_height_ - 1, (segment_num_ - 1) * step_width_, width_ - 1, inverse); } for(int j = 0; j < segment_num_ - 1; j++) BinarizeLocalArea(buffer_in, buffer_out, (segment_num_ - 1) * step_height_, height_ - 1, j * step_width_, (j + 1) * step_width_ - 1, inverse); BinarizeLocalArea(buffer_in, buffer_out, (segment_num_ - 1) * step_height_, height_ - 1, (segment_num_ - 1) * step_width_, width_ - 1, inverse); }
std::string GetPathFromUrl(const std::string& url) { std::string u(url); // Remove starting "http://" if it exists u = Replace(u, "http://", ""); // Remove all up to and NOT including the first slash if (url.find("/") == std::string::npos) { return "/"; } u.erase(u.begin(), u.begin() + u.find("/")); return u; }
void Swig_cparse_replace_descriptor(String *s) { char tmp[512]; String *arg = 0; SwigType *t; char *c = 0; while ((c = strstr(Char(s), "$descriptor("))) { char *d = tmp; int level = 0; while (*c) { if (*c == '(') level++; if (*c == ')') { level--; if (level == 0) { break; } } *d = *c; d++; c++; } *d = 0; arg = NewString(tmp + 12); t = Swig_cparse_type(arg); Delete(arg); arg = 0; if (t) { String *mangle; String *descriptor; mangle = SwigType_manglestr(t); descriptor = NewStringf("SWIGTYPE%s", mangle); SwigType_remember(t); *d = ')'; d++; *d = 0; Replace(s, tmp, descriptor, DOH_REPLACE_ANY); Delete(mangle); Delete(descriptor); Delete(t); } else { Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n"); break; } } }
void CStdString::ProcessResourceTokens() { // Replace string-tokens: %{nnn} where nnn is a resource string identifier int iPos = Find('%'); while( iPos >= 0 ) { if( GetAt(iPos + 1) == '{' ) { int iEndPos = iPos + 2; while( isdigit(GetAt(iEndPos)) ) iEndPos++; if( GetAt(iEndPos) == '}' ) { CStdString sTemp = CStdString::RES((UINT)_ttoi(m_pstr + iPos + 2)); Replace(Mid(iPos, iEndPos - iPos + 1), sTemp); } } iPos = Find('%', iPos + 1); } }
HRESULT Atom::Close() { m_bClosed = true; // we only support 32-bit lengths for atoms // (otherwise you would have to either decide in the constructor // or shift the whole atom down). if (m_cBytes > 0xffffffff) { return E_INVALIDARG; } BYTE b[4]; WriteLong(long(m_cBytes), b); return Replace(0, b, 4); }
void SetWindowsPath(char* remotePath) { CHAR remotePathA[MAX_PATH], *as = remotePathA; WCHAR remotePathW[MAX_PATH], *ws = remotePathW; size_t si = sizeof(u_int16_t), so = 0, lo = sizeof(remotePathA); MultiByteToWideChar(CP_ACP, 0, remotePath, -1, remotePathW, MAX_PATH); // UCS-2 to UTF-8-MAC while (*ws && lo > so) { utf8_encodestr((const u_int16_t *)ws, si, (u_int8_t *)as, &so, lo -= so, 0, UTF_NO_NULL_TERM | UTF_DECOMPOSED); ws += si/2; as += so; } *as = 0; SetString(remotePathA); Replace('\\', '/'); }
BOOL CINSTALLSYS::InstallDriver( CString DriverName, CString DriverFromPath) { if(IsDriverStarted(DriverName)==TRUE) { AfxMessageBox("驱动已经加载,或无法得到驱动信息,操作已停止"); return TRUE; } _TCHAR System32Directory[_MAX_PATH]; if( 0==GetSystemDirectory(System32Directory,_MAX_PATH)) { AfxMessageBox("Could not find Windows system directory"); return FALSE; } ///////////////////////////////////////////////////////////////////////// // Copy driver .sys file across CString DriverFullPath = (CString)System32Directory+"\\Drivers\\"+DriverName+".sys"; if( 0==CopyFile( DriverFromPath, DriverFullPath, FALSE)) // Overwrite OK { AfxMessageBox("Could not find Windows system directory"); return FALSE; } CString SubDriverFromPath=Replace(DriverFromPath,DriverName,"DebugPrt"); CString SubDriverFullPath=(CString)System32Directory+"\\Drivers\\"+"DebugPrt.sys"; if(0==CopyFile(SubDriverFromPath,SubDriverFullPath,FALSE)) { AfxMessageBox("Could not find Windows system directory"); return FALSE; } //创建服务 if(!CreateDriverService(DriverName)) return FALSE; if(!RegeditKey(DriverName) || !RegeditKey(TEXT("DebugPrt"))) return FALSE; //开始服务 if(!StartDriverService(DriverName)) return FALSE; AfxMessageBox("传输驱动程序安装成功!"); return TRUE; }
string CLanguage :: HasPlayedGamesWithThisBot( string user, string firstgame, string lastgame, string totalgames, string avgloadingtime, string avgstay ) { string Out = m_CFG->GetString( "lang_0061", "lang_0061" ); Replace( Out, "$USER$", user ); Replace( Out, "$FIRSTGAME$", firstgame ); Replace( Out, "$LASTGAME$", lastgame ); Replace( Out, "$TOTALGAMES$", totalgames ); Replace( Out, "$AVGLOADINGTIME$", avgloadingtime ); Replace( Out, "$AVGSTAY$", avgstay ); return Out; }
String * Swig_name_wrapper(const String_or_char *fname) { String *r; String *f; r = NewString(""); if (!naming_hash) naming_hash = NewHash(); f = Getattr(naming_hash,"wrapper"); if (!f) { Append(r,"_wrap_%f"); } else { Append(r,f); } Replace(r,"%f",fname, DOH_REPLACE_ANY); name_mangle(r); return r; }
void nsTString_CharT::ReplaceSubstring( const self_type& aTarget, const self_type& aNewValue ) { if (aTarget.Length() == 0) return; uint32_t i = 0; while (i < mLength) { int32_t r = FindSubstring(mData + i, mLength - i, aTarget.Data(), aTarget.Length(), false); if (r == kNotFound) break; Replace(i + r, aTarget.Length(), aNewValue); i += r + aNewValue.Length(); } }
void IconImageList::SetColourIcon( const int& num, const wxColour& colour ) { wxImage img( colourbox_xpm ); img.Replace( 1, 1, 1, colour.Red(), colour.Green(), colour.Blue() ); int r,g,b; r = colour.Red()+80; g = colour.Green()+80; b = colour.Blue()+80; img.Replace( 2, 2, 2, r>255?255:r, g>255?255:g, b>255?255:b ); /*r = colour.Red()-60; g = colour.Green()-60; b = colour.Blue()-60; img.Replace( 200, 200, 200, r<0?0:r, g<0?0:g, b<0?0:b );*/ if ( m_player_colour_icons[num] != 0 ) Replace( m_player_colour_icons[num], wxBitmap( img ) ); else m_player_colour_icons[num] = Add( wxBitmap( img ) ); }
PixelShader RemoveMADTransformation::Transform(const PixelShader& original) { PixelShader shader; shader.SetInfo(original.GetInfo()); unsigned int i = 0; for (const Statement& statement : original.GetStatements()) { if (statement.opcode == Opcode::MAD) Replace(original, &shader, statement, i); else shader.PushStatement(statement); ++i; } return shader; }
void nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple ) { if (tuple.IsDependentOn(mData, mData + mLength)) { nsTAutoString_CharT temp(tuple); Replace(cutStart, cutLength, temp); return; } size_type length = tuple.Length(); cutStart = XPCOM_MIN(cutStart, Length()); if (ReplacePrep(cutStart, cutLength, length) && length > 0) tuple.WriteTo(mData + cutStart, length); }
bool SearchReplaceEngine::ReplaceAll() { if (!initialized) return false; size_t count = 0; auto matches = GetMatcher(settings); auto const& sel = context->selectionController->GetSelectedSet(); bool selection_only = settings.limit_to == SearchReplaceSettings::Limit::SELECTED; for (auto& diag : context->ass->Events) { if (selection_only && !sel.count(&diag)) continue; if (settings.ignore_comments && diag.Comment) continue; if (settings.use_regex) { if (MatchState ms = matches(&diag, 0)) { auto& diag_field = diag.*get_dialogue_field(settings.field); std::string const& text = diag_field.get(); count += std::distance( boost::u32regex_iterator<std::string::const_iterator>(begin(text), end(text), *ms.re), boost::u32regex_iterator<std::string::const_iterator>()); diag_field = u32regex_replace(text, *ms.re, settings.replace_with); } continue; } size_t pos = 0; while (MatchState ms = matches(&diag, pos)) { ++count; Replace(&diag, ms); pos = ms.end; } } if (count > 0) { context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT); wxMessageBox(fmt_plural(count, "One match was replaced.", "%d matches were replaced.", (int)count)); } else { wxMessageBox(_("No matches found.")); } return true; }
PixelShader RemoveNegationTransformation::Transform(const PixelShader& original) { PixelShader shader; shader.SetInfo(original.GetInfo()); unsigned int i = 0; for (const Statement& statement : original.GetStatements()) { if (statement.source1.negated || statement.source2.negated) { Replace(original, &shader, statement, i); } else shader.PushStatement(statement); ++i; } return shader; }
void OrderedTask::CheckDuplicateWaypoints(Waypoints& waypoints, OrderedTaskPointVector& points, const bool is_task) { for (auto begin = points.cbegin(), end = points.cend(), i = begin; i != end; ++i) { auto wp = waypoints.CheckExistsOrAppend((*i)->GetWaypointPtr()); const OrderedTaskPoint *new_tp = (*i)->Clone(task_behaviour, ordered_settings, std::move(wp)); if (is_task) Replace(*new_tp, std::distance(begin, i)); else ReplaceOptionalStart(*new_tp, std::distance(begin, i)); delete new_tp; } }
void CCopasiMessage::lineBreak() { std::string Search("\n"); std::string Replace("\n "); std::string::size_type pos = 0; while (true) { pos = mText.find(Search, pos); if (pos == std::string::npos) break; mText.replace(pos, Search.length(), Replace); pos += Replace.length(); } }
static String *partial_arg(String *s, String *p) { char *c; char *cp = Char(p); String *prefix; String *newarg; /* Find the prefix on the partial argument */ c = strchr(cp, '$'); if (!c) { return Copy(s); } prefix = NewStringWithSize(cp, c - cp); newarg = Copy(s); Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); Delete(prefix); return newarg; }
void csStringBase::ReplaceAll (const char* str, const char* replaceWith) { csStringBase newStr; size_t p = 0; const size_t strLen = strlen (str); char* x = GetDataMutable(); while (true) { size_t strPos = Find (str, p); if (strPos == (size_t)-1) break; newStr.Append (x + p, strPos - p); newStr.Append (replaceWith); p = strPos + strLen; } newStr.Append (x + p, Size - p); Replace (newStr); }