2017-03-31 17:56:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SKSL_STRING
|
|
|
|
#define SKSL_STRING
|
|
|
|
|
2021-06-07 20:09:59 +00:00
|
|
|
#include "include/core/SkStringView.h"
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLDefines.h"
|
2017-09-11 20:50:14 +00:00
|
|
|
#include <cstring>
|
2017-09-11 13:42:09 +00:00
|
|
|
#include <stdarg.h>
|
2019-06-07 16:32:35 +00:00
|
|
|
#include <string>
|
2019-06-06 14:04:27 +00:00
|
|
|
|
2019-09-20 16:19:11 +00:00
|
|
|
#ifndef SKSL_STANDALONE
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
class String;
|
|
|
|
|
2019-06-18 14:14:20 +00:00
|
|
|
class SK_API String : public std::string {
|
2017-03-31 17:56:23 +00:00
|
|
|
public:
|
2020-08-17 13:47:01 +00:00
|
|
|
using std::string::string;
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2021-03-18 16:45:15 +00:00
|
|
|
explicit String(std::string s) : INHERITED(std::move(s)) {}
|
2021-06-08 14:23:51 +00:00
|
|
|
explicit String(skstd::string_view s) : INHERITED(s.data(), s.length()) {}
|
2021-06-07 20:09:59 +00:00
|
|
|
// TODO(johnstiles): add operator skstd::string_view
|
2017-09-11 20:50:14 +00:00
|
|
|
|
2021-02-18 01:43:54 +00:00
|
|
|
static String printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2);
|
|
|
|
void appendf(const char* fmt, ...) SK_PRINTF_LIKE(2, 3);
|
2017-03-31 17:56:23 +00:00
|
|
|
void vappendf(const char* fmt, va_list va);
|
|
|
|
|
2021-06-10 15:21:59 +00:00
|
|
|
bool starts_with(const char prefix[]) const {
|
2021-06-10 17:06:39 +00:00
|
|
|
return skstd::string_view(data(), size()).starts_with(prefix);
|
2020-11-13 20:55:27 +00:00
|
|
|
}
|
2021-06-10 15:21:59 +00:00
|
|
|
bool ends_with(const char suffix[]) const {
|
2021-06-10 17:06:39 +00:00
|
|
|
return skstd::string_view(data(), size()).ends_with(suffix);
|
2020-11-13 20:55:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 21:43:11 +00:00
|
|
|
bool consumeSuffix(const char suffix[]);
|
2018-08-31 14:52:47 +00:00
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
String operator+(const char* s) const;
|
|
|
|
String operator+(const String& s) const;
|
2021-06-10 17:06:39 +00:00
|
|
|
String operator+(skstd::string_view s) const;
|
2017-09-11 20:50:14 +00:00
|
|
|
String& operator+=(char c);
|
|
|
|
String& operator+=(const char* s);
|
|
|
|
String& operator+=(const String& s);
|
2021-06-10 17:06:39 +00:00
|
|
|
String& operator+=(skstd::string_view s);
|
2017-03-31 17:56:23 +00:00
|
|
|
friend String operator+(const char* s1, const String& s2);
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = std::string;
|
2017-03-31 17:56:23 +00:00
|
|
|
};
|
|
|
|
|
2021-06-10 17:06:39 +00:00
|
|
|
String operator+(skstd::string_view left, skstd::string_view right);
|
2017-03-31 17:56:23 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-06-10 17:06:39 +00:00
|
|
|
bool stod(const skstd::string_view& s, SKSL_FLOAT* value);
|
|
|
|
bool stoi(const skstd::string_view& s, SKSL_INT* value);
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2020-12-23 23:58:43 +00:00
|
|
|
} // namespace SkSL
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
namespace std {
|
2017-03-31 17:56:23 +00:00
|
|
|
template<> struct hash<SkSL::String> {
|
|
|
|
size_t operator()(const SkSL::String& s) const {
|
|
|
|
return hash<std::string>{}(s);
|
|
|
|
}
|
|
|
|
};
|
2019-06-07 16:32:35 +00:00
|
|
|
} // namespace std
|
2017-03-31 17:56:23 +00:00
|
|
|
|
|
|
|
#endif
|