add stringview.cc
This commit is contained in:
12
c_os/user/lib/StringView.cc
Normal file
12
c_os/user/lib/StringView.cc
Normal file
@ -0,0 +1,12 @@
|
||||
#include "user/lib/StringView.h"
|
||||
|
||||
bse::string_view bse::string_view::substring(std::size_t first, std::size_t last) const {
|
||||
if (first < 0 || first > len || last <= first || last > len) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
string_view new_view;
|
||||
new_view.len = last - first;
|
||||
new_view.buf = &buf[first];
|
||||
return new_view;
|
||||
}
|
@ -22,39 +22,17 @@ namespace bse {
|
||||
string_view(const char* str) : len(strlen(str)), buf(str) {}
|
||||
string_view(const string& str) : len(str.size()), buf(static_cast<char*>(str)) {}
|
||||
|
||||
// iterator begin() { return iterator(buf); }
|
||||
iterator begin() const { return iterator(buf); }
|
||||
// iterator end() { return iterator(&buf[len]); }
|
||||
iterator end() const { return iterator(&buf[len]); }
|
||||
|
||||
// explicit operator const char*() { return buf; }
|
||||
explicit operator const char*() const { return buf; }
|
||||
|
||||
// char operator[](std::size_t pos) { return buf[pos]; }
|
||||
char operator[](std::size_t pos) const { return buf[pos]; }
|
||||
bool operator==(const string_view& other) const { return buf == other.buf; }
|
||||
bool operator!=(const string_view& other) const { return buf != other.buf; }
|
||||
|
||||
bool operator==(const string_view& other) const {
|
||||
return buf == other.buf;
|
||||
}
|
||||
std::size_t size() const { return len; }
|
||||
|
||||
bool operator!=(const string_view& other) const {
|
||||
return buf != other.buf;
|
||||
}
|
||||
|
||||
string_view substring(std::size_t first, std::size_t last) const {
|
||||
if (first < 0 || first > len || last <= first || last > len) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
string_view new_view;
|
||||
new_view.len = last - first;
|
||||
new_view.buf = &buf[first];
|
||||
return new_view;
|
||||
}
|
||||
|
||||
std::size_t size() const {
|
||||
return len;
|
||||
}
|
||||
string_view substring(std::size_t first, std::size_t last) const;
|
||||
};
|
||||
|
||||
} // namespace bse
|
||||
|
Reference in New Issue
Block a user