Lely core libraries 2.3.4
lex.c File Reference

This file is part of the utilities library; it contains the implementation of the lexer functions. More...

#include "util.h"
#include <lely/libc/string.h>
#include <lely/libc/uchar.h>
#include <lely/util/diag.h>
#include <lely/util/lex.h>
#include <lely/util/print.h>
#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <stdlib.h>
Include dependency graph for lex.c:

Go to the source code of this file.

Functions

size_t lex_char (int c, const char *begin, const char *end, struct floc *at)
 Lexes the specified character from a memory buffer. More...
 
size_t lex_ctype (int(*ctype)(int), const char *begin, const char *end, struct floc *at)
 Greedily lexes a sequence of characters of the specified class from a memory buffer. More...
 
size_t lex_break (const char *begin, const char *end, struct floc *at)
 Lexes a single line break from a memory buffer. More...
 
size_t lex_utf8 (const char *begin, const char *end, struct floc *at, char32_t *pc32)
 Lexes a UTF-8 encoded Unicode character from a memory buffer. More...
 
size_t lex_c99_id (const char *begin, const char *end, struct floc *at, char *s, size_t *pn)
 Lexes a C99 identifier from a memory buffer. More...
 
size_t lex_c99_esc (const char *begin, const char *end, struct floc *at, char32_t *pc32)
 Lexes a C99 character escape sequence from a memory buffer if the buffer begins with '\', and a UTF-8 encoded Unicode character if not. More...
 
size_t lex_c99_str (const char *begin, const char *end, struct floc *at, char *s, size_t *pn)
 Lexes a UTF-8 encoded Unicode string from a memory buffer. More...
 
size_t lex_c99_pp_num (const char *begin, const char *end, struct floc *at)
 Lexes a C99 preprocessing number from a memory buffer. More...
 
size_t lex_c99_long (const char *begin, const char *end, struct floc *at, long *pl)
 Lexes a C99 long from a memory buffer. More...
 
size_t lex_c99_ulong (const char *begin, const char *end, struct floc *at, unsigned long *pul)
 Lexes a C99 unsigned long from a memory buffer. More...
 
size_t lex_c99_llong (const char *begin, const char *end, struct floc *at, long long *pll)
 Lexes a C99 long long from a memory buffer. More...
 
size_t lex_c99_ullong (const char *begin, const char *end, struct floc *at, unsigned long long *pull)
 Lexes a C99 unsigned long long from a memory buffer. More...
 
size_t lex_c99_flt (const char *begin, const char *end, struct floc *at, float *pf)
 Lexes a C99 float from a memory buffer. More...
 
size_t lex_c99_dbl (const char *begin, const char *end, struct floc *at, double *pd)
 Lexes a C99 double from a memory buffer. More...
 
size_t lex_c99_ldbl (const char *begin, const char *end, struct floc *at, long double *pld)
 Lexes a C99 long double from a memory buffer. More...
 
size_t lex_c99_i8 (const char *begin, const char *end, struct floc *at, int_least8_t *pi8)
 Lexes a C99 int_least8_t from a memory buffer. More...
 
size_t lex_c99_i16 (const char *begin, const char *end, struct floc *at, int_least16_t *pi16)
 Lexes a C99 int_least16_t from a memory buffer. More...
 
size_t lex_c99_i32 (const char *begin, const char *end, struct floc *at, int_least32_t *pi32)
 Lexes a C99 int_least32_t from a memory buffer. More...
 
size_t lex_c99_i64 (const char *begin, const char *end, struct floc *at, int_least64_t *pi64)
 Lexes a C99 int_least64_t from a memory buffer. More...
 
size_t lex_c99_u8 (const char *begin, const char *end, struct floc *at, uint_least8_t *pu8)
 Lexes a C99 uint_least8_t from a memory buffer. More...
 
size_t lex_c99_u16 (const char *begin, const char *end, struct floc *at, uint_least16_t *pu16)
 Lexes a C99 uint_least16_t from a memory buffer. More...
 
size_t lex_c99_u32 (const char *begin, const char *end, struct floc *at, uint_least32_t *pu32)
 Lexes a C99 uint_least32_t from a memory buffer. More...
 
size_t lex_c99_u64 (const char *begin, const char *end, struct floc *at, uint_least64_t *pu64)
 Lexes a C99 uint_least64_t from a memory buffer. More...
 
size_t lex_line_comment (const char *delim, const char *begin, const char *end, struct floc *at)
 Lexes a single line-comment (excluding the line break) starting with the specified delimiter from a memory buffer. More...
 
size_t lex_hex (const char *begin, const char *end, struct floc *at, void *ptr, size_t *pn)
 Lexes and decodes the hexadecimal representation of binary data from a memory buffer. More...
 
size_t lex_base64 (const char *begin, const char *end, struct floc *at, void *ptr, size_t *pn)
 Lexes and decodes the Base64 representation of binary data from a memory buffer. More...
 

Detailed Description

This file is part of the utilities library; it contains the implementation of the lexer functions.

See also
lely/util/lex.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file lex.c.

Function Documentation

◆ lex_char()

size_t lex_char ( int  c,
const char *  begin,
const char *  end,
struct floc at 
)

Lexes the specified character from a memory buffer.

Parameters
cthe character to match.
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
Returns
the number of characters read (at most one).

Definition at line 41 of file lex.c.

◆ lex_ctype()

size_t lex_ctype ( int(*)(int)  ctype,
const char *  begin,
const char *  end,
struct floc at 
)

Greedily lexes a sequence of characters of the specified class from a memory buffer.

Parameters
ctypea pointer to a function returning a non-zero value if its argument is part of the character class.
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
Returns
the number of characters read.

Definition at line 54 of file lex.c.

◆ lex_break()

size_t lex_break ( const char *  begin,
const char *  end,
struct floc at 
)

Lexes a single line break from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
Returns
the number of characters read (at most two).

Definition at line 69 of file lex.c.

◆ lex_utf8()

size_t lex_utf8 ( const char *  begin,
const char *  end,
struct floc at,
char32_t *  pc32 
)

Lexes a UTF-8 encoded Unicode character from a memory buffer.

Illegal Unicode code points are replaced with the replacement character (U+FFFD).

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pc32the address at which to store the Unicode character. On success, if pc32 is not NULL, *pc32 contains the UTF-32 encoded character. On error, *pc32 is left untouched.
Returns
the number of characters read (at least 1 if begin < end).
See also
lex_c99_esc()

Definition at line 86 of file lex.c.

◆ lex_c99_id()

size_t lex_c99_id ( const char *  begin,
const char *  end,
struct floc at,
char *  s,
size_t *  pn 
)

Lexes a C99 identifier from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
sthe address at which to store the identifier (can be NULL).
pnthe address of a value containing the size (in bytes) of the buffer at s. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at s been sufficiently large.
Returns
the number of characters read.

Definition at line 162 of file lex.c.

◆ lex_c99_esc()

size_t lex_c99_esc ( const char *  begin,
const char *  end,
struct floc at,
char32_t *  pc32 
)

Lexes a C99 character escape sequence from a memory buffer if the buffer begins with '\', and a UTF-8 encoded Unicode character if not.

If the escape sequence is invalid, the initial '\' is returned as is.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pc32the address at which to store the converted escape sequence or Unicode character. On success, if pc32 is not NULL, *pc32 contains the UTF-32 encoded character. On error, *pc32 is left untouched.
Returns
the number of characters read (at least 1 if begin < end).
See also
lex_utf8()

Definition at line 187 of file lex.c.

◆ lex_c99_str()

size_t lex_c99_str ( const char *  begin,
const char *  end,
struct floc at,
char *  s,
size_t *  pn 
)

Lexes a UTF-8 encoded Unicode string from a memory buffer.

The string MAY contain C99 character escape sequences. Strings are terminated by a null byte, an unescaped double-quote or a newline character.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
sthe address at which to store the string (can be NULL).
pnthe address of a value containing the size (in bytes) of the buffer at s. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at s been sufficiently large.
Returns
the number of characters read (excluding the termination character).
See also
lex_c99_esc()

Definition at line 250 of file lex.c.

◆ lex_c99_pp_num()

size_t lex_c99_pp_num ( const char *  begin,
const char *  end,
struct floc at 
)

Lexes a C99 preprocessing number from a memory buffer.

Note that this does not necessarily correspond to a valid integer or floating-point constant.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
Returns
the number of characters read.

Definition at line 288 of file lex.c.

◆ lex_c99_long()

size_t lex_c99_long ( const char *  begin,
const char *  end,
struct floc at,
long *  pl 
)

Lexes a C99 long from a memory buffer.

The actual conversion is performed by strtol ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
plthe address at which to store the value. On success, if pl is not NULL, * pl contains the lexed value. On error, * pl is left untouched. On underflow/overflow, * pl contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 407 of file lex.c.

◆ lex_c99_ulong()

size_t lex_c99_ulong ( const char *  begin,
const char *  end,
struct floc at,
unsigned long *  pul 
)

Lexes a C99 unsigned long from a memory buffer.

The actual conversion is performed by strtoul ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pulthe address at which to store the value. On success, if pul is not NULL, * pul contains the lexed value. On error, * pul is left untouched. On underflow/overflow, * pul contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 409 of file lex.c.

◆ lex_c99_llong()

size_t lex_c99_llong ( const char *  begin,
const char *  end,
struct floc at,
long long *  pll 
)

Lexes a C99 long long from a memory buffer.

The actual conversion is performed by strtoll ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pllthe address at which to store the value. On success, if pll is not NULL, * pll contains the lexed value. On error, * pll is left untouched. On underflow/overflow, * pll contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 411 of file lex.c.

◆ lex_c99_ullong()

size_t lex_c99_ullong ( const char *  begin,
const char *  end,
struct floc at,
unsigned long long *  pul 
)

Lexes a C99 unsigned long long from a memory buffer.

The actual conversion is performed by strtoull ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pulthe address at which to store the value. On success, if pul is not NULL, * pul contains the lexed value. On error, * pul is left untouched. On underflow/overflow, * pul contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 414 of file lex.c.

◆ lex_c99_flt()

size_t lex_c99_flt ( const char *  begin,
const char *  end,
struct floc at,
float *  pf 
)

Lexes a C99 float from a memory buffer.

The actual conversion is performed by strtof ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pfthe address at which to store the value. On success, if pf is not NULL, * pf contains the lexed value. On error, * pf is left untouched. On underflow/overflow, * pf contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 415 of file lex.c.

◆ lex_c99_dbl()

size_t lex_c99_dbl ( const char *  begin,
const char *  end,
struct floc at,
double *  pd 
)

Lexes a C99 double from a memory buffer.

The actual conversion is performed by strtod ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pdthe address at which to store the value. On success, if pd is not NULL, * pd contains the lexed value. On error, * pd is left untouched. On underflow/overflow, * pd contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 416 of file lex.c.

◆ lex_c99_ldbl()

size_t lex_c99_ldbl ( const char *  begin,
const char *  end,
struct floc at,
long double *  pld 
)

Lexes a C99 long double from a memory buffer.

The actual conversion is performed by strtold ().

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pldthe address at which to store the value. On success, if pld is not NULL, * pld contains the lexed value. On error, * pld is left untouched. On underflow/overflow, * pld contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 418 of file lex.c.

◆ lex_c99_i8()

size_t lex_c99_i8 ( const char *  begin,
const char *  end,
struct floc at,
int_least8_t *  pi8 
)

Lexes a C99 int_least8_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pi8the address at which to store the value. On success, if pi8 is not NULL, * pi8 contains the lexed value. On error, * pi8 is left untouched. On underflow/overflow, * pi8 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 424 of file lex.c.

◆ lex_c99_i16()

size_t lex_c99_i16 ( const char *  begin,
const char *  end,
struct floc at,
int_least16_t *  pi16 
)

Lexes a C99 int_least16_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pi16the address at which to store the value. On success, if pi16 is not NULL, * pi16 contains the lexed value. On error, * pi16 is left untouched. On underflow/overflow, * pi16 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 448 of file lex.c.

◆ lex_c99_i32()

size_t lex_c99_i32 ( const char *  begin,
const char *  end,
struct floc at,
int_least32_t *  pi32 
)

Lexes a C99 int_least32_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pi32the address at which to store the value. On success, if pi32 is not NULL, * pi32 contains the lexed value. On error, * pi32 is left untouched. On underflow/overflow, * pi32 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 472 of file lex.c.

◆ lex_c99_i64()

size_t lex_c99_i64 ( const char *  begin,
const char *  end,
struct floc at,
int_least64_t *  pi64 
)

Lexes a C99 int_least64_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pi64the address at which to store the value. On success, if pi64 is not NULL, * pi64 contains the lexed value. On error, * pi64 is left untouched. On underflow/overflow, * pi64 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 504 of file lex.c.

◆ lex_c99_u8()

size_t lex_c99_u8 ( const char *  begin,
const char *  end,
struct floc at,
uint_least8_t *  pu8 
)

Lexes a C99 uint_least8_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pu8the address at which to store the value. On success, if pu8 is not NULL, * pu8 contains the lexed value. On error, * pu8 is left untouched. On underflow/overflow, * pu8 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 543 of file lex.c.

◆ lex_c99_u16()

size_t lex_c99_u16 ( const char *  begin,
const char *  end,
struct floc at,
uint_least16_t *  pu16 
)

Lexes a C99 uint_least16_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pu16the address at which to store the value. On success, if pu16 is not NULL, * pu16 contains the lexed value. On error, * pu16 is left untouched. On underflow/overflow, * pu16 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 562 of file lex.c.

◆ lex_c99_u32()

size_t lex_c99_u32 ( const char *  begin,
const char *  end,
struct floc at,
uint_least32_t *  pu32 
)

Lexes a C99 uint_least32_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pu32the address at which to store the value. On success, if pu32 is not NULL, * pu32 contains the lexed value. On error, * pu32 is left untouched. On underflow/overflow, * pu32 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 581 of file lex.c.

◆ lex_c99_u64()

size_t lex_c99_u64 ( const char *  begin,
const char *  end,
struct floc at,
uint_least64_t *  pu64 
)

Lexes a C99 uint_least64_t from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
pu64the address at which to store the value. On success, if pu64 is not NULL, * pu64 contains the lexed value. On error, * pu64 is left untouched. On underflow/overflow, * pu64 contains the minimum/maximum value and get_errnum() returns ERRNUM_RANGE.
Returns
the number of characters read.

Definition at line 604 of file lex.c.

◆ lex_line_comment()

size_t lex_line_comment ( const char *  delim,
const char *  begin,
const char *  end,
struct floc at 
)

Lexes a single line-comment (excluding the line break) starting with the specified delimiter from a memory buffer.

Parameters
delima pointer to the delimiter indicating the start of a comment (can be NULL or pointing to the empty string to lex a line unconditionally).
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
Returns
the number of characters read.

Definition at line 633 of file lex.c.

◆ lex_hex()

size_t lex_hex ( const char *  begin,
const char *  end,
struct floc at,
void *  ptr,
size_t *  pn 
)

Lexes and decodes the hexadecimal representation of binary data from a memory buffer.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
ptrthe address at which to store the decoded binary data (can be NULL).
pnthe address of a value containing the size of the buffer at *ptr. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at ptr been sufficiently large.
Returns
the number of characters read.

Definition at line 655 of file lex.c.

◆ lex_base64()

size_t lex_base64 ( const char *  begin,
const char *  end,
struct floc at,
void *  ptr,
size_t *  pn 
)

Lexes and decodes the Base64 representation of binary data from a memory buffer.

This function implements the MIME variant of Base64 as specified in RFC 2045. Since this variant instructs implementations to ignore invalid characters, this function will lex the entire input.

Parameters
begina pointer to the start of the buffer.
enda pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL, *at points to one past the last character lexed. On error, *at is left untouched.
ptrthe address at which to store the decoded binary data (can be NULL).
pnthe address of a value containing the size of the buffer at *ptr. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at ptr been sufficiently large.
Returns
the number of characters read.

Definition at line 685 of file lex.c.