mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 11:37:12 +01:00

* [vcpkg] Add initial JSON support This adds a JSON parser, as well as the amount of unicode support required for JSON parsing to work according to the specification. In the future, I hope to rewrite our existing XML files into JSON. Additionally, as a drive-by, we've added the following: * add /wd4800 to pragmas.h -- this is a "performance warning", for when you implicitly convert pointers or integers to bool, and shouldn't be an issue for us. * Switched Parse::ParserBase to read unicode (as utf-8), as opposed to ASCII * Building again under VCPKG_DEVELOPMENT_WARNINGS, yay!
53 lines
1.9 KiB
C++
53 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <vcpkg/base/optional.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace vcpkg
|
|
{
|
|
struct StringView
|
|
{
|
|
static std::vector<StringView> find_all_enclosed(const StringView& input,
|
|
const std::string& left_delim,
|
|
const std::string& right_delim);
|
|
|
|
static StringView find_exactly_one_enclosed(const StringView& input,
|
|
const std::string& left_tag,
|
|
const std::string& right_tag);
|
|
|
|
static Optional<StringView> find_at_most_one_enclosed(const StringView& input,
|
|
const std::string& left_tag,
|
|
const std::string& right_tag);
|
|
|
|
constexpr StringView() = default;
|
|
StringView(const std::string& s); // Implicit by design
|
|
|
|
// NOTE: we do this instead of the delegating constructor since delegating ctors are a perf footgun
|
|
template<size_t Sz>
|
|
constexpr StringView(const char (&arr)[Sz]) : m_ptr(arr), m_size(Sz - 1)
|
|
{
|
|
}
|
|
|
|
constexpr StringView(const char* ptr, size_t size) : m_ptr(ptr), m_size(size) {}
|
|
constexpr StringView(const char* b, const char* e) : m_ptr(b), m_size(static_cast<size_t>(e - b)) {}
|
|
|
|
constexpr const char* begin() const { return m_ptr; }
|
|
constexpr const char* end() const { return m_ptr + m_size; }
|
|
|
|
constexpr const char* data() const { return m_ptr; }
|
|
constexpr size_t size() const { return m_size; }
|
|
|
|
std::string to_string() const;
|
|
void to_string(std::string& out) const;
|
|
|
|
private:
|
|
const char* m_ptr = 0;
|
|
size_t m_size = 0;
|
|
};
|
|
|
|
bool operator==(StringView lhs, StringView rhs) noexcept;
|
|
bool operator!=(StringView lhs, StringView rhs) noexcept;
|
|
}
|