From 28705000bbfaf13c83a30d77315d1457c1ae7743 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 7 Dec 2012 08:06:03 -0800 Subject: [PATCH] Use boost::join in a handful of places --- aegisub/src/ass_dialogue.cpp | 9 +++++---- aegisub/src/ass_override.cpp | 32 ++++++++++++++++---------------- aegisub/src/command/edit.cpp | 17 +++++++---------- aegisub/src/toolbar.cpp | 30 +++++++++++------------------- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index f1491bd05..77b3463f6 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -48,6 +48,8 @@ #include +using namespace boost::adaptors; + std::size_t hash_value(wxString const& s) { return wxStringHash()(s); } @@ -290,7 +292,7 @@ void AssDialogue::StripTag(wxString const& tag_name) { static wxString get_text(AssDialogueBlock &d) { return d.GetText(); } void AssDialogue::UpdateText(boost::ptr_vector& blocks) { if (blocks.empty()) return; - Text = join(blocks | boost::adaptors::transformed(get_text), wxS("")); + Text = join(blocks | transformed(get_text), wxS("")); } void AssDialogue::SetMarginString(wxString const& origvalue, int which) { @@ -323,12 +325,11 @@ bool AssDialogue::CollidesWith(const AssDialogue *target) const { return ((Start < target->Start) ? (target->Start < End) : (Start < target->End)); } +static wxString get_text_p(AssDialogueBlock *d) { return d->GetText(); } wxString AssDialogue::GetStrippedText() const { wxString ret; boost::ptr_vector blocks(ParseTags()); - for (auto block : blocks | agi::of_type()) - ret += block->GetText(); - return ret; + return join(blocks | agi::of_type() | transformed(get_text_p), wxS("")); } AssEntry *AssDialogue::Clone() const { diff --git a/aegisub/src/ass_override.cpp b/aegisub/src/ass_override.cpp index 9d5634874..e83ccff4f 100644 --- a/aegisub/src/ass_override.cpp +++ b/aegisub/src/ass_override.cpp @@ -35,15 +35,21 @@ #include "config.h" -#include -#include - #include #include "ass_dialogue.h" #include "ass_override.h" #include "utils.h" +#include +#include +#include +#include +#include +#include + +using namespace boost::adaptors; + AssOverrideParameter::AssOverrideParameter() : classification(PARCLASS_NORMAL) , omitted(false) @@ -91,11 +97,9 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) { Tags.push_back(new AssOverrideTag(tag)); } +static wxString tag_str(AssOverrideTag *t) { return *t; } wxString AssDialogueBlockOverride::GetText() { - text = "{"; - for (auto tag : Tags) - text += *tag; - text += "}"; + text = "{" + join(Tags | transformed(tag_str), wxString()) + "}"; return text; } @@ -424,6 +428,7 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto:: } } +static wxString param_str(AssOverrideParameter *p) { return p->Get(); } AssOverrideTag::operator wxString() const { wxString result = Name; @@ -432,15 +437,10 @@ AssOverrideTag::operator wxString() const { if (parentheses) result += "("; // Add parameters - bool any = false; - for (auto param : Params) { - if (param->GetType() != VARDATA_NONE && !param->omitted) { - result += param->Get(); - result += ","; - any = true; - } - } - if (any) result.resize(result.size() - 1); + result += join(Params + | filtered([](AssOverrideParameter *p) { return p->GetType() != VARDATA_NONE && !p->omitted; }) + | transformed(param_str), + wxS(",")); if (parentheses) result += ")"; return result; diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 6afe4cccf..e5846c769 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -60,6 +60,7 @@ #include "../utils.h" #include "../video_context.h" +#include #include #include @@ -468,18 +469,14 @@ struct edit_find_replace : public Command { } }; +static wxString get_entry_data(AssDialogue *d) { return d->GetEntryData(); } static void copy_lines(agi::Context *c) { - wxString data; SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (auto diag : c->ass->Line | agi::of_type()) { - if (sel.count(diag)) { - if (!data.empty()) - data += "\r\n"; - data += diag->GetEntryData(); - } - } - - SetClipboard(data); + SetClipboard(join(c->ass->Line + | agi::of_type() + | filtered([&](AssDialogue *d) { return sel.count(d); }) + | transformed(get_entry_data), + wxS(""))); } static void delete_lines(agi::Context *c, wxString const& commit_message) { diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 638d73cf3..476d6b62c 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -26,23 +26,23 @@ #include "libresrc/libresrc.h" #include "main.h" +#include +#include +#include +#include + +#include #include #include #include #include -#include -#include -#include -#include - namespace { json::Object const& get_root() { static json::Object root; - if (root.empty()) { + if (root.empty()) root = agi::json_util::parse(new std::istringstream(GET_DEFAULT_CONFIG(default_toolbar))); - } return root; } @@ -70,12 +70,10 @@ namespace { /// Enable/disable the toolbar buttons void OnIdle(wxIdleEvent &) { for (size_t i = 0; i < commands.size(); ++i) { - if (commands[i]->Type() & cmd::COMMAND_VALIDATE) { + if (commands[i]->Type() & cmd::COMMAND_VALIDATE) EnableTool(TOOL_ID_BASE + i, commands[i]->Validate(context)); - } - if (commands[i]->Type() & cmd::COMMAND_TOGGLE || commands[i]->Type() & cmd::COMMAND_RADIO) { + if (commands[i]->Type() & cmd::COMMAND_TOGGLE || commands[i]->Type() & cmd::COMMAND_RADIO) ToggleTool(TOOL_ID_BASE + i, commands[i]->IsActive(context)); - } } } @@ -157,14 +155,8 @@ namespace { wxString ret = command->StrHelp(); std::vector hotkeys = hotkey::get_hotkey_strs(ht_context, command->name()); - for (size_t i = 0; i < hotkeys.size(); ++i) { - if (i == 0) - ret += " ("; - else - ret += "/"; - ret += hotkeys[i]; - } - if (hotkeys.size()) ret += ")"; + if (!hotkeys.empty()) + ret += " (" + boost::join(hotkeys, "/") + ")"; return ret; }