Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/support/istring.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ struct IString {
return startsWith(std::string_view(str));
}

bool endsWith(std::string_view suffix) const {
// TODO: Use C++20 `ends_with`.
if (suffix.size() > str.size()) {
return false;
}
return str.substr(str.size() - suffix.size()) == suffix;
}
bool endsWith(IString str) const { return endsWith(str.str); }

// Disambiguate for string literals.
template<int N> bool endsWith(const char (&str)[N]) const {
return endsWith(std::string_view(str));
}

IString substr(size_t pos, size_t len = std::string_view::npos) const {
return IString(str.substr(pos, len));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has binararyen really gone this long without a substr() or endswith() operations on strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently 🤷🏻


size_t size() const { return str.size(); }
};

Expand Down
6 changes: 6 additions & 0 deletions src/tools/wasm-split/wasm-split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ void multiSplitModule(const WasmSplitOptions& options) {
}
Name name = WasmBinaryReader::escape(line);
if (newSection) {
if (name.endsWith(":")) {
name = name.substr(0, name.size() - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could be clever and allow (0, -1) here like in high level languages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In basic_string_view::substr, the second argument is a count, the number of characters, so I think making the meaning of IString::substr different will be confusing. If we want that behavior we can add a separate function like slice(size_t start, size_end) or something. But we only have a single use here now, so I'm not sure if that's necessary at this point?

if (name.size() == 0) {
Fatal() << "Module name is empty\n";
}
}
if (moduleNameSet.count(name)) {
Fatal() << "Module name " << name << " is listed more than once\n";
}
Expand Down
6 changes: 3 additions & 3 deletions test/lit/wasm-split/multi-split-escape-names.wast.manifest
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1
1:
wasm::Type::getFeatures() const

2
2:
wasm::Literal::Literal(std::__2::array<wasm::Literal, 4ul> const&)

3
3:
std::operator<<(std::__2::basic_ostream<char, std::__2::char_traits<char>>&, wasm::Module&)
6 changes: 3 additions & 3 deletions test/lit/wasm-split/multi-split.wast.manifest
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1
1:
A

2
2:
B

3
3:
C
Loading