Commit 39585e1b authored by Tom Niget's avatar Tom Niget

Add some useful functions to PyStr

parent 1cae67e3
...@@ -12,7 +12,7 @@ using namespace std::literals; ...@@ -12,7 +12,7 @@ using namespace std::literals;
#include "bytes.hpp" #include "bytes.hpp"
#include "print.hpp" #include "print.hpp"
//#include <format> // #include <format>
#include <fmt/format.h> #include <fmt/format.h>
class PyStr : public std::string { class PyStr : public std::string {
...@@ -22,6 +22,7 @@ public: ...@@ -22,6 +22,7 @@ public:
PyStr(const std::string &s) : std::string(s) {} PyStr(const std::string &s) : std::string(s) {}
PyStr(std::string &&s) : std::string(std::move(s)) {} PyStr(std::string &&s) : std::string(std::move(s)) {}
PyStr(size_t count, char ch) : std::string(count, ch) {} PyStr(size_t count, char ch) : std::string(count, ch) {}
constexpr PyStr(const char *s, size_t count) : std::string(s, count) {}
template <class InputIterator> template <class InputIterator>
PyStr(InputIterator first, InputIterator last) : std::string(first, last) {} PyStr(InputIterator first, InputIterator last) : std::string(first, last) {}
...@@ -33,6 +34,8 @@ public: ...@@ -33,6 +34,8 @@ public:
template <typename... T> PyStr format(T &&...args) const { template <typename... T> PyStr format(T &&...args) const {
return PyStr(fmt::format(fmt::runtime(*this), std::forward<T>(args)...)); return PyStr(fmt::format(fmt::runtime(*this), std::forward<T>(args)...));
} }
bool startswith(const std::string &s) const { return this->starts_with(s); }
}; };
inline constexpr PyStr operator""_ps(const char *s, size_t len) noexcept { inline constexpr PyStr operator""_ps(const char *s, size_t len) noexcept {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment