syncfiles/convert/convert.h

82 lines
2.4 KiB
C
Raw Normal View History

2022-03-22 23:05:13 +00:00
#ifndef convert_h
#define convert_h
/* convert.h - character set conversion routines. */
2022-03-25 05:45:55 +00:00
#include "lib/defs.h"
enum
{
/* Constants for CR and LF. Note that we should not use '\n' or '\r'
anywhere, because these character constants may have unexpected values on
certain old Mac OS compilers, depending on the compiler settings. In
particular, the values of '\n' and '\r' will be swapped. */
kCharLF = 10,
kCharCR = 13,
/* Constant for substitution character: '?'. */
kCharSubstitute = 63
};
typedef enum
{
/* Don't translite line breaks. */
kLineBreakKeep,
/* Convert line breaks to LF. */
kLineBreakLF,
/* Convert line breaks to CR. */
kLineBreakCR,
/* Convert line breaks to CR LF. */
kLineBreakCRLF
} LineBreakConversion;
/* Directions that the converter runs in. */
typedef enum
{
kToUTF8,
kFromUTF8
} ConvertDirection;
2022-03-22 23:05:13 +00:00
/* Get the character map used for the given Mac OS script and region codes.
Return -1 if no known character map exists. */
int GetCharmap(int script, int region);
/* The state of a converter. Must be zeroed prior to first conversion. */
struct ConverterState {
UInt32 data;
};
/* Implementation function for building a converter. */
typedef ErrorCode (*ConvertBuildf)(Handle *out, Handle data, Size datasz);
/* Implementation function for running a converter. */
typedef void (*ConvertRunf)(const void *cvtptr, LineBreakConversion lc,
struct ConverterState *stateptr, UInt8 **optr,
UInt8 *oend, const UInt8 **iptr, const UInt8 *iend);
/* A converter. The converter can be freed by disposing the handle. */
struct Converter {
Handle data;
ConvertRunf run;
};
/* Build a converter from the given conversion table data. */
int ConverterBuild(struct Converter *c, Handle data, Size datasz,
ConvertDirection direction);
/* Engine 1: extended ASCII */
ErrorCode Convert1fBuild(Handle *out, Handle data, Size datasz);
void Convert1fRun(const void *cvtptr, LineBreakConversion lc,
struct ConverterState *stateptr, UInt8 **optr, UInt8 *oend,
const UInt8 **iptr, const UInt8 *iend);
ErrorCode Convert1rBuild(Handle *out, Handle data, Size datasz);
void Convert1rRun(const void *cvtptr, LineBreakConversion lc,
struct ConverterState *stateptr, UInt8 **optr, UInt8 *oend,
const UInt8 **iptr, const UInt8 *iend);
2022-03-22 23:05:13 +00:00
#endif