30#include <unordered_map>
34#include "pw_result/result.h"
35#include "pw_span/span.h"
36#include "pw_tokenizer/internal/decode.h"
37#include "pw_tokenizer/token_database.h"
39namespace pw::tokenizer {
52 const span<const TokenizedStringEntry>& entries,
53 const span<const std::byte>& arguments);
58 bool ok()
const {
return matches_.size() == 1 && matches_[0].ok(); }
61 const std::vector<DecodedFormatString>&
matches()
const {
return matches_; }
63 const uint32_t& token()
const {
return token_; }
77 std::vector<DecodedFormatString> matches_;
91 std::unordered_map<uint32_t, std::vector<TokenizedStringEntry>>&&
93 : database_(std::move(database)) {}
97 static Result<Detokenizer>
FromElfSection(span<const std::byte> elf_section);
115 return Detokenize(encoded.data(), encoded.size());
120 return Detokenize(span(
static_cast<const std::byte*
>(encoded), size_bytes));
141 unsigned max_passes = 3)
const;
146 std::string_view text)
const {
164 const span<const std::byte>& optionally_tokenized_data);
167 std::unordered_map<uint32_t, std::vector<TokenizedStringEntry>> database_;
Definition: detokenize.h:49
const std::vector< DecodedFormatString > & matches() const
Returns the strings that matched the token, with the best matches first.
Definition: detokenize.h:61
std::string BestString() const
bool ok() const
True if there was only one valid match and it decoded successfully.
Definition: detokenize.h:58
std::string BestStringWithErrors() const
Definition: detokenize.h:82
DetokenizedString Detokenize(const span< const uint8_t > &encoded) const
Overload of Detokenize for span<const uint8_t>.
Definition: detokenize.h:109
DetokenizedString Detokenize(std::string_view encoded) const
Overload of Detokenize for std::string_view.
Definition: detokenize.h:114
std::string DetokenizeBase64(std::string_view text) const
Definition: detokenize.h:145
Detokenizer(std::unordered_map< uint32_t, std::vector< TokenizedStringEntry > > &&database)
Constructs a detokenizer by directly passing the parsed database.
Definition: detokenize.h:90
DetokenizedString DetokenizeBase64Message(std::string_view text) const
static Result< Detokenizer > FromElfSection(span< const uint8_t > elf_section)
Overload of FromElfSection for a uint8_t span.
Definition: detokenize.h:100
Detokenizer(const TokenDatabase &database)
std::string DetokenizeText(std::string_view text, unsigned max_passes=3) const
DetokenizedString Detokenize(const void *encoded, size_t size_bytes) const
Overload of Detokenize for a pointer and length.
Definition: detokenize.h:119
static Result< Detokenizer > FromElfSection(span< const std::byte > elf_section)
DetokenizedString Detokenize(const span< const std::byte > &encoded) const
std::string DecodeOptionallyTokenizedData(const span< const std::byte > &optionally_tokenized_data)
Definition: token_database.h:75
std::pair< FormatString, uint32_t > TokenizedStringEntry
Token database entry.
Definition: detokenize.h:45