|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +/* Fluent Bit |
| 4 | + * ========== |
| 5 | + * Copyright (C) 2015-2024 The Fluent Bit Authors |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef FLB_UNICODE |
| 21 | +#define FLB_UNICODE |
| 22 | + |
| 23 | +#include <stddef.h> |
| 24 | + |
| 25 | +#ifdef FLB_HAVE_UNICODE_ENCODER |
| 26 | +#include <fluent-bit/simdutf/flb_simdutf_connector.h> |
| 27 | + |
| 28 | +#define FLB_UNICODE_CONVERT_OK FLB_SIMDUTF_CONNECTOR_CONVERT_OK |
| 29 | +#define FLB_UNICODE_CONVERT_NOP FLB_SIMDUTF_CONNECTOR_CONVERT_NOP |
| 30 | +#define FLB_UNICODE_CONVERT_UNSUPPORTED FLB_SIMDUTF_CONNECTOR_CONVERT_UNSUPPORTED |
| 31 | +#define FLB_UNICODE_CONVERT_ERROR FLB_SIMDUTF_CONNECTOR_CONVERT_ERROR |
| 32 | + |
| 33 | +enum flb_unicode_endocing_type { |
| 34 | + FLB_UNICODE_ENCODING_UTF8 = FLB_SIMDUTF_ENCODING_TYPE_UTF8, /* BOM 0xef 0xbb 0xbf */ |
| 35 | + FLB_UNICODE_ENCODING_UTF16_LE = FLB_SIMDUTF_ENCODING_TYPE_UTF16_LE, /* BOM 0xff 0xfe */ |
| 36 | + FLB_UNICODE_ENCODING_UTF16_BE = FLB_SIMDUTF_ENCODING_TYPE_UTF16_BE, /* BOM 0xfe 0xff */ |
| 37 | + FLB_UNICODE_ENCODING_UTF32_LE = FLB_SIMDUTF_ENCODING_TYPE_UTF32_LE, /* BOM 0xff 0xfe 0x00 0x00 */ |
| 38 | + FLB_UNICODE_ENCODING_UTF32_BE = FLB_SIMDUTF_ENCODING_TYPE_UTF32_BE, /* BOM 0x00 0x00 0xfe 0xff */ |
| 39 | + FLB_UNICODE_ENCODING_Latin1 = FLB_SIMDUTF_ENCODING_TYPE_Latin1, |
| 40 | + |
| 41 | + FLB_UNICODE_ENCODING_UNSPECIFIED = FLB_SIMDUTF_ENCODING_TYPE_UNSPECIFIED, |
| 42 | + FLB_UNICODE_ENCODING_AUTO = FLB_SIMDUTF_ENCODING_TYPE_UNICODE_AUTO, /* Automatically detecting flag*/ |
| 43 | +}; |
| 44 | + |
| 45 | +#else |
| 46 | + |
| 47 | +#define FLB_UNICODE_CONVERT_OK 0 |
| 48 | +#define FLB_UNICODE_CONVERT_UNSUPPORTED -2 |
| 49 | + |
| 50 | +#endif |
| 51 | + |
| 52 | +/* Mainly converting from UTF-16LE/BE to UTF-8 */ |
| 53 | +int flb_unicode_convert(int preferred_encoding, const char *input, size_t length, |
| 54 | + char **output, size_t *out_size); |
| 55 | +int flb_unicode_validate(const char *record, size_t size); |
| 56 | + |
| 57 | +#endif |
0 commit comments