Skip to content

Commit

Permalink
Get rid of boost::starts_with
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Jan 21, 2025
1 parent eb2e503 commit 22b03bc
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 31 deletions.
1 change: 0 additions & 1 deletion libaegisub/ass/karaoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <libaegisub/karaoke_matcher.h>
#include <libaegisub/format.h>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>

namespace agi::ass {
Expand Down
4 changes: 2 additions & 2 deletions src/ass_dialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ class tokenizer {

void AssDialogue::Parse(std::string const& raw) {
std::string_view str = raw;
if (boost::starts_with(raw, "Dialogue:")) {
if (raw.starts_with("Dialogue:")) {
Comment = false;
str.remove_prefix(10);
}
else if (boost::starts_with(raw, "Comment:")) {
else if (raw.starts_with("Comment:")) {
Comment = true;
str.remove_prefix(9);
}
Expand Down
7 changes: 3 additions & 4 deletions src/ass_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <libaegisub/split.h>
#include <libaegisub/string.h>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <functional>
Expand All @@ -57,8 +56,8 @@ template<> std::string AssOverrideParameter::Get<std::string>() const {
if (omitted) throw agi::InternalError("AssOverrideParameter::Get() called on omitted parameter");
if (block.get()) {
std::string str(block->GetText());
if (boost::starts_with(str, "{")) str.erase(begin(str));
if (boost::ends_with(str, "}")) str.erase(end(str) - 1);
if (str.starts_with("{")) str.erase(begin(str));
if (str.starts_with("}")) str.erase(end(str) - 1);
return str;
}
return value;
Expand Down Expand Up @@ -442,7 +441,7 @@ void AssOverrideTag::Clear() {
void AssOverrideTag::SetText(const std::string &text) {
load_protos();
for (auto cur = proto.begin(); cur != proto.end(); ++cur) {
if (boost::starts_with(text, cur->name)) {
if (text.starts_with(cur->name)) {
Name = cur->name;
parse_parameters(this, text.substr(Name.size()), cur);
valid = true;
Expand Down
19 changes: 9 additions & 10 deletions src/ass_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <algorithm>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
Expand Down Expand Up @@ -84,7 +83,7 @@ class AssParser::HeaderToProperty {
return true;
}

if (boost::starts_with(key, "Automation Settings ")) {
if (key.starts_with("Automation Settings ")) {
target->Properties.automation_settings[key.substr(strlen("Automation Settings"))] = value;
return true;
}
Expand All @@ -104,7 +103,7 @@ AssParser::AssParser(AssFile *target, int version)
AssParser::~AssParser() = default;

void AssParser::ParseAttachmentLine(std::string const& data) {
bool is_filename = boost::starts_with(data, "fontname: ") || boost::starts_with(data, "filename: ");
bool is_filename = data.starts_with("fontname: ") || data.starts_with("filename: ");

bool valid_data = data.size() > 0 && data.size() <= 80;
for (auto byte : data) {
Expand All @@ -129,13 +128,13 @@ void AssParser::ParseAttachmentLine(std::string const& data) {
}

void AssParser::ParseScriptInfoLine(std::string const& data) {
if (boost::starts_with(data, ";")) {
if (data.starts_with(";")) {
// Skip stupid comments added by other programs
// Of course, we'll add our own in place later... ;)
return;
}

if (boost::starts_with(data, "ScriptType:")) {
if (data.starts_with("ScriptType:")) {
std::string version_str = data.substr(11);
boost::trim(version_str);
boost::to_lower(version_str);
Expand All @@ -149,7 +148,7 @@ void AssParser::ParseScriptInfoLine(std::string const& data) {

// Nothing actually supports the Collisions property and malformed values
// crash VSFilter, so just remove it entirely
if (boost::starts_with(data, "Collisions:"))
if (data.starts_with("Collisions:"))
return;

size_t pos = data.find(':');
Expand All @@ -175,22 +174,22 @@ void AssParser::ParseMetadataLine(std::string const& data) {
}

void AssParser::ParseEventLine(std::string const& data) {
if (boost::starts_with(data, "Dialogue:") || boost::starts_with(data, "Comment:"))
if (data.starts_with("Dialogue:") || data.starts_with("Comment:"))
target->Events.push_back(*new AssDialogue(data));
}

void AssParser::ParseStyleLine(std::string const& data) {
if (boost::starts_with(data, "Style:"))
if (data.starts_with("Style:"))
target->Styles.push_back(*new AssStyle(data, version));
}

void AssParser::ParseFontLine(std::string const& data) {
if (boost::starts_with(data, "fontname: "))
if (data.starts_with("fontname: "))
attach = std::make_unique<AssAttachment>(data, AssEntryGroup::FONT);
}

void AssParser::ParseGraphicsLine(std::string const& data) {
if (boost::starts_with(data, "filename: "))
if (data.starts_with("filename: "))
attach = std::make_unique<AssAttachment>(data, AssEntryGroup::GRAPHIC);
}

Expand Down
6 changes: 3 additions & 3 deletions src/command/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ struct edit_line_join_keep_first final : public validate_sel_multiple {
static bool try_paste_lines(agi::Context *c) {
std::string data = GetClipboard();
boost::trim_left(data);
if (!boost::starts_with(data, "Dialogue:")) return false;
if (!data.starts_with("Dialogue:")) return false;

EntryList<AssDialogue> parsed;
boost::char_separator<char> sep("\r\n");
Expand Down Expand Up @@ -944,7 +944,7 @@ void expand_times(AssDialogue *src, AssDialogue *dst) {
}

bool check_start(AssDialogue *d1, AssDialogue *d2) {
if (boost::starts_with(d1->Text.get(), d2->Text.get())) {
if (d1->Text.get().starts_with(d2->Text.get())) {
d1->Text = trim_text(d1->Text.get().substr(d2->Text.get().size()));
expand_times(d1, d2);
return true;
Expand All @@ -953,7 +953,7 @@ bool check_start(AssDialogue *d1, AssDialogue *d2) {
}

bool check_end(AssDialogue *d1, AssDialogue *d2) {
if (boost::ends_with(d1->Text.get(), d2->Text.get())) {
if (d1->Text.get().ends_with(d2->Text.get())) {
d1->Text = trim_text(d1->Text.get().substr(0, d1->Text.get().size() - d2->Text.get().size()));
expand_times(d1, d2);
return true;
Expand Down
5 changes: 2 additions & 3 deletions src/command/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include <libaegisub/util.h>

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>
#include <wx/msgdlg.h>
#include <wx/textdlg.h>
Expand Down Expand Up @@ -475,12 +474,12 @@ static void save_snapshot(agi::Context *c, bool raw, bool subsonly = false) {
agi::fs::path basepath;

auto videoname = c->project->VideoName();
bool is_dummy = boost::starts_with(videoname.string(), "?dummy");
bool is_dummy = videoname.string().starts_with("?dummy");

// Is it a path specifier and not an actual fixed path?
if (option[0] == '?') {
// If dummy video is loaded, we can't save to the video location
if (boost::starts_with(option, "?video") && is_dummy) {
if (option.starts_with("?video") && is_dummy) {
// So try the script location instead
option = "?script";
}
Expand Down
3 changes: 1 addition & 2 deletions src/resolution_resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <libaegisub/ycbcr_conv.h>

#include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
#include <cmath>
#include <wx/intl.h>

Expand Down Expand Up @@ -157,7 +156,7 @@ namespace {
}

void resample_line(resample_state *state, AssDialogue &diag) {
if (diag.Comment && (boost::starts_with(diag.Effect.get(), "template") || boost::starts_with(diag.Effect.get(), "code")))
if (diag.Comment && (diag.Effect.get().starts_with("template") || diag.Effect.get().starts_with("code")))
return;

auto blocks = diag.ParseTags();
Expand Down
4 changes: 2 additions & 2 deletions src/subtitle_format_txt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ void TXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename,
if (value.empty() && !OPT_GET("Tool/Import/Text/Include Blank")->GetBool()) continue;

// Check if this isn't a timecodes file
if (boost::starts_with(value, "# timecode"))
if (value.starts_with("# timecode"))
throw SubtitleFormatParseError("File is a timecode file, cannot load as subtitles.");

// Read comment data
bool isComment = false;
if (!comment.empty() && boost::starts_with(value, comment)) {
if (!comment.empty() && value.starts_with(comment)) {
isComment = true;
value.erase(0, comment.size());
}
Expand Down
3 changes: 1 addition & 2 deletions src/text_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <libaegisub/file_mapping.h>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/interprocess/streams/bufferstream.hpp>

Expand All @@ -38,7 +37,7 @@ std::string TextFileReader::ReadLineFromFile() {
++iter;
if (trim)
boost::trim(str);
if (boost::starts_with(str, "\xEF\xBB\xBF"))
if (str.starts_with("\xEF\xBB\xBF"))
str.erase(0, 3);
return str;
}
3 changes: 1 addition & 2 deletions src/video_provider_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <libaegisub/split.h>
#include <libaegisub/util.h>

#include <boost/algorithm/string/predicate.hpp>
#include <libaegisub/format.h>
#include <boost/gil.hpp>

Expand Down Expand Up @@ -129,7 +128,7 @@ void DummyVideoProvider::GetFrame(int, VideoFrame &frame) {
namespace agi { class BackgroundRunner; }
std::unique_ptr<VideoProvider> CreateDummyVideoProvider(agi::fs::path const& filename, std::string_view, agi::BackgroundRunner *) {
// Use filename.generic_string here so forward slashes stay as they are
if (!boost::starts_with(filename.generic_string(), "?dummy"))
if (!filename.generic_string().starts_with("?dummy"))
return {};

std::vector<std::string> toks;
Expand Down

0 comments on commit 22b03bc

Please sign in to comment.