xref: /aosp_15_r20/external/brotli/c/enc/utf8_util.h (revision f4ee7fba7774faf2a30f13154332c0a06550dbc4)
1*f4ee7fbaSAndroid Build Coastguard Worker /* Copyright 2013 Google Inc. All Rights Reserved.
2*f4ee7fbaSAndroid Build Coastguard Worker 
3*f4ee7fbaSAndroid Build Coastguard Worker    Distributed under MIT license.
4*f4ee7fbaSAndroid Build Coastguard Worker    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5*f4ee7fbaSAndroid Build Coastguard Worker */
6*f4ee7fbaSAndroid Build Coastguard Worker 
7*f4ee7fbaSAndroid Build Coastguard Worker /* Heuristics for deciding about the UTF8-ness of strings. */
8*f4ee7fbaSAndroid Build Coastguard Worker 
9*f4ee7fbaSAndroid Build Coastguard Worker #ifndef BROTLI_ENC_UTF8_UTIL_H_
10*f4ee7fbaSAndroid Build Coastguard Worker #define BROTLI_ENC_UTF8_UTIL_H_
11*f4ee7fbaSAndroid Build Coastguard Worker 
12*f4ee7fbaSAndroid Build Coastguard Worker #include "../common/platform.h"
13*f4ee7fbaSAndroid Build Coastguard Worker #include <brotli/types.h>
14*f4ee7fbaSAndroid Build Coastguard Worker 
15*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
16*f4ee7fbaSAndroid Build Coastguard Worker extern "C" {
17*f4ee7fbaSAndroid Build Coastguard Worker #endif
18*f4ee7fbaSAndroid Build Coastguard Worker 
19*f4ee7fbaSAndroid Build Coastguard Worker static const double kMinUTF8Ratio = 0.75;
20*f4ee7fbaSAndroid Build Coastguard Worker 
21*f4ee7fbaSAndroid Build Coastguard Worker /* Returns 1 if at least min_fraction of the bytes between pos and
22*f4ee7fbaSAndroid Build Coastguard Worker    pos + length in the (data, mask) ring-buffer is UTF8-encoded, otherwise
23*f4ee7fbaSAndroid Build Coastguard Worker    returns 0. */
24*f4ee7fbaSAndroid Build Coastguard Worker BROTLI_INTERNAL BROTLI_BOOL BrotliIsMostlyUTF8(
25*f4ee7fbaSAndroid Build Coastguard Worker     const uint8_t* data, const size_t pos, const size_t mask,
26*f4ee7fbaSAndroid Build Coastguard Worker     const size_t length, const double min_fraction);
27*f4ee7fbaSAndroid Build Coastguard Worker 
28*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
29*f4ee7fbaSAndroid Build Coastguard Worker }  /* extern "C" */
30*f4ee7fbaSAndroid Build Coastguard Worker #endif
31*f4ee7fbaSAndroid Build Coastguard Worker 
32*f4ee7fbaSAndroid Build Coastguard Worker #endif  /* BROTLI_ENC_UTF8_UTIL_H_ */
33