From 6c9cb174fb2598d11762cde62d1808a10653a1b0 Mon Sep 17 00:00:00 2001 From: mniip Date: Wed, 2 May 2018 22:08:52 +0300 Subject: [PATCH] Change some uses of String::Stream to StringBuilder --- src/PowderToySDL.cpp | 4 +- src/client/Client.cpp | 8 +-- src/client/GameSave.cpp | 7 +-- src/common/Format.h | 9 +++ src/debug/DebugLines.cpp | 21 +++---- src/debug/DebugParts.cpp | 7 +-- src/debug/ParticleDebug.cpp | 17 +++--- src/graphics/Renderer.cpp | 5 +- src/gui/colourpicker/ColourPickerActivity.cpp | 4 +- src/gui/font/FontEditor.cpp | 13 ++--- src/gui/game/GameController.cpp | 4 +- src/gui/game/GameModel.cpp | 5 +- src/gui/game/GameView.cpp | 56 +++++++++---------- .../localbrowser/LocalBrowserController.cpp | 15 ++--- src/gui/localbrowser/LocalBrowserView.cpp | 12 ++-- src/gui/preview/PreviewView.cpp | 4 +- src/gui/search/SearchController.cpp | 48 +++++----------- src/gui/search/SearchView.cpp | 18 +++--- src/gui/update/UpdateActivity.cpp | 18 +++--- src/lua/LuaScriptInterface.cpp | 50 +++++------------ src/lua/TPTSTypes.cpp | 8 +-- src/simulation/Sign.cpp | 17 +++--- src/tasks/TaskWindow.cpp | 10 +--- 23 files changed, 143 insertions(+), 217 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index f16fb917d1..4fd0bb32e5 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -753,11 +753,11 @@ void EventProcess(SDL_Event event) void DoubleScreenDialog() { - String::Stream message; + StringBuilder message; message << "Switching to double size mode since your screen was determined to be large enough: "; message << desktopWidth << "x" << desktopHeight << " detected, " << WINDOWW*2 << "x" << WINDOWH*2 << " required"; message << "\nTo undo this, hit Cancel. You can toggle double size mode in settings at any time."; - if (!ConfirmPrompt::Blocking("Large screen detected", message.str())) + if (!ConfirmPrompt::Blocking("Large screen detected", message.Build())) { Client::Ref().SetPref("Scale", 1); engine->SetScale(1); diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 333d7e98d8..4741c896ac 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -695,9 +695,7 @@ RequestStatus Client::ParseServerReturn(char *result, int status, bool json) return RequestOkay; if (status != 200) { - String::Stream httperror; - httperror << "HTTP Error " << status << ": " << http_ret_text(status); - lastError = httperror.str(); + lastError = String::Build("HTTP Error ", status, ": ", ByteString(http_ret_text(status)).FromUtf8()); return RequestFailure; } @@ -727,9 +725,7 @@ RequestStatus Client::ParseServerReturn(char *result, int status, bool json) if (!strncmp((const char *)result, "Error: ", 7)) { status = atoi(result+7); - String::Stream httperror; - httperror << "HTTP Error " << status << ": " << http_ret_text(status); - lastError = httperror.str(); + lastError = String::Build("HTTP Error ", status, ": ", ByteString(http_ret_text(status)).FromUtf8()); return RequestFailure; } lastError = "Could not read response: " + ByteString(e.what()).FromUtf8(); diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 7bf4845f0c..3b7f16f23b 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -805,13 +805,12 @@ void GameSave::readOPS(char * data, int dataLength) if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION)) #endif { - String::Stream errorMessage; #ifdef RENDERER - errorMessage << "Save from a newer version: Requires render version " << renderMajor << "." << renderMinor; + String errorMessage = String::Build("Save from a newer version: Requires render version ", renderMajor, ".", renderMinor); #else - errorMessage << "Save from a newer version: Requires version " << major << "." << minor; + String errorMessage = String::Build("Save from a newer version: Requires version ", major, ".", minor); #endif - throw ParseException(ParseException::WrongVersion, errorMessage.str()); + throw ParseException(ParseException::WrongVersion, errorMessage); } #if defined(SNAPSHOT) || defined(DEBUG) else if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION)) diff --git a/src/common/Format.h b/src/common/Format.h index 1c7fdf9753..cd454b3623 100644 --- a/src/common/Format.h +++ b/src/common/Format.h @@ -56,6 +56,15 @@ namespace Format inline FlagsOverride Dec() { return FlagsOverride(); } inline FlagsOverride Hex() { return FlagsOverride(); } + template inline FlagsOverride Uppercase(T value) { return FlagsOverride(value); } + template inline FlagsOverride ShowPoint(T value) { return FlagsOverride(value); } + template inline FlagsOverride NoUppercase(T value) { return FlagsOverride(value); } + template inline FlagsOverride NoShowPoint(T value) { return FlagsOverride(value); } + inline FlagsOverride Uppercase() { return FlagsOverride(); } + inline FlagsOverride ShowPoint() { return FlagsOverride(); } + inline FlagsOverride NoUppercase() { return FlagsOverride(); } + inline FlagsOverride NoShowPoint() { return FlagsOverride(); } + template inline FlagsOverride Fixed(T value) { return FlagsOverride(value); } template inline FlagsOverride Scientific(T value) { return FlagsOverride(value); } template inline FlagsOverride FloatDefault(T value) { return FlagsOverride(value); } diff --git a/src/debug/DebugLines.cpp b/src/debug/DebugLines.cpp index 5a42928a18..7de5665b43 100644 --- a/src/debug/DebugLines.cpp +++ b/src/debug/DebugLines.cpp @@ -27,21 +27,18 @@ void DebugLines::Draw() g->draw_line(0, drawPoint2.Y, XRES, drawPoint2.Y, 255, 255, 255, 120); g->draw_line(drawPoint2.X, 0, drawPoint2.X, YRES, 255, 255, 255, 120); - String::Stream info; - info << drawPoint2.X << " x " << drawPoint2.Y; - g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info.str())-3), drawPoint2.Y+(drawPoint2.Ydrawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info)-3), drawPoint2.Y+(drawPoint2.Ydrawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info.str())-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str(), 255, 255, 255, 200); + info = String::Build(drawPoint1.X, " x ", drawPoint1.Y); + g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info)-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info, 255, 255, 255, 200); - info.str(String()); - info << std::abs(drawPoint2.X-drawPoint1.X); - g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info.str())/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str(), 255, 255, 255, 200); + info = String::Build(std::abs(drawPoint2.X-drawPoint1.X)); + g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info)/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info, 255, 255, 255, 200); - info.str(String()); - info << std::abs(drawPoint2.Y-drawPoint1.Y); - g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info.str())-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info.str(), 255, 255, 255, 200); + info = String::Build(std::abs(drawPoint2.Y-drawPoint1.Y)); + g->drawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(info)-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info, 255, 255, 255, 200); } } diff --git a/src/debug/DebugParts.cpp b/src/debug/DebugParts.cpp index 9c2ef55d2e..ffab842282 100644 --- a/src/debug/DebugParts.cpp +++ b/src/debug/DebugParts.cpp @@ -15,8 +15,7 @@ void DebugParts::Draw() Graphics * g = ui::Engine::Ref().g; int x = 0, y = 0, lpx = 0, lpy = 0; - String::Stream info; - info << sim->parts_lastActiveIndex << "/" << NPART << " (" << std::fixed << std::setprecision(2) << (float)sim->parts_lastActiveIndex/(NPART)*100.0f << "%)"; + String info = String::Build(sim->parts_lastActiveIndex, "/", NPART, " (", Format::Precision((float)sim->parts_lastActiveIndex/(NPART)*100.0f, 2), "%)"); for (int i = 0; i < NPART; i++) { if (sim->parts[i].type) @@ -45,8 +44,8 @@ void DebugParts::Draw() g->addpixel(lpx, lpy+1, 255, 50, 50, 120); g->addpixel(lpx, lpy-1, 255, 50, 50, 120); - g->fillrect(7, YRES-26, g->textwidth(info.str())+5, 14, 0, 0, 0, 180); - g->drawtext(10, YRES-22, info.str(), 255, 255, 255, 255); + g->fillrect(7, YRES-26, g->textwidth(info)+5, 14, 0, 0, 0, 180); + g->drawtext(10, YRES-22, info, 255, 255, 255, 255); } DebugParts::~DebugParts() diff --git a/src/debug/ParticleDebug.cpp b/src/debug/ParticleDebug.cpp index a9fd3ebfe1..d50ed7a9f3 100644 --- a/src/debug/ParticleDebug.cpp +++ b/src/debug/ParticleDebug.cpp @@ -15,7 +15,7 @@ void ParticleDebug::Debug(int mode, int x, int y) { int debug_currentParticle = sim->debug_currentParticle; int i = 0; - String::Stream logmessage; + String logmessage; if (mode == 0) { @@ -25,21 +25,21 @@ void ParticleDebug::Debug(int mode, int x, int y) while (i < NPART && !sim->parts[i].type) i++; if (i == NPART) - logmessage << "End of particles reached, updated sim"; + logmessage = "End of particles reached, updated sim"; else - logmessage << "Updated particle #" << i; + logmessage = String::Build("Updated particle #", i); } else if (mode == 1) { if (x < 0 || x >= XRES || y < 0 || y >= YRES || !sim->pmap[y][x] || (i = ID(sim->pmap[y][x])) < debug_currentParticle) { i = NPART; - logmessage << "Updated particles from #" << debug_currentParticle << " to end, updated sim"; + logmessage = String::Build("Updated particles from #", debug_currentParticle, " to end, updated sim"); } else - logmessage << "Updated particles #" << debug_currentParticle << " through #" << i; + logmessage = String::Build("Updated particles #", debug_currentParticle, " through #", i); } - model->Log(logmessage.str(), false); + model->Log(logmessage, false); if (sim->debug_currentParticle == 0) { @@ -89,9 +89,8 @@ bool ParticleDebug::KeyPress(int key, Uint16 character, bool shift, bool ctrl, b { sim->UpdateParticles(sim->debug_currentParticle, NPART); sim->AfterSim(); - String::Stream logmessage; - logmessage << "Updated particles from #" << sim->debug_currentParticle << " to end, updated sim"; - model->Log(logmessage.str(), false); + String logmessage = String::Build("Updated particles from #", sim->debug_currentParticle, " to end, updated sim"); + model->Log(logmessage, false); sim->debug_currentParticle = 0; } else diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 575a7e156d..d937986f1a 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -1496,9 +1496,8 @@ void Renderer::render_parts() if (mousePos.X>(nx-3) && mousePos.X<(nx+3) && mousePos.Y<(ny+3) && mousePos.Y>(ny-3)) //If mouse is in the head { - String::Stream hp; - hp << std::setw(3) << sim->parts[i].life; - drawtext(mousePos.X-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousePos.Y-12, hp.str(), 255, 255, 255, 255); + String hp = String::Build(Format::Width(sim->parts[i].life, 3)); + drawtext(mousePos.X-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousePos.Y-12, hp, 255, 255, 255, 255); } if (findingElement == t) diff --git a/src/gui/colourpicker/ColourPickerActivity.cpp b/src/gui/colourpicker/ColourPickerActivity.cpp index 85d0510305..a3bef8f237 100644 --- a/src/gui/colourpicker/ColourPickerActivity.cpp +++ b/src/gui/colourpicker/ColourPickerActivity.cpp @@ -108,9 +108,7 @@ void ColourPickerActivity::UpdateTextboxes(int r, int g, int b, int a) gValue->SetText(format::NumberToString(g)); bValue->SetText(format::NumberToString(b)); aValue->SetText(format::NumberToString(a)); - String::Stream hex; - hex << std::hex << "0x" << std::setfill(String::value_type('0')) << std::setw(2) << std::uppercase << a << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b; - hexValue->SetText(hex.str()); + hexValue->SetText(String::Build(Format::Hex(), Format::Uppercase(), Format::Width(2), a, r, g, b)); } void ColourPickerActivity::OnTryExit(ExitMethod method) { diff --git a/src/gui/font/FontEditor.cpp b/src/gui/font/FontEditor.cpp index b322c4badd..82a761f606 100644 --- a/src/gui/font/FontEditor.cpp +++ b/src/gui/font/FontEditor.cpp @@ -433,9 +433,7 @@ FontEditor::FontEditor(ByteString _header): int *refs[6] = {&fgR, &fgG, &fgB, &bgR, &bgG, &bgB}; for(int i = 0; i < 6; i++) { - String::Stream ss; - ss << *refs[i]; - ui::Textbox *colorComponent = new ui::Textbox(ui::Point(currentX, baseline), ui::Point(27, 17), ss.str()); + ui::Textbox *colorComponent = new ui::Textbox(ui::Point(currentX, baseline), ui::Point(27, 17), format::NumberToString(*refs[i])); currentX += 28; colorComponent->SetActionCallback(new ColorComponentAction(*refs[i])); AddComponent(colorComponent); @@ -522,14 +520,15 @@ FontEditor::FontEditor(ByteString _header): inputPreview->Appearance.VerticalAlign = ui::Appearance::AlignTop; inputPreview->SetActionCallback(new PreviewAction(this)); - String::Stream input; + StringBuilder input; + input << Format::Hex() << Format::Width(2); for(unsigned int ch = 0x20; ch <= 0xFF; ch++) { if(!(ch & 0x3F)) - input << "20 "; - input << std::hex << std::setw(2) << ch << " "; + input << 0x20 << " "; + input << ch << " "; } - inputPreview->SetText(input.str()); + inputPreview->SetText(input.Build()); PreviewAction(this).TextChangedCallback(inputPreview); AddComponent(inputPreview); } diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index f7b1079ac9..f82dc4a5db 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1638,7 +1638,7 @@ void GameController::NotifyUpdateAvailable(Client * sender) virtual void Action() { UpdateInfo info = Client::Ref().GetUpdateInfo(); - String::Stream updateMessage; + StringBuilder updateMessage; updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n "; #ifdef SNAPSHOT @@ -1666,7 +1666,7 @@ void GameController::NotifyUpdateAvailable(Client * sender) if (info.Changelog.length()) updateMessage << "\n\nChangelog:\n" << info.Changelog; - new ConfirmPrompt("Run Updater", updateMessage.str(), new UpdateConfirmation(c)); + new ConfirmPrompt("Run Updater", updateMessage.Build(), new UpdateConfirmation(c)); } }; diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 14684df973..e5d953cb28 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -912,12 +912,11 @@ void GameModel::SetPaused(bool pauseState) { if (!pauseState && sim->debug_currentParticle > 0) { - String::Stream logmessage; - logmessage << "Updated particles from #" << sim->debug_currentParticle << " to end due to unpause"; + String logmessage = String::Build("Updated particles from #", sim->debug_currentParticle, " to end due to unpause"); sim->UpdateParticles(sim->debug_currentParticle, NPART); sim->AfterSim(); sim->debug_currentParticle = 0; - Log(logmessage.str(), false); + Log(logmessage, false); } sim->sys_pause = pauseState?1:0; diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 75c1ac8a5e..37b95e3c94 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -971,7 +971,7 @@ void GameView::NotifySaveChanged(GameModel * sender) tagSimulationButton->Enabled = sender->GetSave()->GetID(); if (sender->GetSave()->GetID()) { - String::Stream tagsStream; + StringBuilder tagsStream; std::list tags = sender->GetSave()->GetTags(); if (tags.size()) { @@ -981,7 +981,7 @@ void GameView::NotifySaveChanged(GameModel * sender) tagsStream << " "; tagsStream << iter->FromUtf8(); } - tagSimulationButton->SetText(tagsStream.str()); + tagSimulationButton->SetText(tagsStream.Build()); } else { @@ -1734,7 +1734,7 @@ void GameView::OnTick(float dt) if (type == 'c' || type == 't' || type == 's') { String linkSign = str.Substr(3, pos-3); - String::Stream tooltip; + StringBuilder tooltip; switch (type) { case 'c': @@ -1747,7 +1747,7 @@ void GameView::OnTick(float dt) tooltip << "Search for " << linkSign; break; } - ToolTip(ui::Point(0, Size.Y), tooltip.str()); + ToolTip(ui::Point(0, Size.Y), tooltip.Build()); } } @@ -2258,13 +2258,11 @@ void GameView::OnDraw() if(recording) { - String::Stream sampleInfo; - sampleInfo << recordingIndex; - sampleInfo << ". " + String(0xE00E) + " REC"; + String sampleInfo = String::Build(recordingIndex, ". ", String(0xE00E), " REC"); - int textWidth = Graphics::textwidth(sampleInfo.str()); + int textWidth = Graphics::textwidth(sampleInfo); g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); - g->drawtext(XRES-16-textWidth, 16, sampleInfo.str(), 255, 50, 20, 255); + g->drawtext(XRES-16-textWidth, 16, sampleInfo, 255, 50, 20, 255); } else if(showHud) { @@ -2274,8 +2272,8 @@ void GameView::OnDraw() alpha = 255-toolTipPresence*3; if (alpha < 50) alpha = 50; - String::Stream sampleInfo; - sampleInfo.precision(2); + StringBuilder sampleInfo; + sampleInfo << Format::Precision(2); int type = sample.particle.type; if (type) @@ -2315,7 +2313,7 @@ void GameView::OnDraw() else sampleInfo << " ()"; } - sampleInfo << ", Temp: " << std::fixed << sample.particle.temp -273.15f << " C"; + sampleInfo << ", Temp: " << (sample.particle.temp - 273.15f) << " C"; sampleInfo << ", Life: " << sample.particle.life; if (sample.particle.type != PT_RFRG && sample.particle.type != PT_RFGL) sampleInfo << ", Tmp: " << sample.particle.tmp; @@ -2324,7 +2322,7 @@ void GameView::OnDraw() if (type == PT_CRAY || type == PT_DRAY || type == PT_EXOT || type == PT_LIGH || type == PT_SOAP || type == PT_TRON || type == PT_VIBR || type == PT_VIRS || type == PT_WARP || type == PT_LCRY || type == PT_CBNW || type == PT_TSNS || type == PT_DTEC || type == PT_LSNS || type == PT_PSTN) sampleInfo << ", Tmp2: " << sample.particle.tmp2; - sampleInfo << ", Pressure: " << std::fixed << sample.AirPressure; + sampleInfo << ", Pressure: " << sample.AirPressure; } else { @@ -2336,27 +2334,27 @@ void GameView::OnDraw() sampleInfo << c->ElementResolve(type, ctype).FromAscii(); else sampleInfo << c->ElementResolve(type, ctype).FromAscii(); - sampleInfo << ", Temp: " << std::fixed << sample.particle.temp - 273.15f << " C"; - sampleInfo << ", Pressure: " << std::fixed << sample.AirPressure; + sampleInfo << ", Temp: " << sample.particle.temp - 273.15f << " C"; + sampleInfo << ", Pressure: " << sample.AirPressure; } } else if (sample.WallType) { sampleInfo << c->WallName(sample.WallType); - sampleInfo << ", Pressure: " << std::fixed << sample.AirPressure; + sampleInfo << ", Pressure: " << sample.AirPressure; } else if (sample.isMouseInSim) { - sampleInfo << "Empty, Pressure: " << std::fixed << sample.AirPressure; + sampleInfo << "Empty, Pressure: " << sample.AirPressure; } else { sampleInfo << "Empty"; } - int textWidth = Graphics::textwidth(sampleInfo.str()); + int textWidth = Graphics::textwidth(sampleInfo.Build()); g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5f); - g->drawtext(XRES-16-textWidth, 16, sampleInfo.str(), 255, 255, 255, alpha*0.75f); + g->drawtext(XRES-16-textWidth, 16, sampleInfo.Build(), 255, 255, 255, alpha*0.75f); #ifndef OGLI if (wavelengthGfx) @@ -2397,7 +2395,8 @@ void GameView::OnDraw() if (showDebug) { - sampleInfo.str(String()); + StringBuilder sampleInfo; + sampleInfo << Format::Precision(2); if (type) sampleInfo << "#" << sample.ParticleID << ", "; @@ -2408,22 +2407,21 @@ void GameView::OnDraw() sampleInfo << ", GX: " << sample.GravityVelocityX << " GY: " << sample.GravityVelocityY; if (c->GetAHeatEnable()) - sampleInfo << ", AHeat: " << std::fixed << sample.AirTemperature -273.15f << " C"; + sampleInfo << ", AHeat: " << sample.AirTemperature - 273.15f << " C"; - textWidth = Graphics::textwidth(sampleInfo.str()); + textWidth = Graphics::textwidth(sampleInfo.Build()); g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, alpha*0.5f); - g->drawtext(XRES-16-textWidth, 30, sampleInfo.str(), 255, 255, 255, alpha*0.75f); + g->drawtext(XRES-16-textWidth, 30, sampleInfo.Build(), 255, 255, 255, alpha*0.75f); } } if(showHud && introText < 51) { //FPS and some version info - String::Stream fpsInfo; - fpsInfo.precision(2); - fpsInfo << "FPS: " << std::fixed << ui::Engine::Ref().GetFps(); + StringBuilder fpsInfo; + fpsInfo << Format::Precision(2) << "FPS: " << ui::Engine::Ref().GetFps(); #ifdef DEBUG - fpsInfo << " Delta: " << std::fixed << ui::Engine::Ref().GetDelta(); + fpsInfo << " Delta: " << ui::Engine::Ref().GetDelta(); #endif if (showDebug) @@ -2442,10 +2440,10 @@ void GameView::OnDraw() if (ren && ren->findingElement) fpsInfo << " [FIND]"; - int textWidth = Graphics::textwidth(fpsInfo.str()); + int textWidth = Graphics::textwidth(fpsInfo.Build()); int alpha = 255-introText*5; g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5); - g->drawtext(16, 16, fpsInfo.str(), 32, 216, 255, alpha*0.75); + g->drawtext(16, 16, fpsInfo.Build(), 32, 216, 255, alpha*0.75); } //Tooltips diff --git a/src/gui/localbrowser/LocalBrowserController.cpp b/src/gui/localbrowser/LocalBrowserController.cpp index 7094147019..1675c68fc1 100644 --- a/src/gui/localbrowser/LocalBrowserController.cpp +++ b/src/gui/localbrowser/LocalBrowserController.cpp @@ -44,12 +44,12 @@ void LocalBrowserController::RemoveSelected() virtual ~RemoveSelectedConfirmation() { } }; - String::Stream desc; + StringBuilder desc; desc << "Are you sure you want to delete " << browserModel->GetSelected().size() << " stamp"; if(browserModel->GetSelected().size()>1) desc << "s"; desc << "?"; - new ConfirmPrompt("Delete stamps", desc.str(), new RemoveSelectedConfirmation(this)); + new ConfirmPrompt("Delete stamps", desc.Build(), new RemoveSelectedConfirmation(this)); } void LocalBrowserController::removeSelectedC() @@ -64,10 +64,8 @@ void LocalBrowserController::removeSelectedC() { for (size_t i = 0; i < saves.size(); i++) { - String::Stream saveName; - saveName << "Deleting stamp [" << saves[i].FromUtf8() << "] ..."; - notifyStatus(saveName.str()); - Client::Ref().DeleteStamp(saves[i]); + notifyStatus(String::Build("Deleting stamp [", saves[i].FromUtf8(), "] ...")); + Client::Ref().DeleteStamp(saves[i]); notifyProgress((float(i+1)/float(saves.size())*100)); } return true; @@ -96,9 +94,8 @@ void LocalBrowserController::RescanStamps() virtual ~RescanConfirmation() { } }; - String::Stream desc; - desc << "Rescanning the stamps folder can find stamps added to the stamps folder or recover stamps when the stamps.def file has been lost or damaged. However, be warned that this will mess up the current sorting order"; - new ConfirmPrompt("Rescan", desc.str(), new RescanConfirmation(this)); + String desc = "Rescanning the stamps folder can find stamps added to the stamps folder or recover stamps when the stamps.def file has been lost or damaged. However, be warned that this will mess up the current sorting order"; + new ConfirmPrompt("Rescan", desc, new RescanConfirmation(this)); } void LocalBrowserController::rescanStampsC() diff --git a/src/gui/localbrowser/LocalBrowserView.cpp b/src/gui/localbrowser/LocalBrowserView.cpp index d0c1f175b9..1a87a42e11 100644 --- a/src/gui/localbrowser/LocalBrowserView.cpp +++ b/src/gui/localbrowser/LocalBrowserView.cpp @@ -140,10 +140,9 @@ void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender) } else { - String::Stream pageInfo; - pageInfo << "of " << pageCount; - pageCountLabel->SetText(pageInfo.str()); - int width = Graphics::textwidth(pageInfo.str().c_str()); + String pageInfo = String::Build("of ", pageCount); + pageCountLabel->SetText(pageInfo); + int width = Graphics::textwidth(pageInfo); pageLabel->Position.X = WINDOWW/2-width-20; pageTextbox->Position.X = WINDOWW/2-width+11; @@ -151,9 +150,8 @@ void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender) //pageCountLabel->Position.X = WINDOWW/2+6; pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = true; - pageInfo.str(String()); - pageInfo << sender->GetPageNum(); - pageTextbox->SetText(pageInfo.str()); + pageInfo = String::Build(sender->GetPageNum()); + pageTextbox->SetText(pageInfo); } if(sender->GetPageNum() == 1) diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index df0eea9550..d1565471bc 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -637,9 +637,7 @@ void PreviewView::SaveLoadingError(String errorMessage) void PreviewView::NotifyCommentsPageChanged(PreviewModel * sender) { - String::Stream pageInfoStream; - pageInfoStream << "Page " << sender->GetCommentsPageNum() << " of " << sender->GetCommentsPageCount(); - pageInfo->SetText(pageInfoStream.str()); + pageInfo->SetText(String::Build("Page ", sender->GetCommentsPageNum(), " of ", sender->GetCommentsPageCount())); } void PreviewView::NotifyCommentsChanged(PreviewModel * sender) diff --git a/src/gui/search/SearchController.cpp b/src/gui/search/SearchController.cpp index 196a6d0c98..ce461b97a8 100644 --- a/src/gui/search/SearchController.cpp +++ b/src/gui/search/SearchController.cpp @@ -235,12 +235,12 @@ void SearchController::RemoveSelected() virtual ~RemoveSelectedConfirmation() { } }; - String::Stream desc; + StringBuilder desc; desc << "Are you sure you want to delete " << searchModel->GetSelected().size() << " save"; if(searchModel->GetSelected().size()>1) desc << "s"; desc << "?"; - new ConfirmPrompt("Delete saves", desc.str(), new RemoveSelectedConfirmation(this)); + new ConfirmPrompt("Delete saves", desc.Build(), new RemoveSelectedConfirmation(this)); } void SearchController::removeSelectedC() @@ -255,14 +255,10 @@ void SearchController::removeSelectedC() { for (size_t i = 0; i < saves.size(); i++) { - String::Stream saveID; - saveID << "Deleting save [" << saves[i] << "] ..."; - notifyStatus(saveID.str()); + notifyStatus(String::Build("Deleting save [", saves[i], "] ...")); if (Client::Ref().DeleteSave(saves[i])!=RequestOkay) { - String::Stream saveIDF; - saveIDF << "Failed to delete [" << saves[i] << "]: " << Client::Ref().GetLastError(); - notifyError(saveIDF.str()); + notifyError(String::Build("Failed to delete [", saves[i], "]: ", Client::Ref().GetLastError())); c->Refresh(); return false; } @@ -293,12 +289,12 @@ void SearchController::UnpublishSelected(bool publish) virtual ~UnpublishSelectedConfirmation() { } }; - String::Stream desc; - desc << "Are you sure you want to " << (publish ? "publish " : "unpublish ") << searchModel->GetSelected().size() << " save"; + StringBuilder desc; + desc << "Are you sure you want to " << (publish ? String("publish ") : String("unpublish ")) << searchModel->GetSelected().size() << " save"; if (searchModel->GetSelected().size() > 1) desc << "s"; desc << "?"; - new ConfirmPrompt(publish ? String("Publish Saves") : String("Unpublish Saves"), desc.str(), new UnpublishSelectedConfirmation(this, publish)); + new ConfirmPrompt(publish ? String("Publish Saves") : String("Unpublish Saves"), desc.Build(), new UnpublishSelectedConfirmation(this, publish)); } void SearchController::unpublishSelectedC(bool publish) @@ -313,9 +309,7 @@ void SearchController::unpublishSelectedC(bool publish) bool PublishSave(int saveID) { - String::Stream message; - message << "Publishing save [" << saveID << "]"; - notifyStatus(message.str()); + notifyStatus(String::Build("Publishing save [", saveID, "]")); if (Client::Ref().PublishSave(saveID) != RequestOkay) return false; return true; @@ -323,9 +317,7 @@ void SearchController::unpublishSelectedC(bool publish) bool UnpublishSave(int saveID) { - String::Stream message; - message << "Unpublishing save [" << saveID << "]"; - notifyStatus(message.str()); + notifyStatus(String::Build("Unpublishing save [", saveID, "]")); if (Client::Ref().UnpublishSave(saveID) != RequestOkay) return false; return true; @@ -342,12 +334,10 @@ void SearchController::unpublishSelectedC(bool publish) ret = UnpublishSave(saves[i]); if (!ret) { - String::Stream error; if (publish) // uses html page so error message will be spam - error << "Failed to publish [" << saves[i] << "], is this save yours?"; + notifyError(String::Build("Failed to publish [", saves[i], "], is this save yours?")); else - error << "Failed to unpublish [" << saves[i] << "]: " + Client::Ref().GetLastError(); - notifyError(error.str()); + notifyError(String::Build("Failed to unpublish [", saves[i], "]: " + Client::Ref().GetLastError())); c->Refresh(); return false; } @@ -373,14 +363,10 @@ void SearchController::FavouriteSelected() { for (size_t i = 0; i < saves.size(); i++) { - String::Stream saveID; - saveID << "Favouring save [" << saves[i] << "]"; - notifyStatus(saveID.str()); + notifyStatus(String::Build("Favouring save [", saves[i], "]")); if (Client::Ref().FavouriteSave(saves[i], true)!=RequestOkay) { - String::Stream saveIDF; - saveIDF << "Failed to favourite [" << saves[i] << "]: " + Client::Ref().GetLastError(); - notifyError(saveIDF.str()); + notifyError(String::Build("Failed to favourite [", saves[i], "]: " + Client::Ref().GetLastError())); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); @@ -398,14 +384,10 @@ void SearchController::FavouriteSelected() { for (size_t i = 0; i < saves.size(); i++) { - String::Stream saveID; - saveID << "Unfavouring save [" << saves[i] << "]"; - notifyStatus(saveID.str()); + notifyStatus(String::Build("Unfavouring save [", saves[i], "]")); if (Client::Ref().FavouriteSave(saves[i], false)!=RequestOkay) { - String::Stream saveIDF; - saveIDF << "Failed to unfavourite [" << saves[i] << "]: " + Client::Ref().GetLastError(); - notifyError(saveIDF.str()); + notifyError(String::Build("Failed to unfavourite [", saves[i], "]: " + Client::Ref().GetLastError())); return false; } notifyProgress((float(i+1)/float(saves.size())*100)); diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 117e5544d0..14fe3798fe 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -374,10 +374,9 @@ void SearchView::NotifyPageChanged(SearchModel * sender) } else { - String::Stream pageInfo; - pageInfo << "of " << pageCount; - pageCountLabel->SetText(pageInfo.str()); - int width = Graphics::textwidth(pageInfo.str().c_str()); + String pageInfo = String::Build("of ", pageCount); + pageCountLabel->SetText(pageInfo); + int width = Graphics::textwidth(pageInfo); pageLabel->Position.X = WINDOWW/2-width-20; pageTextbox->Position.X = WINDOWW/2-width+11; @@ -385,9 +384,8 @@ void SearchView::NotifyPageChanged(SearchModel * sender) //pageCountLabel->Position.X = WINDOWW/2+6; pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = true; - pageInfo.str(String()); - pageInfo << sender->GetPageNum(); - pageTextbox->SetText(pageInfo.str()); + pageInfo = String::Build(sender->GetPageNum()); + pageTextbox->SetText(pageInfo); } if(sender->GetPageNum() == 1) { @@ -671,13 +669,11 @@ void SearchView::NotifySaveListChanged(SearchModel * sender) } virtual void AltActionCallback(ui::SaveButton * sender) { - String::Stream search; - search << "history:" << sender->GetSave()->GetID(); - v->Search(search.str()); + v->Search(String::Build("history:", sender->GetSave()->GetID())); } virtual void AltActionCallback2(ui::SaveButton * sender) { - v->Search("user:"+sender->GetSave()->GetUserName().FromUtf8()); + v->Search(String::Build("user:", sender->GetSave()->GetUserName().FromUtf8())); } }; for (size_t i = 0; i < saves.size(); i++) diff --git a/src/gui/update/UpdateActivity.cpp b/src/gui/update/UpdateActivity.cpp index 9cf2286333..3f9ddcb8bd 100644 --- a/src/gui/update/UpdateActivity.cpp +++ b/src/gui/update/UpdateActivity.cpp @@ -25,7 +25,7 @@ class UpdateDownloadTask : public Task } virtual bool doWork() { - String::Stream errorStream; + String error; void * request = http_async_req_start(NULL, (char*)updateName.c_str(), NULL, 0, 0); notifyStatus("Downloading update"); notifyProgress(-1); @@ -42,13 +42,13 @@ class UpdateDownloadTask : public Task if (status!=200) { free(data); - errorStream << "Server responded with Status " << status; - notifyError("Could not download update: " + String(errorStream.str())); + error = String::Build("Server responded with Status ", status); + notifyError("Could not download update: " + error); return false; } if (!data) { - errorStream << "Server responded with nothing"; + error = "Server responded with nothing"; notifyError("Server did not return any data"); return false; } @@ -60,12 +60,12 @@ class UpdateDownloadTask : public Task if(dataLength<16) { - errorStream << "Unsufficient data, got " << dataLength << " bytes"; + error = String::Build("Unsufficient data, got ", dataLength, " bytes"); goto corrupt; } if (data[0]!=0x42 || data[1]!=0x75 || data[2]!=0x54 || data[3]!=0x54) { - errorStream << "Invalid update format"; + error = "Invalid update format"; goto corrupt; } @@ -78,7 +78,7 @@ class UpdateDownloadTask : public Task res = (char *)malloc(uncompressedLength); if (!res) { - errorStream << "Unable to allocate " << uncompressedLength << " bytes of memory for decompression"; + error = String::Build("Unable to allocate ", uncompressedLength, " bytes of memory for decompression"); goto corrupt; } @@ -86,7 +86,7 @@ class UpdateDownloadTask : public Task dstate = BZ2_bzBuffToBuffDecompress((char *)res, (unsigned *)&uncompressedLength, (char *)(data+8), dataLength-8, 0, 0); if (dstate) { - errorStream << "Unable to decompress update: " << dstate; + error = String::Build("Unable to decompress update: ", dstate); free(res); goto corrupt; } @@ -109,7 +109,7 @@ class UpdateDownloadTask : public Task return true; corrupt: - notifyError("Downloaded update is corrupted\n" + String(errorStream.str())); + notifyError("Downloaded update is corrupted\n" + error); free(data); return false; } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 013f1596ea..cdcf4910cf 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3608,7 +3608,7 @@ int strlcmp(const char* a, const char* b, int len) String highlight(String command) { #define CMP(X) (String(wstart, len) == X) - String::Stream result; + StringBuilder result; int pos = 0; String::value_type const*raw = command.c_str(); String::value_type c; @@ -3622,23 +3622,11 @@ String highlight(String command) while((w = wstart[len]) && ((w >= 'A' && w <= 'Z') || (w >= 'a' && w <= 'z') || (w >= '0' && w <= '9') || w == '_')) len++; if(CMP("and") || CMP("break") || CMP("do") || CMP("else") || CMP("elseif") || CMP("end") || CMP("for") || CMP("function") || CMP("if") || CMP("in") || CMP("local") || CMP("not") || CMP("or") || CMP("repeat") || CMP("return") || CMP("then") || CMP("until") || CMP("while")) - { - result << String("\x0F\xB5\x89\x01"); - result.write(wstart, len); - result << String("\bw"); - } + result << "\x0F\xB5\x89\x01" << String(wstart, len) << "\bw"; else if(CMP("false") || CMP("nil") || CMP("true")) - { - result << String("\x0F\xCB\x4B\x16"); - result.write(wstart, len); - result << String("\bw"); - } + result << "\x0F\xCB\x4B\x16" << String(wstart, len) << "\bw"; else - { - result << String("\x0F\x2A\xA1\x98"); - result.write(wstart, len); - result << String("\bw"); - } + result << "\x0F\x2A\xA1\x98" << String(wstart, len) << "\bw"; pos += len; } else if((c >= '0' && c <= '9') || (c == '.' && raw[pos + 1] >= '0' && raw[pos + 1] <= '9')) @@ -3650,9 +3638,7 @@ String highlight(String command) String::value_type const* wstart = raw+pos; while((w = wstart[len]) && ((w >= '0' && w <= '9') || (w >= 'A' && w <= 'F') || (w >= 'a' && w <= 'f'))) len++; - result << String("\x0F\xD3\x36\x82"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\xD3\x36\x82" << String(wstart, len) << "\bw"; pos += len; } else @@ -3681,9 +3667,7 @@ String highlight(String command) while((w = wstart[len]) && (w >= '0' && w <= '9')) len++; } - result << String("\x0F\xD3\x36\x82"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\xD3\x36\x82" << String(wstart, len) << "\bw"; pos += len; } } @@ -3715,9 +3699,7 @@ String highlight(String command) } len++; } - result << String("\x0F\xDC\x32\x2F"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\xDC\x32\x2F" << String(wstart, len) << "\bw"; pos += len; } else @@ -3733,9 +3715,7 @@ String highlight(String command) } if(w == c) len++; - result << String("\x0F\xDC\x32\x2F"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\xDC\x32\x2F" << String(wstart, len) << "\bw"; pos += len; } } @@ -3767,9 +3747,7 @@ String highlight(String command) } len++; } - result << String("\x0F\x85\x99\x01"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\x85\x99\x01" << String(wstart, len) << "\bw"; pos += len; } else @@ -3779,20 +3757,18 @@ String highlight(String command) String::value_type const* wstart = raw + pos; while((w = wstart[len]) && (w != '\n')) len++; - result << String("\x0F\x85\x99\x01"); - result.write(wstart, len); - result << String("\bw"); + result << "\x0F\x85\x99\x01" << String(wstart, len) << "\bw"; pos += len; } } else if(c == '{' || c == '}') { - result << String("\x0F\xCB\x4B\x16") << c; + result << "\x0F\xCB\x4B\x16" << c << "\bw"; pos++; } else if(c == '.' && raw[pos + 1] == '.' && raw[pos + 2] == '.') { - result << String("\x0F\x2A\xA1\x98..."); + result << "\x0F\x2A\xA1\x98...\bw"; pos += 3; } else @@ -3801,7 +3777,7 @@ String highlight(String command) pos++; } } - return result.str(); + return result.Build(); } String LuaScriptInterface::FormatCommand(String command) diff --git a/src/lua/TPTSTypes.cpp b/src/lua/TPTSTypes.cpp index caaa6917ae..0d77293c7b 100644 --- a/src/lua/TPTSTypes.cpp +++ b/src/lua/TPTSTypes.cpp @@ -47,9 +47,7 @@ AnyType::operator StringType() { if(type == TypeNumber) { - String::Stream numberStream; - numberStream << ((NumberType *)this)->Value(); - return StringType(numberStream.str()); + return StringType(String::Build(((NumberType *)this)->Value())); } else if(type == TypeString && value.str) { @@ -58,9 +56,7 @@ AnyType::operator StringType() else if (type == TypePoint && value.pt) { ui::Point thisPoint = *(value.pt); - String::Stream pointStream; - pointStream << thisPoint.X << "," << thisPoint.Y; - return StringType(pointStream.str()); + return StringType(String::Build(thisPoint.X, ",", thisPoint.Y)); } else throw InvalidConversionException(type, TypeString); diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 01bbf40ace..11cb273f36 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -13,7 +13,6 @@ sign::sign(String text_, int x_, int y_, Justification justification_): String sign::getText(Simulation *sim) { - String::Stream signTextNew; if (text[0] && text[0] == '{') { if (text == "{p}") @@ -21,37 +20,35 @@ String sign::getText(Simulation *sim) float pressure = 0.0f; if (x >= 0 && x < XRES && y >= 0 && y < YRES) pressure = sim->pv[y/CELL][x/CELL]; - signTextNew << std::fixed << std::showpoint << std::setprecision(2) << "Pressure: " << pressure; + return String::Build("Pressure: ", Format::Precision(Format::ShowPoint(pressure), 2)); } else if (text == "{aheat}") { float aheat = 0.0f; if (x >= 0 && x < XRES && y >= 0 && y < YRES) aheat = sim->hv[y/CELL][x/CELL]; - signTextNew << std::fixed << std::showpoint << std::setprecision(2) << aheat-273.15f; + return String::Build(Format::Precision(Format::ShowPoint(aheat - 273.15f), 2)); } else if (text == "{t}") { if (x >= 0 && x < XRES && y >= 0 && y < YRES && sim->pmap[y][x]) - signTextNew << std::fixed << std::showpoint << std::setprecision(2) << "Temp: " << sim->parts[ID(sim->pmap[y][x])].temp-273.15f; + return String::Build("Temp: ", Format::Precision(Format::ShowPoint(sim->parts[ID(sim->pmap[y][x])].temp - 273.15f), 2)); else - signTextNew << "Temp: 0.00"; + return String::Build("Temp: ", Format::Precision(Format::ShowPoint(0), 2)); } else { int pos = splitsign(text); if (pos) - signTextNew << text.Between(pos + 1, text.size() - 1); + return text.Between(pos + 1, text.size() - 1); else - signTextNew << text; + return text; } } else { - signTextNew << text; + return text; } - - return signTextNew.str(); } void sign::pos(String signText, int & x0, int & y0, int & w, int & h) diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 3e46ecad37..c742ad2985 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -62,16 +62,10 @@ void TaskWindow::Exit() void TaskWindow::NotifyProgress(Task * task) { progress = task->GetProgress(); - String::Stream pStream; if(progress>-1) - { - pStream << progress << "%"; - } + progressStatus = String::Build(progress, "%"); else - { - pStream << "Please wait..."; - } - progressStatus = pStream.str(); + progressStatus = "Please wait..."; } void TaskWindow::OnTick(float dt)