From 010f6c4f79b0dd6bcc784717ce4aa5c9463523d1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 26 Dec 2014 11:00:23 -0800 Subject: [PATCH] Debloatify some stuff --- libaegisub/ass/time.cpp | 14 +++--- libaegisub/common/format.cpp | 57 +++++++++++++++++++++++ libaegisub/include/libaegisub/ass/smpte.h | 4 +- libaegisub/include/libaegisub/format.h | 30 +----------- src/ass_karaoke.cpp | 2 +- src/dialog_version_check.cpp | 3 +- src/subtitle_format_encore.cpp | 2 +- src/video_provider_dummy.cpp | 3 +- 8 files changed, 72 insertions(+), 43 deletions(-) diff --git a/libaegisub/ass/time.cpp b/libaegisub/ass/time.cpp index 0d05cd4c8..7b0596f00 100644 --- a/libaegisub/ass/time.cpp +++ b/libaegisub/ass/time.cpp @@ -21,9 +21,7 @@ #include #include -#include #include -#include namespace agi { Time::Time(int time) : time(util::mid(0, time, 10 * 60 * 60 * 1000 - 1)) { } @@ -31,7 +29,7 @@ Time::Time(int time) : time(util::mid(0, time, 10 * 60 * 60 * 1000 - 1)) { } Time::Time(std::string const& text) { int after_decimal = -1; int current = 0; - for (char c : text | boost::adaptors::filtered(boost::is_any_of(",.0123456789:"))) { + for (char c : text) { if (c == ':') { time = time * 60 + current; current = 0; @@ -41,6 +39,8 @@ Time::Time(std::string const& text) { current = 0; after_decimal = 100; } + else if (c < '0' || c > '9') + continue; else if (after_decimal < 0) { current *= 10; current += c - '0'; @@ -80,21 +80,21 @@ int Time::GetTimeSeconds() const { return (time % 60000) / 1000; } int Time::GetTimeMiliseconds() const { return (time % 1000); } int Time::GetTimeCentiseconds() const { return (time % 1000) / 10; } -SmpteFormatter::SmpteFormatter(vfr::Framerate fps, std::string sep) +SmpteFormatter::SmpteFormatter(vfr::Framerate fps, char sep) : fps(std::move(fps)) -, sep(std::move(sep)) +, sep(sep) { } std::string SmpteFormatter::ToSMPTE(Time time) const { int h=0, m=0, s=0, f=0; fps.SmpteAtTime(time, &h, &m, &s, &f); - return format("%02d%s%02d%s%02d%s%02d", h, sep, m, sep, s, sep, f); + return format("%02d%c%02d%c%02d%c%02d", h, sep, m, sep, s, sep, f); } Time SmpteFormatter::FromSMPTE(std::string const& str) const { std::vector toks; - boost::split(toks, str, boost::is_any_of(sep)); + boost::split(toks, str, [=](char c) { return c == sep; }); if (toks.size() != 4) return 0; int h, m, s, f; diff --git a/libaegisub/common/format.cpp b/libaegisub/common/format.cpp index 300682017..74cb4a6bf 100644 --- a/libaegisub/common/format.cpp +++ b/libaegisub/common/format.cpp @@ -228,6 +228,63 @@ bool formatter::parse_next() { return true; } +template +Char formatter::next_format() { + this->pending = false; + + if (this->width < 0) { + this->out.fill(' '); + this->out.setf(std::ios::left, std::ios::adjustfield); + this->width = -this->width; + } + this->out.width(this->width); + this->out.precision(this->precision < 0 ? 6 : this->precision); + + Char c = *this->fmt_cur ? this->fmt_cur[0] : 's'; + if (c >= 'A' && c <= 'Z') { + this->out.setf(std::ios::uppercase); + c += 'a' - 'A'; + } + + switch (c) { + case 'c': + this->out.setf(std::ios::dec, std::ios::basefield); + break; + case 'd': case 'i': + this->out.setf(std::ios::dec, std::ios::basefield); + break; + case 'o': + this->out.setf(std::ios::oct, std::ios::basefield); + break; + case 'x': + this->out.setf(std::ios::hex, std::ios::basefield); + break; + case 'u': + this->out.setf(std::ios::dec, std::ios::basefield); + break; + case 'e': + this->out.setf(std::ios::scientific, std::ios::floatfield); + this->out.setf(std::ios::dec, std::ios::basefield); + break; + case 'f': + this->out.setf(std::ios::fixed, std::ios::floatfield); + break; + case 'g': + this->out.setf(std::ios::dec, std::ios::basefield); + this->out.flags(this->out.flags() & ~std::ios::floatfield); + break; + case 'p': + this->out.setf(std::ios::hex, std::ios::basefield); + break; + default: // s and other + this->out.setf(std::ios::boolalpha); + break; + } + + this->fmt = *this->fmt_cur ? this->fmt_cur + 1 : this->fmt_cur; + return c; +} + template formatter::~formatter() { // Write remaining formatting string diff --git a/libaegisub/include/libaegisub/ass/smpte.h b/libaegisub/include/libaegisub/ass/smpte.h index c6bed8034..129825182 100644 --- a/libaegisub/include/libaegisub/ass/smpte.h +++ b/libaegisub/include/libaegisub/ass/smpte.h @@ -27,10 +27,10 @@ class SmpteFormatter { /// Frame rate to use vfr::Framerate fps; /// Separator character - std::string sep; + char sep; public: - SmpteFormatter(vfr::Framerate fps, std::string sep=":"); + SmpteFormatter(vfr::Framerate fps, char sep=':'); /// Convert an Time to a SMPTE timecode std::string ToSMPTE(Time time) const; diff --git a/libaegisub/include/libaegisub/format.h b/libaegisub/include/libaegisub/format.h index 6cdd8766c..790ba861a 100644 --- a/libaegisub/include/libaegisub/format.h +++ b/libaegisub/include/libaegisub/format.h @@ -94,6 +94,7 @@ class formatter : formatter_state { boost::io::basic_ios_all_saver saver; bool parse_next(); + Char next_format(); public: formatter(std::basic_ostream& out, const Char *fmt) @@ -115,68 +116,41 @@ public: this->read_precision = false; return; } - this->pending = false; - if (this->width < 0) { - this->out.fill(' '); - this->out.setf(std::ios::left, std::ios::adjustfield); - this->width = -this->width; - } - this->out.width(this->width); - this->out.precision(this->precision < 0 ? 6 : this->precision); - - Char c = *this->fmt_cur ? this->fmt_cur[0] : 's'; - if (c >= 'A' && c <= 'Z') { - this->out.setf(std::ios::uppercase); - c += 'a' - 'A'; - } + Char c = next_format(); switch (c) { case 'c': - this->out.setf(std::ios::dec, std::ios::basefield); this->out << runtime_cast(value); break; case 'd': case 'i': - this->out.setf(std::ios::dec, std::ios::basefield); this->out << runtime_cast(value); break; case 'o': - this->out.setf(std::ios::oct, std::ios::basefield); this->out << runtime_cast(value); break; case 'x': - this->out.setf(std::ios::hex, std::ios::basefield); this->out << runtime_cast(value); break; case 'u': - this->out.setf(std::ios::dec, std::ios::basefield); this->out << runtime_cast(value); break; case 'e': - this->out.setf(std::ios::scientific, std::ios::floatfield); - this->out.setf(std::ios::dec, std::ios::basefield); this->out << runtime_cast(value); break; case 'f': - this->out.setf(std::ios::fixed, std::ios::floatfield); this->out << runtime_cast(value); break; case 'g': - this->out.setf(std::ios::dec, std::ios::basefield); - this->out.flags(this->out.flags() & ~std::ios::floatfield); this->out << runtime_cast(value); break; case 'p': - this->out.setf(std::ios::hex, std::ios::basefield); this->out << runtime_cast(value); break; default: // s and other - this->out.setf(std::ios::boolalpha); writer::type>::write(this->out, this->precision, value); break; } - - this->fmt = *this->fmt_cur ? this->fmt_cur + 1 : this->fmt_cur; } }; diff --git a/src/ass_karaoke.cpp b/src/ass_karaoke.cpp index a06a81bd3..cc55f6143 100644 --- a/src/ass_karaoke.cpp +++ b/src/ass_karaoke.cpp @@ -129,7 +129,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { else { std::string& otext = syl.ovr_tags[syl.text.size()]; // Merge adjacent override tags - boost::trim_right_if(text, boost::is_any_of("}")); + boost::trim_right_if(text, [](char c) { return c == '}'; }); if (!in_tag) otext += "{"; diff --git a/src/dialog_version_check.cpp b/src/dialog_version_check.cpp index b5d95910e..62e7daede 100644 --- a/src/dialog_version_check.cpp +++ b/src/dialog_version_check.cpp @@ -45,7 +45,6 @@ #include #include -#include #include #include #include @@ -322,7 +321,7 @@ void DoCheck(bool interactive) { if (line.empty()) continue; std::vector parsed; - boost::split(parsed, line, boost::is_any_of("|")); + boost::split(parsed, line, [](char c) { return c == '|'; }); if (parsed.size() != 6) continue; if (atoi(parsed[1].c_str()) <= GetSVNRevision()) diff --git a/src/subtitle_format_encore.cpp b/src/subtitle_format_encore.cpp index 51843180a..cf54b1721 100644 --- a/src/subtitle_format_encore.cpp +++ b/src/subtitle_format_encore.cpp @@ -65,7 +65,7 @@ void EncoreSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& fi // Encore wants ; for NTSC and : for PAL // The manual suggests no other frame rates are supported - agi::SmpteFormatter ft(fps, fps.NeedsDropFrames() ? ";" : ":"); + agi::SmpteFormatter ft(fps, fps.NeedsDropFrames() ? ';' : ':'); // Write lines int i = 0; diff --git a/src/video_provider_dummy.cpp b/src/video_provider_dummy.cpp index 39eb69ebf..b74341aca 100644 --- a/src/video_provider_dummy.cpp +++ b/src/video_provider_dummy.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include #include @@ -107,7 +106,7 @@ std::unique_ptr CreateDummyVideoProvider(agi::fs::path const& fil std::vector toks; auto const& fields = filename.string().substr(7); - boost::split(toks, fields, boost::is_any_of(":")); + boost::split(toks, fields, [](char c) { return c == ':'; }); if (toks.size() != 8) throw VideoOpenError("Too few fields in dummy video parameter list");