OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
Utf8Sanitizer.h
Go to the documentation of this file.
1#pragma once
2
22#include <cstddef>
23#include <string>
24#include <string_view>
25
26// AssertAllStringFieldsAreValidUtf8 takes a google::protobuf::Message. Include
27// the message header (rather than relying on transitive includes) so this header
28// is self-contained regardless of include order.
29#include <google/protobuf/message.h>
30
31namespace Odb::Lib::Text
32{
46 bool IsValidUtf8(const char* data, std::size_t size) noexcept;
47
53 bool IsValidUtf8(std::string_view s) noexcept;
54
75 std::string ToUtf8(std::string_view input);
76
87 void SanitizeToUtf8(std::string& s);
88
105 void AssertAllStringFieldsAreValidUtf8(const google::protobuf::Message& msg, std::string_view msgName);
106
107} // namespace Odb::Lib::Text
void AssertAllStringFieldsAreValidUtf8(const google::protobuf::Message &msg, std::string_view msgName)
Debug-only assertion to verify all string fields in a message are valid UTF-8.
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.
void SanitizeToUtf8(std::string &s)
In-place convenience overload.
bool IsValidUtf8(const char *data, std::size_t size) noexcept
Validates that a byte sequence is valid UTF-8 per RFC 3629.