OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
Utf8Sanitizer.h
Go to the documentation of this file.
1#pragma once
2
20#include <cstddef>
21#include <string>
22#include <string_view>
23
24// AssertAllStringFieldsAreValidUtf8 takes a google::protobuf::Message. Include
25// the message header (rather than relying on transitive includes) so this header
26// is self-contained regardless of include order.
27#include <google/protobuf/message.h>
28
29namespace Odb::Lib::Text
30{
44 bool IsValidUtf8(const char* data, std::size_t size) noexcept;
45
51 bool IsValidUtf8(std::string_view s) noexcept;
52
73 std::string ToUtf8(std::string_view input);
74
85 void SanitizeToUtf8(std::string& s);
86
103 void AssertAllStringFieldsAreValidUtf8(const google::protobuf::Message& msg, std::string_view msgName);
104
105} // 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.