Sha256: fc16de6f4545a78b8d340ed4c4430e02e5bd88ce0c3fccd6fa39b0748e509b23
Contents?: true
Size: 1.74 KB
Versions: 29
Compression:
Stored size: 1.74 KB
Contents
#pragma once #include "GraphicsImpl.hpp" #include <functional> #include <vector> namespace Gosu { struct FormattedString { std::u32string text; Color color = Color::WHITE; unsigned flags = 0; bool can_be_merged_with(const FormattedString& other) const { return color == other.color && flags == other.flags; } }; class MarkupParser { // The current parser position. const char* markup; // A substring that will be built up during parsing, then passed to the consumer. std::string substring; // Current b/i/u counters. An opening tag increases by 1, a closing tag decreases by 1. // Text is bold/italic/underline when the respective counter is > 0. int b, i, u; // Current color stack. std::vector<Color> c{ Color::WHITE }; enum { IGNORE_WORDS, ADDING_WORD, ADDING_WHITESPACE } word_state; std::vector<FormattedString> substrings; std::function<void (std::vector<FormattedString>)> consumer; unsigned flags() const; template<size_t N> bool match_and_skip(const char (&chars)[N]) { return match_and_skip(chars, N - 1 /* do not match terminating zero */); } bool match_and_skip(const char* chars, std::size_t length); bool parse_markup(); bool parse_escape_entity(); void add_current_substring(); void add_composed_substring(std::u32string&& substring); void flush_to_consumer(); public: MarkupParser(unsigned base_flags, bool split_words, std::function<void (std::vector<FormattedString>)> consumer); void parse(const std::string& markup); }; }
Version data entries
29 entries across 29 versions & 1 rubygems