Entropic
2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
utf8_safe.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
#pragma once
3
4
#include <string>
5
#include <cstddef>
6
19
namespace
entropic::facade {
20
32
inline
std::string
utf8_safe_substr
(
const
std::string& s, std::size_t max_bytes) {
33
if
(s.size() <= max_bytes) {
return
s; }
34
std::size_t cut = max_bytes;
35
while
(cut > 0
36
&& (
static_cast<
unsigned
char
>
(s[cut]) & 0xC0) == 0x80) {
37
--cut;
38
}
39
return
s.substr(0, cut);
40
}
41
42
}
// namespace entropic::facade
entropic::facade::utf8_safe_substr
std::string utf8_safe_substr(const std::string &s, std::size_t max_bytes)
Truncate a UTF-8 string at-or-before a byte cap on a codepoint boundary.
Definition
utf8_safe.h:32
facade
utf8_safe.h
Generated by
1.9.8