Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
conv.h
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
33 #ifndef CONV_H_
34 #define CONV_H_
35 
38 
44 #define BASE64 0x8000
45 
51 #define BASE64_MASK 0xFF00
52 
58 #define TYPE_MASK 0xFF
59 
62 
64 #define BINARY 4
65 
66 #define LATIN1 4
67 
75 #define ISO_8859_1 4
76 
77 #define UTF_8 8
78 
79 #define UTF_16 16
80 
81 #define UTF_16BE 17
82 
83 #define UTF_16LE 18
84 
85 #define UTF_32 32
86 
87 #define UTF_32BE 33
88 
89 #define UTF_32LE 34
90 
93 
95 #define UTF_UNKNOWN 40
96 
97 #define BOM 1
98 
99 #define NOBOM 0
100 
101 #define BASE64_LF 10
102 
103 #define BASE64_CRLF 13
104 
109 typedef struct {
113  uint8_t* ucpData;
115 } conv_src;
116 
120 typedef struct{
123  uint8_t* ucpData;
125 } conv_dst;
126 
127 void* vpConvCtor(exception* spEx);
128 void vConvDtor(void* vpCtx);
129 void vConvDecode(void* vpCtx, conv_src* spSrc);
130 void vConvEncode(void* vpCtx, conv_dst* spDst);
131 void vConvConvert(void* vpCtx, conv_src* spSrc, conv_dst* spDst);
132 void vConvGetCodePoints(void* vpCtx, uint32_t* uipData, uint32_t* uipDataLen);
133 void vConvUseCodePoints(void* vpCtx, uint32_t* uipSrc, aint uiSrcLen);
134 void vConvConfigureBase64(void* vpCtx, aint uiLineLen, aint uiLineEnd);
135 
136 #endif /* CONV_H_ */
conv_src::uiDataType
aint uiDataType
One of the encoding type identifiers, UTF_8, etc. If or'ed (|) with BASE64, the source data stream is...
Definition: conv.h:110
vConvConvert
void vConvConvert(void *vpCtx, conv_src *spSrc, conv_dst *spDst)
Decodes and encodes in a single functions call.
Definition: conv.c:422
vpConvCtor
void * vpConvCtor(exception *spEx)
The data conversion object constructor.
Definition: conv.c:134
conv_src::ucpData
uint8_t * ucpData
Pointer to the byte stream to decode,.
Definition: conv.h:113
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
conv_dst::bBOM
abool bBOM
[in] If true(BOM) prepend a Byte Order Mark, if false(NOBOM) no Byte Order Mark prepended.
Definition: conv.h:122
conv_dst::uiDataType
aint uiDataType
[in] One of the encoding type identifiers, UTF_8, etc.
Definition: conv.h:121
vConvUseCodePoints
void vConvUseCodePoints(void *vpCtx, uint32_t *uipSrc, aint uiSrcLen)
Insert a stream of 32-bit Unicode code points as the intermediate data.
Definition: conv.c:395
conv_dst
Defines the output data type, location, length and whether or not to preface with a Byte Order Mark (...
Definition: conv.h:120
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
vConvGetCodePoints
void vConvGetCodePoints(void *vpCtx, uint32_t *uipData, uint32_t *uipDataLen)
Access the intermediate 32-bit data following a call to vConvDecode() or vConvUseCodePoints().
Definition: conv.c:361
conv_src::uiDataLen
aint uiDataLen
Number of bytes in the byte stream.
Definition: conv.h:114
vConvDecode
void vConvDecode(void *vpCtx, conv_src *spSrc)
Decode a source byte stream to 32-bit Unicode code points.
Definition: conv.c:205
vConvDtor
void vConvDtor(void *vpCtx)
Conversion object destructor.
Definition: conv.c:161
vConvEncode
void vConvEncode(void *vpCtx, conv_dst *spDst)
Encode the 32-bit Unicode code points to a byte stream.
Definition: conv.c:302
conv_dst::uiDataLen
aint uiDataLen
[out] Number of bytes in the byte stream.
Definition: conv.h:124
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
conv_src
Defines the input data type, location and length.
Definition: conv.h:109
vConvConfigureBase64
void vConvConfigureBase64(void *vpCtx, aint uiLineLen, aint uiLineEnd)
Configures base64 output format.
Definition: conv.c:186
conv_dst::ucpData
uint8_t * ucpData
[out] Pointer to the output byte stream. Valid until another function call on the context handle.
Definition: conv.h:123
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.