2016-09-28 14:40:37 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2018-02-07 14:13:13 +00:00
|
|
|
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
|
2016-09-28 14:40:37 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HCL_UTL_H_
|
|
|
|
#define _HCL_UTL_H_
|
|
|
|
|
|
|
|
#include "hcl-cmn.h"
|
|
|
|
|
2018-02-05 10:43:25 +00:00
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------
|
|
|
|
* DOUBLY LINKED LIST MACROS
|
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
#define HCL_APPEND_TO_LIST(list, node) do { \
|
|
|
|
(node)->next = HCL_NULL; \
|
|
|
|
(node)->prev = (list)->last; \
|
|
|
|
if ((list)->first) (list)->last->next = (node); \
|
|
|
|
else (list)->first = (node); \
|
|
|
|
(list)->last = (node); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HCL_PREPPEND_TO_LIST(list, node) do { \
|
|
|
|
(node)->prev = HCL_NULL; \
|
|
|
|
(node)->next = (list)->first; \
|
|
|
|
if ((list)->last) (list)->first->prev = (node); \
|
|
|
|
else (list)->last = (node); \
|
|
|
|
(list)->first = (node); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HCL_DELETE_FROM_LIST(list, node) do { \
|
|
|
|
if ((node)->prev) (node)->prev->next = (node)->next; \
|
|
|
|
else (list)->first = (node)->next; \
|
|
|
|
if ((node)->next) (node)->next->prev = (node)->prev; \
|
|
|
|
else (list)->last = (node)->prev; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define HCL_APPEND_TO_OOP_LIST(hcl, list, node_type, node, _link) do { \
|
|
|
|
(node)->_link.next = (node_type)(hcl)->_nil; \
|
2018-04-10 13:57:17 +00:00
|
|
|
(node)->_link.prev = (extern "C" {list)->last; \
|
2018-02-05 10:43:25 +00:00
|
|
|
if ((hcl_oop_t)(list)->last != (hcl)->_nil) (list)->last->_link.next = (node); \
|
|
|
|
else (list)->first = (node); \
|
|
|
|
(list)->last = (node); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HCL_PREPPEND_TO_OOP_LIST(hcl, list, node_type, node, _link) do { \
|
|
|
|
(node)->_link.prev = (node_type)(hcl)->_nil; \
|
|
|
|
(node)->_link.next = (list)->first; \
|
|
|
|
if ((hcl_oop_t)(list)->first != (hcl)->_nil) (list)->first->_link.prev = (node); \
|
|
|
|
else (list)->last = (node); \
|
|
|
|
(list)->first = (node); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HCL_DELETE_FROM_OOP_LIST(hcl, list, node, _link) do { \
|
|
|
|
if ((hcl_oop_t)(node)->_link.prev != (hcl)->_nil) (node)->_link.prev->_link.next = (node)->_link.next; \
|
|
|
|
else (list)->first = (node)->_link.next; \
|
|
|
|
if ((hcl_oop_t)(node)->_link.next != (hcl)->_nil) (node)->_link.next->_link.prev = (node)->_link.prev; \
|
|
|
|
else (list)->last = (node)->_link.prev; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define HCL_CLEANUP_FROM_OOP_LIST(hcl, list, node, _link) do { \
|
|
|
|
HCL_DELETE_FROM_OOP_LIST (hcl, list, node, _link); \
|
|
|
|
(node)->_link.prev = (node_type)(hcl)->_nil; \
|
|
|
|
(node)->_link.next = (node_type)(hcl)->_nil; \
|
|
|
|
} while(0);
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define HCL_CONST_SWAP16(x) \
|
|
|
|
((qse_uint16_t)((((qse_uint16_t)(x) & (qse_uint16_t)0x00ffU) << 8) | \
|
|
|
|
(((qse_uint16_t)(x) & (qse_uint16_t)0xff00U) >> 8) ))
|
|
|
|
|
|
|
|
#define HCL_CONST_SWAP32(x) \
|
|
|
|
((qse_uint32_t)((((qse_uint32_t)(x) & (qse_uint32_t)0x000000ffUL) << 24) | \
|
|
|
|
(((qse_uint32_t)(x) & (qse_uint32_t)0x0000ff00UL) << 8) | \
|
|
|
|
(((qse_uint32_t)(x) & (qse_uint32_t)0x00ff0000UL) >> 8) | \
|
|
|
|
(((qse_uint32_t)(x) & (qse_uint32_t)0xff000000UL) >> 24) ))
|
|
|
|
|
|
|
|
#if defined(HCL_ENDIAN_LITTLE)
|
2018-03-22 03:42:17 +00:00
|
|
|
# define HCL_CONST_NTOH16(x) HCL_CONST_SWAP16(x)
|
|
|
|
# define HCL_CONST_HTON16(x) HCL_CONST_SWAP16(x)
|
|
|
|
# define HCL_CONST_NTOH32(x) HCL_CONST_SWAP32(x)
|
|
|
|
# define HCL_CONST_HTON32(x) HCL_CONST_SWAP32(x)
|
2018-02-05 10:43:25 +00:00
|
|
|
#elif defined(HCL_ENDIAN_BIG)
|
2018-03-22 03:42:17 +00:00
|
|
|
# define HCL_CONST_NTOH16(x) (x)
|
|
|
|
# define HCL_CONST_HTON16(x) (x)
|
|
|
|
# define HCL_CONST_NTOH32(x) (x)
|
|
|
|
# define HCL_CONST_HTON32(x) (x)
|
2018-02-05 10:43:25 +00:00
|
|
|
#else
|
2018-03-22 03:42:17 +00:00
|
|
|
# error UNKNOWN ENDIAN
|
2018-02-05 10:43:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-09-28 14:40:37 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_hash_bytes (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_oob_t* ptr,
|
|
|
|
hcl_oow_t len
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(HCL_HAVE_INLINE)
|
|
|
|
static HCL_INLINE hcl_oow_t hcl_hashbchars (const hcl_bch_t* ptr, hcl_oow_t len)
|
|
|
|
{
|
2018-04-07 15:54:16 +00:00
|
|
|
return hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_bch_t));
|
2018-02-05 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HCL_INLINE hcl_oow_t hcl_hashuchars (const hcl_uch_t* ptr, hcl_oow_t len)
|
|
|
|
{
|
2018-04-07 15:54:16 +00:00
|
|
|
return hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_uch_t));
|
2018-02-05 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HCL_INLINE hcl_oow_t hcl_hashwords (const hcl_oow_t* ptr, hcl_oow_t len)
|
|
|
|
{
|
2018-04-07 15:54:16 +00:00
|
|
|
return hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_oow_t));
|
2018-02-05 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HCL_INLINE hcl_oow_t hcl_hashhalfwords (const hcl_oohw_t* ptr, hcl_oow_t len)
|
|
|
|
{
|
2018-04-07 15:54:16 +00:00
|
|
|
return hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_oohw_t));
|
2018-02-05 10:43:25 +00:00
|
|
|
}
|
2016-09-28 14:40:37 +00:00
|
|
|
#else
|
2018-04-07 15:54:16 +00:00
|
|
|
# define hcl_hashbchars(ptr,len) hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_bch_t))
|
|
|
|
# define hcl_hashuchars(ptr,len) hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_uch_t))
|
|
|
|
# define hcl_hashwords(ptr,len) hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_oow_t))
|
|
|
|
# define hcl_hashhalfwords(ptr,len) hcl_hash_bytes((const hcl_oob_t*)ptr, len * HCL_SIZEOF(hcl_oohw_t))
|
2016-09-28 14:40:37 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-05 10:43:25 +00:00
|
|
|
#if defined(HCL_OOCH_IS_UCH)
|
|
|
|
# define hcl_hashoochars(ptr,len) hcl_hashuchars(ptr,len)
|
|
|
|
#else
|
|
|
|
# define hcl_hashoochars(ptr,len) hcl_hashbchars(ptr,len)
|
|
|
|
#endif
|
2016-09-28 14:40:37 +00:00
|
|
|
|
2018-02-05 10:43:25 +00:00
|
|
|
/**
|
2018-04-07 15:54:16 +00:00
|
|
|
* The hcl_equal_uchars() function determines equality of two strings
|
2018-02-05 10:43:25 +00:00
|
|
|
* of the same length \a len.
|
|
|
|
*/
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_equal_uchars (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* str1,
|
|
|
|
const hcl_uch_t* str2,
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_oow_t len
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_equal_bchars (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* str1,
|
|
|
|
const hcl_bch_t* str2,
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_oow_t len
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_uchars (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* str1,
|
|
|
|
hcl_oow_t len1,
|
|
|
|
const hcl_uch_t* str2,
|
|
|
|
hcl_oow_t len2
|
|
|
|
);
|
2016-09-28 14:40:37 +00:00
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_bchars (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* str1,
|
|
|
|
hcl_oow_t len1,
|
|
|
|
const hcl_bch_t* str2,
|
|
|
|
hcl_oow_t len2
|
2016-09-28 14:40:37 +00:00
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_ucstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* str1,
|
|
|
|
const hcl_uch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_bcstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_bch_t* str1,
|
|
|
|
const hcl_bch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_ucstr_bcstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* str1,
|
|
|
|
const hcl_bch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_uchars_ucstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* str1,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len,
|
|
|
|
const hcl_uch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_uchars_bcstr (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* str1,
|
|
|
|
hcl_oow_t len,
|
|
|
|
const hcl_bch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_bchars_bcstr (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* str1,
|
|
|
|
hcl_oow_t len,
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_bch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_comp_bchars_ucstr (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* str1,
|
|
|
|
hcl_oow_t len,
|
|
|
|
const hcl_uch_t* str2
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT void hcl_copy_uchars (
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_uch_t* dst,
|
|
|
|
const hcl_uch_t* src,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len
|
2016-09-28 14:40:37 +00:00
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT void hcl_copy_bchars (
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_bch_t* dst,
|
|
|
|
const hcl_bch_t* src,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len
|
2016-09-28 14:40:37 +00:00
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT void hcl_copy_bchars_to_uchars (
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_uch_t* dst,
|
|
|
|
const hcl_bch_t* src,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len
|
2016-09-28 14:40:37 +00:00
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_copy_ucstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_uch_t* dst,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len,
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* src
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_copy_bcstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
hcl_bch_t* dst,
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_oow_t len,
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_bch_t* src
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_uch_t* hcl_find_uchar (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* ptr,
|
|
|
|
hcl_oow_t len,
|
|
|
|
hcl_uch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_bch_t* hcl_find_bchar (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* ptr,
|
|
|
|
hcl_oow_t len,
|
|
|
|
hcl_bch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_uch_t* hcl_rfind_uchar (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* ptr,
|
|
|
|
hcl_oow_t len,
|
|
|
|
hcl_uch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_bch_t* hcl_rfind_bchar (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* ptr,
|
|
|
|
hcl_oow_t len,
|
|
|
|
hcl_bch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_uch_t* hcl_find_uchar_in_ucstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* ptr,
|
|
|
|
hcl_uch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_bch_t* hcl_find_bchar_in_bcstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_bch_t* ptr,
|
|
|
|
hcl_bch_t c
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_count_ucstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_uch_t* str
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_count_bcstr (
|
2016-09-28 14:40:37 +00:00
|
|
|
const hcl_bch_t* str
|
|
|
|
);
|
|
|
|
|
2018-02-05 10:43:25 +00:00
|
|
|
#if defined(HCL_OOCH_IS_UCH)
|
2018-04-07 15:54:16 +00:00
|
|
|
# define hcl_equal_oochars(str1,str2,len) hcl_equal_uchars(str1,str2,len)
|
|
|
|
# define hcl_comp_oochars(str1,len1,str2,len2) hcl_comp_uchars(str1,len1,str2,len2)
|
|
|
|
# define hcl_comp_oocstr_bcstr(str1,str2) hcl_comp_ucstr_bcstr(str1,str2)
|
|
|
|
# define hcl_comp_oochars_bcstr(str1,len1,str2) hcl_comp_uchars_bcstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oochars_ucstr(str1,len1,str2) hcl_comp_uchars_ucstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oochars_oocstr(str1,len1,str2) hcl_comp_uchars_ucstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oocstr(str1,str2) hcl_comp_ucstr(str1,str2)
|
|
|
|
# define hcl_copy_oochars(dst,src,len) hcl_copy_uchars(dst,src,len)
|
|
|
|
# define hcl_copy_bchars_to_oochars(dst,src,len) hcl_copy_bchars_to_uchars(dst,src,len)
|
|
|
|
# define hcl_copy_oocstr(dst,len,src) hcl_copy_ucstr(dst,len,src)
|
|
|
|
# define hcl_find_oochar(ptr,len,c) hcl_find_uchar(ptr,len,c)
|
|
|
|
# define hcl_rfind_oochar(ptr,len,c) hcl_rfind_uchar(ptr,len,c)
|
|
|
|
# define hcl_find_oochar_in_oocstr(ptr,c) hcl_find_uchar_in_ucstr(ptr,c)
|
|
|
|
# define hcl_count_oocstr(str) hcl_count_ucstr(str)
|
2018-02-05 10:43:25 +00:00
|
|
|
#else
|
2018-04-07 15:54:16 +00:00
|
|
|
# define hcl_equal_oochars(str1,str2,len) hcl_equal_bchars(str1,str2,len)
|
|
|
|
# define hcl_comp_oochars(str1,len1,str2,len2) hcl_comp_bchars(str1,len1,str2,len2)
|
|
|
|
# define hcl_comp_oocstr_bcstr(str1,str2) hcl_comp_bcstr(str1,str2)
|
|
|
|
# define hcl_comp_oochars_bcstr(str1,len1,str2) hcl_comp_bchars_bcstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oochars_ucstr(str1,len1,str2) hcl_comp_bchars_ucstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oochars_oocstr(str1,len1,str2) hcl_comp_bchars_bcstr(str1,len1,str2)
|
|
|
|
# define hcl_comp_oocstr(str1,str2) hcl_comp_bcstr(str1,str2)
|
|
|
|
# define hcl_copy_oochars(dst,src,len) hcl_copy_bchars(dst,src,len)
|
|
|
|
# define hcl_copy_bchars_to_oochars(dst,src,len) hcl_copy_bchars(dst,src,len)
|
|
|
|
# define hcl_copy_oocstr(dst,len,src) hcl_copy_bcstr(dst,len,src)
|
|
|
|
# define hcl_find_oochar(ptr,len,c) hcl_find_bchar(ptr,len,c)
|
|
|
|
# define hcl_rfind_oochar(ptr,len,c) hcl_rfind_bchar(ptr,len,c)
|
|
|
|
# define hcl_find_oochar_in_oocstr(ptr,c) hcl_find_bchar_in_bcstr(ptr,c)
|
|
|
|
# define hcl_count_oocstr(str) hcl_count_bcstr(str)
|
2018-02-05 10:43:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-12 16:45:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
HCL_EXPORT int hcl_conv_bcs_to_ucs_with_cmgr (
|
|
|
|
const hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_cmgr_t* cmgr,
|
|
|
|
int all
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_conv_bchars_to_uchars_with_cmgr (
|
2018-03-12 16:45:42 +00:00
|
|
|
const hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_cmgr_t* cmgr,
|
|
|
|
int all
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT int hcl_conv_ucs_to_bcs_with_cmgr (
|
|
|
|
const hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_cmgr_t* cmgr
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
HCL_EXPORT int hcl_conv_uchars_to_bchars_with_cmgr (
|
2018-03-12 16:45:42 +00:00
|
|
|
const hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_cmgr_t* cmgr
|
|
|
|
);
|
|
|
|
|
2018-04-07 15:54:16 +00:00
|
|
|
#if defined(HCL_OOCH_IS_UCH)
|
|
|
|
# define hcl_conv_oocs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hcl_conv_ucs_to_bcs_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
|
|
|
# define hcl_conv_oochars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hcl_conv_uchars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
|
|
|
#else
|
|
|
|
# define hcl_conv_oocs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hcl_conv_bcs_to_ucs_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
|
|
|
# define hcl_conv_oochars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hcl_conv_bchars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
|
|
|
#endif
|
|
|
|
|
2018-03-12 16:45:42 +00:00
|
|
|
HCL_EXPORT hcl_cmgr_t* hcl_get_utf8_cmgr (
|
2018-02-05 10:43:25 +00:00
|
|
|
void
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 16:45:42 +00:00
|
|
|
* The hcl_conv_uchars_to_utf8() function converts a unicode character string \a ucs
|
2018-02-05 10:43:25 +00:00
|
|
|
* to a UTF8 string and writes it into the buffer pointed to by \a bcs, but
|
|
|
|
* not more than \a bcslen bytes including the terminating null.
|
|
|
|
*
|
|
|
|
* Upon return, \a bcslen is modified to the actual number of bytes written to
|
|
|
|
* \a bcs excluding the terminating null; \a ucslen is modified to the number of
|
|
|
|
* wide characters converted.
|
|
|
|
*
|
|
|
|
* You may pass #HCL_NULL for \a bcs to dry-run conversion or to get the
|
|
|
|
* required buffer size for conversion. -2 is never returned in this case.
|
|
|
|
*
|
|
|
|
* \return
|
|
|
|
* - 0 on full conversion,
|
|
|
|
* - -1 on no or partial conversion for an illegal character encountered,
|
|
|
|
* - -2 on no or partial conversion for a small buffer.
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* const hcl_uch_t ucs[] = { 'H', 'e', 'l', 'l', 'o' };
|
|
|
|
* hcl_bch_t bcs[10];
|
|
|
|
* hcl_oow_t ucslen = 5;
|
|
|
|
* hcl_oow_t bcslen = HCL_COUNTOF(bcs);
|
2018-03-12 16:45:42 +00:00
|
|
|
* n = hcl_conv_uchars_to_utf8 (ucs, &ucslen, bcs, &bcslen);
|
2018-02-05 10:43:25 +00:00
|
|
|
* if (n <= -1)
|
|
|
|
* {
|
|
|
|
* // conversion error
|
|
|
|
* }
|
|
|
|
* \endcode
|
|
|
|
*/
|
2018-03-12 16:45:42 +00:00
|
|
|
HCL_EXPORT int hcl_conv_uchars_to_utf8 (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 16:45:42 +00:00
|
|
|
* The hcl_conv_utf8_to_uchars() function converts a UTF8 string to a uncide string.
|
2018-02-05 10:43:25 +00:00
|
|
|
*
|
|
|
|
* It never returns -2 if \a ucs is #HCL_NULL.
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* const hcl_bch_t* bcs = "test string";
|
|
|
|
* hcl_uch_t ucs[100];
|
|
|
|
* hcl_oow_t ucslen = HCL_COUNTOF(buf), n;
|
|
|
|
* hcl_oow_t bcslen = 11;
|
|
|
|
* int n;
|
2018-03-12 16:45:42 +00:00
|
|
|
* n = hcl_conv_utf8_to_uchars (bcs, &bcslen, ucs, &ucslen);
|
2018-02-05 10:43:25 +00:00
|
|
|
* if (n <= -1) { invalid/incomplenete sequence or buffer to small }
|
|
|
|
* \endcode
|
|
|
|
*
|
|
|
|
* The resulting \a ucslen can still be greater than 0 even if the return
|
|
|
|
* value is negative. The value indiates the number of characters converted
|
|
|
|
* before the error has occurred.
|
|
|
|
*
|
|
|
|
* \return 0 on success.
|
|
|
|
* -1 if \a bcs contains an illegal character.
|
|
|
|
* -2 if the wide-character string buffer is too small.
|
|
|
|
* -3 if \a bcs is not a complete sequence.
|
|
|
|
*/
|
2018-03-12 16:45:42 +00:00
|
|
|
HCL_EXPORT int hcl_conv_utf8_to_uchars (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-03-12 16:45:42 +00:00
|
|
|
HCL_EXPORT int hcl_conv_ucstr_to_utf8 (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen,
|
|
|
|
hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen
|
|
|
|
);
|
|
|
|
|
2018-03-12 16:45:42 +00:00
|
|
|
HCL_EXPORT int hcl_conv_utf8_to_ucstr (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* bcs,
|
|
|
|
hcl_oow_t* bcslen,
|
|
|
|
hcl_uch_t* ucs,
|
|
|
|
hcl_oow_t* ucslen
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-04-06 16:33:17 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_uc_to_utf8 (
|
2018-02-05 10:43:25 +00:00
|
|
|
hcl_uch_t uc,
|
|
|
|
hcl_bch_t* utf8,
|
|
|
|
hcl_oow_t size
|
|
|
|
);
|
|
|
|
|
2018-04-06 16:33:17 +00:00
|
|
|
HCL_EXPORT hcl_oow_t hcl_utf8_to_uc (
|
2018-02-05 10:43:25 +00:00
|
|
|
const hcl_bch_t* utf8,
|
|
|
|
hcl_oow_t size,
|
|
|
|
hcl_uch_t* uc
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT int hcl_ucwidth (
|
|
|
|
hcl_uch_t uc
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#if defined(HCL_HAVE_UINT16_T)
|
|
|
|
HCL_EXPORT hcl_uint16_t hcl_ntoh16 (
|
|
|
|
hcl_uint16_t x
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT hcl_uint16_t hcl_hton16 (
|
|
|
|
hcl_uint16_t x
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HCL_HAVE_UINT32_T)
|
|
|
|
HCL_EXPORT hcl_uint32_t hcl_ntoh32 (
|
|
|
|
hcl_uint32_t x
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT hcl_uint32_t hcl_hton32 (
|
|
|
|
hcl_uint32_t x
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HCL_HAVE_UINT64_T)
|
|
|
|
HCL_EXPORT hcl_uint64_t hcl_ntoh64 (
|
|
|
|
hcl_uint64_t x
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT hcl_uint64_t hcl_hton64 (
|
|
|
|
hcl_uint64_t x
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HCL_HAVE_UINT128_T)
|
|
|
|
HCL_EXPORT hcl_uint128_t hcl_ntoh128 (
|
|
|
|
hcl_uint128_t x
|
|
|
|
);
|
|
|
|
|
|
|
|
HCL_EXPORT hcl_uint128_t hcl_hton128 (
|
|
|
|
hcl_uint128_t x
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
2018-03-22 03:42:17 +00:00
|
|
|
|
2016-09-28 14:40:37 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|