Switch away from 'bool' type (ABI change)

This type doesn't bring anything over an int and requires some special
handling (e.g. including the right headers). Just drop it and use int, C
programmers will understand!
This commit is contained in:
Laurence Withers 2009-10-13 11:01:40 +00:00
parent 1f62468379
commit dc60dcb2e6
8 changed files with 28 additions and 39 deletions

View File

@ -8,9 +8,8 @@
#ifndef HEADER_LIBUTF8 #ifndef HEADER_LIBUTF8
#define HEADER_LIBUTF8 #define HEADER_LIBUTF8
// standard includes, or includes needed for type declarations /* standard includes, or includes needed for type declarations */
#include <stdbool.h> #include <wchar.h>
#include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -1,20 +0,0 @@
/* libutf8/src/libutf8/010_forward.h
*
* (c)2006-2009, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv3. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
// This file simply contains forward declarations of all libutf8
// classes, to facilitate header ordering, etc.
// encode_state.h
struct utf8_encode_state;
// decode_state.h
struct utf8_decode_state;
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4:syntax=c.doxygen
*/

View File

@ -5,7 +5,7 @@
* http://www.gnu.org/copyleft/gpl.html for details. * http://www.gnu.org/copyleft/gpl.html for details.
*/ */
bool utf8_isascii(wchar_t ch) int utf8_isascii(wchar_t ch)
{ {
return !(ch & ~0x7F); return !(ch & ~0x7F);
} }
@ -28,7 +28,7 @@ bool utf8_isascii(wchar_t ch)
3000 ; White_Space # Zs IDEOGRAPHIC SPACE 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
*/ */
bool utf8_isspace(wchar_t ch) int utf8_isspace(wchar_t ch)
{ {
return((ch >= 0x0009 && ch <= 0x000D) return((ch >= 0x0009 && ch <= 0x000D)
|| ch == 0x0020 || ch == 0x0020
@ -46,7 +46,7 @@ bool utf8_isspace(wchar_t ch)
bool utf8_isvalid(wchar_t ch) int utf8_isvalid(wchar_t ch)
{ {
return !(ch & (~((wchar_t)0x7FFFFFFF))) && (ch < 0xD800 || ch > 0xDFFF) && (ch != 0xFFFE) && (ch != 0xFFFF); return !(ch & (~((wchar_t)0x7FFFFFFF))) && (ch < 0xD800 || ch > 0xDFFF) && (ch != 0xFFFE) && (ch != 0xFFFF);
} }

View File

@ -18,11 +18,11 @@ This module contains functions for character classification. These are basically
/// Returns \c true if \a ch can be represented in ASCII. /*! \biref Returns \c true if \a ch can be represented in ASCII. */
bool utf8_isascii(wchar_t ch); int utf8_isascii(wchar_t ch);
/// Returns \c true if \a ch is whitespace. /*! \brief Returns \c true if \a ch is whitespace. */
bool utf8_isspace(wchar_t ch); int utf8_isspace(wchar_t ch);
/*! \brief Returns \c true if \a ch is a valid UCS-4 character. /*! \brief Returns \c true if \a ch is a valid UCS-4 character.
@ -36,7 +36,7 @@ character. Valid characters lie in the range 0&ndash;0x7FFFFFFF but exclude:
\li the invalid code points U+FFFE and U+FFFF \li the invalid code points U+FFFE and U+FFFF
*/ */
bool utf8_isvalid(wchar_t ch); int utf8_isvalid(wchar_t ch);

View File

@ -42,7 +42,7 @@ loop:
case utf8_state_none: case utf8_state_none:
if(!in && ctx->rd_remain < 0) { if(!in && ctx->rd_remain < 0) {
*wr = 0; *wr = 0;
ctx->complete = true; ctx->complete = 1;
++ctx->byte_offset; ++ctx->byte_offset;
return ctx; return ctx;
} }
@ -51,7 +51,7 @@ loop:
++ctx->written; ++ctx->written;
--avail; --avail;
++ctx->char_offset; ++ctx->char_offset;
ctx->complete = true; ctx->complete = 1;
if(in == 0x0A) { if(in == 0x0A) {
++ctx->line; ++ctx->line;
ctx->col = 0; ctx->col = 0;
@ -61,7 +61,7 @@ loop:
ctx->state = utf8_state_none; ctx->state = utf8_state_none;
break; break;
} }
ctx->complete = false; ctx->complete = 0;
if((in & 0xE0) == 0xC0) { if((in & 0xE0) == 0xC0) {
ctx->minch = 0x80; ctx->minch = 0x80;
ctx->state = utf8_state_multibyte1; ctx->state = utf8_state_multibyte1;
@ -118,7 +118,7 @@ loop:
++ctx->written; ++ctx->written;
--avail; --avail;
++ctx->char_offset; ++ctx->char_offset;
ctx->complete = true; ctx->complete = 1;
if(ctx->statech == 0x0A || ctx->statech == 0x2028) { if(ctx->statech == 0x0A || ctx->statech == 0x2028) {
++ctx->line; ++ctx->line;
ctx->col = 0; ctx->col = 0;

View File

@ -20,6 +20,11 @@ character, or simply skipping the illegal byte sequence.
/* opaque type */
struct utf8_decode_state;
/*! \brief Types of decoder error. /*! \brief Types of decoder error.
These are the types of error that can be encountered by the decoder. This allows slightly more These are the types of error that can be encountered by the decoder. This allows slightly more
@ -114,7 +119,7 @@ these variables aren't perfect, as they can be affected by errors and limitation
*/ */
struct utf8_decode_state { struct utf8_decode_state {
/// \c false if we are part-way through a multi-byte character. /// \c false if we are part-way through a multi-byte character.
bool complete; int complete;
/// Data to read (current read position). /// Data to read (current read position).
const char* rd; const char* rd;

View File

@ -11,7 +11,7 @@ struct utf8_encode_state* utf8_encoder(struct utf8_encode_state* state)
char* endp = wr + state->wr_size - 1; char* endp = wr + state->wr_size - 1;
wchar_t ch; wchar_t ch;
enum utf8_encode_error_action error_action; enum utf8_encode_error_action error_action;
bool reencoding; int reencoding;
if(!state || !state->rd || !state->wr || state->wr_size < 7) { if(!state || !state->rd || !state->wr || state->wr_size < 7) {
errno = EINVAL; errno = EINVAL;
@ -23,7 +23,7 @@ struct utf8_encode_state* utf8_encoder(struct utf8_encode_state* state)
ch = *state->rd; ch = *state->rd;
if(!ch && state->rd_remain < 0) break; if(!ch && state->rd_remain < 0) break;
reencoding = false; reencoding = 0;
reencode: reencode:
ret = utf8_encode_char(wr, endp - wr, ch); ret = utf8_encode_char(wr, endp - wr, ch);
if(!ret) { if(!ret) {
@ -39,7 +39,7 @@ struct utf8_encode_state* utf8_encoder(struct utf8_encode_state* state)
return 0; return 0;
case utf8_encode_error_action_replace: case utf8_encode_error_action_replace:
reencoding = true; reencoding = 1;
goto reencode; goto reencode;
case utf8_encode_error_action_skip: case utf8_encode_error_action_skip:

View File

@ -21,6 +21,11 @@ character.
/* opaque type */
struct utf8_encode_state;
/*! \brief Action to be taken after error callback. /*! \brief Action to be taken after error callback.
These are the possible actions that can be undertaken after a stateful encoding operation has These are the possible actions that can be undertaken after a stateful encoding operation has