Blame winpr/libwinpr/crt/utf.h

Packit Service fa4841
/*
Packit Service fa4841
 * Copyright 2001-2004 Unicode, Inc.
Packit Service b1ea74
 *
Packit Service fa4841
 * Disclaimer
Packit Service b1ea74
 *
Packit Service fa4841
 * This source code is provided as is by Unicode, Inc. No claims are
Packit Service fa4841
 * made as to fitness for any particular purpose. No warranties of any
Packit Service fa4841
 * kind are expressed or implied. The recipient agrees to determine
Packit Service fa4841
 * applicability of information provided. If this file has been
Packit Service fa4841
 * purchased on magnetic or optical media from Unicode, Inc., the
Packit Service fa4841
 * sole remedy for any claim will be exchange of defective media
Packit Service fa4841
 * within 90 days of receipt.
Packit Service b1ea74
 *
Packit Service fa4841
 * Limitations on Rights to Redistribute This Code
Packit Service b1ea74
 *
Packit Service fa4841
 * Unicode, Inc. hereby grants the right to freely use the information
Packit Service fa4841
 * supplied in this file in the creation of products supporting the
Packit Service fa4841
 * Unicode Standard, and to make copies of this file in any form
Packit Service fa4841
 * for internal or external distribution as long as this notice
Packit Service fa4841
 * remains attached.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
/* ---------------------------------------------------------------------
Packit Service fa4841
Packit Service fa4841
    Conversions between UTF32, UTF-16, and UTF-8.  Header file.
Packit Service fa4841
Packit Service fa4841
    Several funtions are included here, forming a complete set of
Packit Service fa4841
    conversions between the three formats.  UTF-7 is not included
Packit Service fa4841
    here, but is handled in a separate source file.
Packit Service fa4841
Packit Service fa4841
    Each of these routines takes pointers to input buffers and output
Packit Service fa4841
    buffers.  The input buffers are const.
Packit Service fa4841
Packit Service fa4841
    Each routine converts the text between *sourceStart and sourceEnd,
Packit Service fa4841
    putting the result into the buffer between *targetStart and
Packit Service b1ea74
    targetEnd. Note: the end pointers are *after* the last item: e.g.
Packit Service fa4841
    *(sourceEnd - 1) is the last item.
Packit Service fa4841
Packit Service fa4841
    The return result indicates whether the conversion was successful,
Packit Service fa4841
    and if not, whether the problem was in the source or target buffers.
Packit Service fa4841
    (Only the first encountered problem is indicated.)
Packit Service fa4841
Packit Service fa4841
    After the conversion, *sourceStart and *targetStart are both
Packit Service fa4841
    updated to point to the end of last text successfully converted in
Packit Service fa4841
    the respective buffers.
Packit Service fa4841
Packit Service fa4841
    Input parameters:
Packit Service fa4841
    sourceStart - pointer to a pointer to the source buffer.
Packit Service fa4841
        The contents of this are modified on return so that
Packit Service fa4841
        it points at the next thing to be converted.
Packit Service fa4841
    targetStart - similarly, pointer to pointer to the target buffer.
Packit Service fa4841
    sourceEnd, targetEnd - respectively pointers to the ends of the
Packit Service fa4841
        two buffers, for overflow checking only.
Packit Service fa4841
Packit Service fa4841
    These conversion functions take a ConversionFlags argument. When this
Packit Service fa4841
    flag is set to strict, both irregular sequences and isolated surrogates
Packit Service fa4841
    will cause an error.  When the flag is set to lenient, both irregular
Packit Service fa4841
    sequences and isolated surrogates are converted.
Packit Service fa4841
Packit Service fa4841
    Whether the flag is strict or lenient, all illegal sequences will cause
Packit Service fa4841
    an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
Packit Service fa4841
    or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
Packit Service fa4841
    must check for illegal sequences.
Packit Service fa4841
Packit Service fa4841
    When the flag is set to lenient, characters over 0x10FFFF are converted
Packit Service fa4841
    to the replacement character; otherwise (when the flag is set to strict)
Packit Service fa4841
    they constitute an error.
Packit Service fa4841
Packit Service fa4841
    Output parameters:
Packit Service fa4841
    The value "sourceIllegal" is returned from some routines if the input
Packit Service fa4841
    sequence is malformed.  When "sourceIllegal" is returned, the source
Packit Service fa4841
    value will point to the illegal value that caused the problem. E.g.,
Packit Service fa4841
    in UTF-8 when a sequence is malformed, it points to the start of the
Packit Service b1ea74
    malformed sequence.
Packit Service fa4841
Packit Service fa4841
    Author: Mark E. Davis, 1994.
Packit Service fa4841
    Rev History: Rick McGowan, fixes & updates May 2001.
Packit Service fa4841
         Fixes & updates, Sept 2001.
Packit Service fa4841
Packit Service fa4841
------------------------------------------------------------------------ */
Packit Service fa4841
Packit Service fa4841
#ifndef FREERDP_UNICODE_CONVERT_UTF_H
Packit Service fa4841
#define FREERDP_UNICODE_CONVERT_UTF_H
Packit Service fa4841
Packit Service fa4841
#include <winpr/wtypes.h>
Packit Service fa4841
Packit Service fa4841
/*
Packit Service fa4841
 * Character Types:
Packit Service fa4841
 *
Packit Service fa4841
 * UTF8:	BYTE		8 bits
Packit Service fa4841
 * UTF16:	WCHAR		16 bits
Packit Service fa4841
 * UTF32:	DWORD		32 bits
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
/* Some fundamental constants */
Packit Service b1ea74
#define UNI_REPLACEMENT_CHAR (DWORD)0x0000FFFD
Packit Service b1ea74
#define UNI_MAX_BMP (DWORD)0x0000FFFF
Packit Service b1ea74
#define UNI_MAX_UTF16 (DWORD)0x0010FFFF
Packit Service b1ea74
#define UNI_MAX_UTF32 (DWORD)0x7FFFFFFF
Packit Service b1ea74
#define UNI_MAX_LEGAL_UTF32 (DWORD)0x0010FFFF
Packit Service fa4841
Packit Service fa4841
typedef enum
Packit Service fa4841
{
Packit Service b1ea74
	conversionOK,    /* conversion successful */
Packit Service fa4841
	sourceExhausted, /* partial character in source, but hit end */
Packit Service fa4841
	targetExhausted, /* insuff. room in target for conversion */
Packit Service b1ea74
	sourceIllegal    /* source sequence is illegal/malformed */
Packit Service fa4841
} ConversionResult;
Packit Service fa4841
Packit Service fa4841
typedef enum
Packit Service fa4841
{
Packit Service fa4841
	strictConversion = 0,
Packit Service fa4841
	lenientConversion
Packit Service fa4841
} ConversionFlags;
Packit Service fa4841
Packit Service fa4841
/* This is for C++ and does no harm in C */
Packit Service fa4841
#ifdef __cplusplus
Packit Service b1ea74
extern "C"
Packit Service b1ea74
{
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF8toUTF16(const BYTE** sourceStart, const BYTE* sourceEnd,
Packit Service b1ea74
	                                    WCHAR** targetStart, WCHAR* targetEnd,
Packit Service b1ea74
	                                    ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF16toUTF8(const WCHAR** sourceStart, const WCHAR* sourceEnd,
Packit Service b1ea74
	                                    BYTE** targetStart, BYTE* targetEnd, ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF8toUTF32(const BYTE** sourceStart, const BYTE* sourceEnd,
Packit Service b1ea74
	                                    DWORD** targetStart, DWORD* targetEnd,
Packit Service b1ea74
	                                    ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF32toUTF8(const DWORD** sourceStart, const DWORD* sourceEnd,
Packit Service b1ea74
	                                    BYTE** targetStart, BYTE* targetEnd, ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF16toUTF32(const WCHAR** sourceStart, const WCHAR* sourceEnd,
Packit Service b1ea74
	                                     DWORD** targetStart, DWORD* targetEnd,
Packit Service b1ea74
	                                     ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	ConversionResult ConvertUTF32toUTF16(const DWORD** sourceStart, const DWORD* sourceEnd,
Packit Service b1ea74
	                                     WCHAR** targetStart, WCHAR* targetEnd,
Packit Service b1ea74
	                                     ConversionFlags flags);
Packit Service fa4841
Packit Service b1ea74
	BOOL isLegalUTF8Sequence(const BYTE* source, const BYTE* sourceEnd);
Packit Service fa4841
Packit Service fa4841
#ifdef __cplusplus
Packit Service fa4841
}
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#endif /* FREERDP_UNICODE_CONVERT_UTF_H */