Simplify SkSL::String by removing unused parts.
- reset, findLastOf: these were entirely unused - find: already existed in C++11's std::string, can just be inherited - defaulted constructors: in C++11, these can be inherited directly from std::string via 'using' Change-Id: I1772ef04e49ab905aaada2ec38c1abeb9a8e26bf Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311039 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
15a5403cd3
commit
fdbd50a8dc
@ -33,16 +33,6 @@ void String::appendf(const char* fmt, ...) {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void String::reset() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
int String::findLastOf(const char c) const {
|
||||
// Rely on find_last_of and remap the output
|
||||
size_t index = this->find_last_of(c);
|
||||
return (index == std::string::npos ? -1 : index);
|
||||
}
|
||||
|
||||
void String::vappendf(const char* fmt, va_list args) {
|
||||
#define BUFFER_SIZE 256
|
||||
char buffer[BUFFER_SIZE];
|
||||
@ -59,27 +49,16 @@ void String::vappendf(const char* fmt, va_list args) {
|
||||
va_end(reuse);
|
||||
}
|
||||
|
||||
|
||||
bool String::startsWith(const char* s) const {
|
||||
return !strncmp(c_str(), s, strlen(s));
|
||||
bool String::startsWith(const char prefix[]) const {
|
||||
return !strncmp(this->data(), prefix, strlen(prefix));
|
||||
}
|
||||
|
||||
bool String::endsWith(const char* s) const {
|
||||
size_t len = strlen(s);
|
||||
if (size() < len) {
|
||||
bool String::endsWith(const char suffix[]) const {
|
||||
size_t suffixLength = strlen(suffix);
|
||||
if (this->length() < suffixLength) {
|
||||
return false;
|
||||
}
|
||||
return !strncmp(c_str() + size() - len, s, len);
|
||||
}
|
||||
|
||||
int String::find(const String& substring, int fromPos) const {
|
||||
return find(substring.c_str(), fromPos);
|
||||
}
|
||||
|
||||
int String::find(const char* substring, int fromPos) const {
|
||||
SkASSERT(fromPos >= 0);
|
||||
size_t found = INHERITED::find(substring, (size_t) fromPos);
|
||||
return found == std::string::npos ? -1 : found;
|
||||
return !strncmp(this->data() + this->size() - suffixLength, suffix, suffixLength);
|
||||
}
|
||||
|
||||
String String::operator+(const char* s) const {
|
||||
|
@ -57,36 +57,16 @@ bool operator!=(const char* s1, StringFragment s2);
|
||||
|
||||
class SK_API String : public std::string {
|
||||
public:
|
||||
String() = default;
|
||||
String(const String&) = default;
|
||||
String(String&&) = default;
|
||||
String& operator=(const String&) = default;
|
||||
String& operator=(String&&) = default;
|
||||
using std::string::string;
|
||||
|
||||
String(const char* s)
|
||||
: INHERITED(s) {}
|
||||
|
||||
String(const char* s, size_t size)
|
||||
: INHERITED(s, size) {}
|
||||
|
||||
String(StringFragment s)
|
||||
: INHERITED(s.fChars, s.fLength) {}
|
||||
String(StringFragment s) : INHERITED(s.fChars, s.fLength) {}
|
||||
|
||||
static String printf(const char* fmt, ...);
|
||||
|
||||
void appendf(const char* fmt, ...);
|
||||
// For API compatibility with SkString's reset (vs. std:string's clear)
|
||||
void reset();
|
||||
// For API compatibility with SkString's findLastOf(vs. find_last_of -> size_t)
|
||||
int findLastOf(const char c) const;
|
||||
|
||||
void vappendf(const char* fmt, va_list va);
|
||||
|
||||
bool startsWith(const char* s) const;
|
||||
bool endsWith(const char* s) const;
|
||||
|
||||
int find(const char* substring, int fromPos = 0) const;
|
||||
int find(const String& substring, int fromPos = 0) const;
|
||||
bool startsWith(const char* prefix) const;
|
||||
bool endsWith(const char* suffix) const;
|
||||
|
||||
String operator+(const char* s) const;
|
||||
String operator+(const String& s) const;
|
||||
@ -111,19 +91,13 @@ String operator+(const char* s1, const String& s2);
|
||||
bool operator!=(const char* s1, const String& s2);
|
||||
|
||||
String to_string(double value);
|
||||
|
||||
String to_string(int32_t value);
|
||||
|
||||
String to_string(uint32_t value);
|
||||
|
||||
String to_string(int64_t value);
|
||||
|
||||
String to_string(uint64_t value);
|
||||
|
||||
SKSL_INT stoi(const String& s);
|
||||
|
||||
SKSL_FLOAT stod(const String& s);
|
||||
|
||||
long stol(const String& s);
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -25,6 +25,7 @@ DEF_TEST(crbug_ossfuzz_21688_interfaceblock, reporter) {
|
||||
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
|
||||
kProgramText, settings);
|
||||
REPORTER_ASSERT(reporter, program == nullptr);
|
||||
REPORTER_ASSERT(reporter, compiler.errorText().find("interface block 'testBlock' must "
|
||||
"contain at least one member") != -1);
|
||||
REPORTER_ASSERT(reporter, compiler.errorText().find(
|
||||
"interface block 'testBlock' must "
|
||||
"contain at least one member") != SkSL::String::npos);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user