moved some strings functions to the m4 files

This commit is contained in:
hyung-hwan 2022-02-14 09:42:09 +00:00
parent 1a089fe8aa
commit 95c202d0e7
6 changed files with 567 additions and 421 deletions

View File

@ -254,29 +254,8 @@ enum hio_trim_oochars_flag_t
extern "C" {
#endif
HIO_EXPORT hio_oow_t hio_count_ucstr (
const hio_uch_t* str
);
HIO_EXPORT hio_oow_t hio_count_bcstr (
const hio_bch_t* str
);
/**
* The hio_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HIO_EXPORT int hio_equal_uchars (
const hio_uch_t* str1,
const hio_uch_t* str2,
hio_oow_t len
);
HIO_EXPORT int hio_equal_bchars (
const hio_bch_t* str1,
const hio_bch_t* str2,
hio_oow_t len
);
/* ------------------------------------ */
HIO_EXPORT int hio_comp_uchars (
const hio_uch_t* str1,
@ -354,76 +333,7 @@ HIO_EXPORT int hio_comp_bchars_ucstr (
int ignorecase
);
HIO_EXPORT void hio_copy_uchars (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars_to_uchars (
hio_uch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_uchars_to_bchars (
hio_bch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_ucstr (
hio_uch_t* dst,
hio_oow_t len,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr (
hio_bch_t* dst,
hio_oow_t len,
const hio_bch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
hio_uch_t* dst,
hio_oow_t dlen,
const hio_uch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
hio_bch_t* dst,
hio_oow_t dlen,
const hio_bch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT hio_oow_t hio_concat_uchars_to_ucstr (
hio_uch_t* buf,
@ -451,6 +361,110 @@ HIO_EXPORT hio_oow_t hio_concat_bcstr (
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT void hio_copy_uchars (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars_to_uchars (
hio_uch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_uchars_to_bchars (
hio_bch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
hio_uch_t* dst,
hio_oow_t dlen,
const hio_uch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
hio_bch_t* dst,
hio_oow_t dlen,
const hio_bch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_ucstr (
hio_uch_t* dst,
hio_oow_t len,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr (
hio_bch_t* dst,
hio_oow_t len,
const hio_bch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT hio_oow_t hio_count_ucstr (
const hio_uch_t* str
);
HIO_EXPORT hio_oow_t hio_count_bcstr (
const hio_bch_t* str
);
/* ------------------------------------ */
/**
* The hio_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HIO_EXPORT int hio_equal_uchars (
const hio_uch_t* str1,
const hio_uch_t* str2,
hio_oow_t len
);
HIO_EXPORT int hio_equal_bchars (
const hio_bch_t* str1,
const hio_bch_t* str2,
hio_oow_t len
);
/* ------------------------------------ */
HIO_EXPORT void hio_fill_uchars (
hio_uch_t* dst,
const hio_uch_t ch,
@ -585,7 +599,6 @@ HIO_EXPORT int hio_split_bcstr (
# define hio_rfind_oochar hio_rfind_uchar
# define hio_find_oochar_in_oocstr hio_find_uchar_in_ucstr
# define hio_rotate_oochars hio_rotate_uchars
# define hio_trim_oochars hio_trim_uchars
# define hio_split_oocstr hio_split_ucstr
#else
@ -618,7 +631,6 @@ HIO_EXPORT int hio_split_bcstr (
# define hio_rfind_oochar hio_rfind_bchar
# define hio_find_oochar_in_oocstr hio_find_bchar_in_bcstr
# define hio_rotate_oochars hio_rotate_bchars
# define hio_trim_oochars hio_trim_bchars
# define hio_split_oocstr hio_split_bcstr
#endif

View File

@ -36,6 +36,7 @@
#include <stdarg.h>
dnl ---------------------------------------------------------------------------
dnl include utl-str.m4 for c++ template functions far below
include(`utl-str.m4')
dnl ---------------------------------------------------------------------------
@ -254,29 +255,8 @@ enum hio_trim_oochars_flag_t
extern "C" {
#endif
HIO_EXPORT hio_oow_t hio_count_ucstr (
const hio_uch_t* str
);
HIO_EXPORT hio_oow_t hio_count_bcstr (
const hio_bch_t* str
);
/**
* The hio_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HIO_EXPORT int hio_equal_uchars (
const hio_uch_t* str1,
const hio_uch_t* str2,
hio_oow_t len
);
HIO_EXPORT int hio_equal_bchars (
const hio_bch_t* str1,
const hio_bch_t* str2,
hio_oow_t len
);
/* ------------------------------------ */
HIO_EXPORT int hio_comp_uchars (
const hio_uch_t* str1,
@ -354,76 +334,7 @@ HIO_EXPORT int hio_comp_bchars_ucstr (
int ignorecase
);
HIO_EXPORT void hio_copy_uchars (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars_to_uchars (
hio_uch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_uchars_to_bchars (
hio_bch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_ucstr (
hio_uch_t* dst,
hio_oow_t len,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr (
hio_bch_t* dst,
hio_oow_t len,
const hio_bch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
hio_uch_t* dst,
hio_oow_t dlen,
const hio_uch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
hio_bch_t* dst,
hio_oow_t dlen,
const hio_bch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT hio_oow_t hio_concat_uchars_to_ucstr (
hio_uch_t* buf,
@ -451,6 +362,110 @@ HIO_EXPORT hio_oow_t hio_concat_bcstr (
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT void hio_copy_uchars (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_bchars_to_uchars (
hio_uch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT void hio_copy_uchars_to_bchars (
hio_bch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
hio_uch_t* dst,
hio_oow_t dlen,
const hio_uch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
hio_bch_t* dst,
hio_oow_t dlen,
const hio_bch_t* src,
hio_oow_t slen
);
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src,
hio_oow_t len
);
HIO_EXPORT hio_oow_t hio_copy_ucstr (
hio_uch_t* dst,
hio_oow_t len,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr (
hio_bch_t* dst,
hio_oow_t len,
const hio_bch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
hio_uch_t* dst,
const hio_uch_t* src
);
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
hio_bch_t* dst,
const hio_bch_t* src
);
/* ------------------------------------ */
HIO_EXPORT hio_oow_t hio_count_ucstr (
const hio_uch_t* str
);
HIO_EXPORT hio_oow_t hio_count_bcstr (
const hio_bch_t* str
);
/* ------------------------------------ */
/**
* The hio_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HIO_EXPORT int hio_equal_uchars (
const hio_uch_t* str1,
const hio_uch_t* str2,
hio_oow_t len
);
HIO_EXPORT int hio_equal_bchars (
const hio_bch_t* str1,
const hio_bch_t* str2,
hio_oow_t len
);
/* ------------------------------------ */
HIO_EXPORT void hio_fill_uchars (
hio_uch_t* dst,
const hio_uch_t ch,

View File

@ -33,50 +33,6 @@
#include <hio-chr.h>
hio_oow_t hio_count_ucstr (const hio_uch_t* str)
{
const hio_uch_t* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
hio_oow_t hio_count_bcstr (const hio_bch_t* str)
{
const hio_bch_t* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str2, hio_oow_t len2, int ignorecase)
{
hio_uchu_t c1, c2;
@ -257,6 +213,70 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo
}
}
int hio_comp_uchars_ucstr (const hio_uch_t* str1, hio_oow_t len, const hio_uch_t* str2, int ignorecase)
{
/* for "abc\0" of length 4 vs "abc", the fourth character
* of the first string is equal to the terminating null of
* the second string. the first string is still considered
* bigger */
if (ignorecase)
{
const hio_uch_t* end = str1 + len;
hio_uch_t c1;
hio_uch_t c2;
while (str1 < end && *str2 != '\0')
{
c1 = hio_to_uch_lower(*str1);
c2 = hio_to_uch_lower(*str2);
if (c1 != c2) return ((hio_uchu_t)c1 > (hio_uchu_t)c2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
else
{
const hio_uch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
{
if (*str1 != *str2) return ((hio_uchu_t)*str1 > (hio_uchu_t)*str2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
}
int hio_comp_bchars_bcstr (const hio_bch_t* str1, hio_oow_t len, const hio_bch_t* str2, int ignorecase)
{
/* for "abc\0" of length 4 vs "abc", the fourth character
* of the first string is equal to the terminating null of
* the second string. the first string is still considered
* bigger */
if (ignorecase)
{
const hio_bch_t* end = str1 + len;
hio_bch_t c1;
hio_bch_t c2;
while (str1 < end && *str2 != '\0')
{
c1 = hio_to_bch_lower(*str1);
c2 = hio_to_bch_lower(*str2);
if (c1 != c2) return ((hio_bchu_t)c1 > (hio_bchu_t)c2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
else
{
const hio_bch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
{
if (*str1 != *str2) return ((hio_bchu_t)*str1 > (hio_bchu_t)*str2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
}
hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len)
{
hio_uch_t* p, * p2;
@ -347,6 +367,146 @@ hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str)
return p - buf;
}
void hio_copy_uchars (hio_uch_t* dst, const hio_uch_t* src, hio_oow_t len)
{
/* take note of no forced null termination */
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
}
void hio_copy_bchars (hio_bch_t* dst, const hio_bch_t* src, hio_oow_t len)
{
/* take note of no forced null termination */
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
}
hio_oow_t hio_copy_uchars_to_ucstr (hio_uch_t* dst, hio_oow_t dlen, const hio_uch_t* src, hio_oow_t slen)
{
hio_oow_t i;
if (dlen <= 0) return 0;
if (dlen <= slen) slen = dlen - 1;
for (i = 0; i < slen; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_bchars_to_bcstr (hio_bch_t* dst, hio_oow_t dlen, const hio_bch_t* src, hio_oow_t slen)
{
hio_oow_t i;
if (dlen <= 0) return 0;
if (dlen <= slen) slen = dlen - 1;
for (i = 0; i < slen; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_uchars_to_ucstr_unlimited (hio_uch_t* dst, const hio_uch_t* src, hio_oow_t len)
{
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_bchars_to_bcstr_unlimited (hio_bch_t* dst, const hio_bch_t* src, hio_oow_t len)
{
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_ucstr (hio_uch_t* dst, hio_oow_t len, const hio_uch_t* src)
{
hio_uch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
if (len > 0) *p = '\0';
return p - dst;
}
hio_oow_t hio_copy_bcstr (hio_bch_t* dst, hio_oow_t len, const hio_bch_t* src)
{
hio_bch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
if (len > 0) *p = '\0';
return p - dst;
}
hio_oow_t hio_copy_ucstr_unlimited (hio_uch_t* dst, const hio_uch_t* src)
{
hio_uch_t* org = dst;
while ((*dst++ = *src++) != '\0');
return dst - org - 1;
}
hio_oow_t hio_copy_bcstr_unlimited (hio_bch_t* dst, const hio_bch_t* src)
{
hio_bch_t* org = dst;
while ((*dst++ = *src++) != '\0');
return dst - org - 1;
}
hio_oow_t hio_count_ucstr (const hio_uch_t* str)
{
const hio_uch_t* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
hio_oow_t hio_count_bcstr (const hio_bch_t* str)
{
const hio_bch_t* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
void hio_fill_uchars (hio_uch_t* dst, hio_uch_t ch, hio_oow_t len)
{
hio_oow_t i;

View File

@ -35,12 +35,6 @@ dnl
dnl ---------------------------------------------------------------------------
include(`utl-str.m4')dnl
dnl ---------------------------------------------------------------------------
dnl
fn_count_cstr(hio_count_ucstr, hio_uch_t)
fn_count_cstr(hio_count_bcstr, hio_bch_t)
dnl --
fn_equal_chars(hio_equal_uchars, hio_uch_t)
fn_equal_chars(hio_equal_bchars, hio_bch_t)
dnl --
fn_comp_chars(hio_comp_uchars, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_chars(hio_comp_bchars, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
@ -51,12 +45,36 @@ dnl --
fn_comp_cstr_limited(hio_comp_ucstr_limited, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_cstr_limited(hio_comp_bcstr_limited, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
dnl --
fn_comp_chars_cstr(hio_comp_uchars_ucstr, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_chars_cstr(hio_comp_bchars_bcstr, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
dnl --
fn_concat_chars_to_cstr(hio_concat_uchars_to_ucstr, hio_uch_t, hio_count_ucstr)
fn_concat_chars_to_cstr(hio_concat_bchars_to_bcstr, hio_bch_t, hio_count_bcstr)
dnl --
fn_concat_cstr(hio_concat_ucstr, hio_uch_t, hio_count_ucstr)
fn_concat_cstr(hio_concat_bcstr, hio_bch_t, hio_count_bcstr)
dnl --
fn_copy_chars(hio_copy_uchars, hio_uch_t)
fn_copy_chars(hio_copy_bchars, hio_bch_t)
dnl --
fn_copy_chars_to_cstr(hio_copy_uchars_to_ucstr, hio_uch_t)
fn_copy_chars_to_cstr(hio_copy_bchars_to_bcstr, hio_bch_t)
dnl --
fn_copy_chars_to_cstr_unlimited(hio_copy_uchars_to_ucstr_unlimited, hio_uch_t)
fn_copy_chars_to_cstr_unlimited(hio_copy_bchars_to_bcstr_unlimited, hio_bch_t)
dnl --
fn_copy_cstr(hio_copy_ucstr, hio_uch_t)
fn_copy_cstr(hio_copy_bcstr, hio_bch_t)
dnl --
fn_copy_cstr_unlimited(hio_copy_ucstr_unlimited, hio_uch_t)
fn_copy_cstr_unlimited(hio_copy_bcstr_unlimited, hio_bch_t)
dnl --
fn_count_cstr(hio_count_ucstr, hio_uch_t)
fn_count_cstr(hio_count_bcstr, hio_bch_t)
dnl --
fn_equal_chars(hio_equal_uchars, hio_uch_t)
fn_equal_chars(hio_equal_bchars, hio_bch_t)
dnl --
fn_fill_chars(hio_fill_uchars, hio_uch_t)
fn_fill_chars(hio_fill_bchars, hio_bch_t)
dnl --

View File

@ -1,34 +1,6 @@
dnl ---------------------------------------------------------------------------
changequote(`[[', `]]')dnl
dnl ---------------------------------------------------------------------------
define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (const _char_type_* str)
{
const _char_type_* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_equal_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_comp_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl
int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, hio_oow_t len2, int ignorecase)
{
@ -128,6 +100,41 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxle
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_comp_chars_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl
int _fn_name_ (const _char_type_* str1, hio_oow_t len, const _char_type_* str2, int ignorecase)
{
/* for "abc\0" of length 4 vs "abc", the fourth character
* of the first string is equal to the terminating null of
* the second string. the first string is still considered
* bigger */
if (ignorecase)
{
const _char_type_* end = str1 + len;
_char_type_ c1;
_char_type_ c2;
while (str1 < end && *str2 != '\0')
{
c1 = _to_lower_()(*str1);
c2 = _to_lower_()(*str2);
if (c1 != c2) return ((_chau_type_)c1 > (_chau_type_)c2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
else
{
const _char_type_* end = str1 + len;
while (str1 < end && *str2 != '\0')
{
if (*str1 != *str2) return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
}
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_concat_chars_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_count_str_]], $3)dnl
hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hio_oow_t len)
{
@ -180,6 +187,97 @@ hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str)
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_count_str_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
void _fn_name_ (_char_type_* dst, const _char_type_* src, hio_oow_t len)
{
/* take note of no forced null termination */
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_chars_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, hio_oow_t dlen, const _char_type_* src, hio_oow_t slen)
{
hio_oow_t i;
if (dlen <= 0) return 0;
if (dlen <= slen) slen = dlen - 1;
for (i = 0; i < slen; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_chars_to_cstr_unlimited]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, const _char_type_* src, hio_oow_t len)
{
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, hio_oow_t len, const _char_type_* src)
{
_char_type_* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
if (len > 0) *p = '\0';
return p - dst;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_cstr_unlimited]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, const _char_type_* src)
{
_char_type_* org = dst;
while ((*dst++ = *src++) != '\0');
return dst - org - 1;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (const _char_type_* str)
{
const _char_type_* ptr = str;
while (*ptr != '\0') ptr++;
return ptr - str;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_equal_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len)
{
hio_oow_t i;
/* NOTE: you should call this function after having ensured that
* str1 and str2 are in the same length */
for (i = 0; i < len; i++)
{
if (str1[i] != str2[i]) return 0;
}
return 1;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_fill_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
void _fn_name_ (_char_type_* dst, _char_type_ ch, hio_oow_t len)
{

View File

@ -51,38 +51,6 @@ int hio_comp_ucstr_bcstr (const hio_uch_t* str1, const hio_bch_t* str2, int igno
}
}
int hio_comp_uchars_ucstr (const hio_uch_t* str1, hio_oow_t len, const hio_uch_t* str2, int ignorecase)
{
/* for "abc\0" of length 4 vs "abc", the fourth character
* of the first string is equal to the terminating null of
* the second string. the first string is still considered
* bigger */
if (ignorecase)
{
const hio_uch_t* end = str1 + len;
hio_uch_t c1;
hio_uch_t c2;
while (str1 < end && *str2 != '\0')
{
c1 = hio_to_uch_lower(*str1);
c2 = hio_to_uch_lower(*str2);
if (c1 != c2) return ((hio_uchu_t)c1 > (hio_uchu_t)c2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
else
{
const hio_uch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
{
if (*str1 != *str2) return ((hio_uchu_t)*str1 > (hio_uchu_t)*str2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
}
int hio_comp_uchars_bcstr (const hio_uch_t* str1, hio_oow_t len, const hio_bch_t* str2, int ignorecase)
{
if (ignorecase)
@ -111,34 +79,6 @@ int hio_comp_uchars_bcstr (const hio_uch_t* str1, hio_oow_t len, const hio_bch_t
}
}
int hio_comp_bchars_bcstr (const hio_bch_t* str1, hio_oow_t len, const hio_bch_t* str2, int ignorecase)
{
if (ignorecase)
{
const hio_bch_t* end = str1 + len;
hio_bch_t c1;
hio_bch_t c2;
while (str1 < end && *str2 != '\0')
{
c1 = hio_to_bch_lower(*str1);
c2 = hio_to_bch_lower(*str2);
if (c1 != c2) return ((hio_bchu_t)c1 > (hio_bchu_t)c2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
else
{
const hio_bch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
{
if (*str1 != *str2) return ((hio_bchu_t)*str1 > (hio_bchu_t)*str2)? 1: -1;
str1++; str2++;
}
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
}
int hio_comp_bchars_ucstr (const hio_bch_t* str1, hio_oow_t len, const hio_uch_t* str2, int ignorecase)
{
if (ignorecase)
@ -169,20 +109,6 @@ int hio_comp_bchars_ucstr (const hio_bch_t* str1, hio_oow_t len, const hio_uch_t
/* ========================================================================= */
void hio_copy_uchars (hio_uch_t* dst, const hio_uch_t* src, hio_oow_t len)
{
/* take note of no forced null termination */
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
}
void hio_copy_bchars (hio_bch_t* dst, const hio_bch_t* src, hio_oow_t len)
{
/* take note of no forced null termination */
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
}
void hio_copy_bchars_to_uchars (hio_uch_t* dst, const hio_bch_t* src, hio_oow_t len)
{
/* copy without conversions.
@ -199,89 +125,6 @@ void hio_copy_uchars_to_bchars (hio_bch_t* dst, const hio_uch_t* src, hio_oow_t
for (i = 0; i < len; i++) dst[i] = src[i];
}
hio_oow_t hio_copy_uchars_to_ucstr (hio_uch_t* dst, hio_oow_t dlen, const hio_uch_t* src, hio_oow_t slen)
{
hio_oow_t i;
if (dlen <= 0) return 0;
if (dlen <= slen) slen = dlen - 1;
for (i = 0; i < slen; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_bchars_to_bcstr (hio_bch_t* dst, hio_oow_t dlen, const hio_bch_t* src, hio_oow_t slen)
{
hio_oow_t i;
if (dlen <= 0) return 0;
if (dlen <= slen) slen = dlen - 1;
for (i = 0; i < slen; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_uchars_to_ucstr_unlimited (hio_uch_t* dst, const hio_uch_t* src, hio_oow_t len)
{
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_bchars_to_bcstr_unlimited (hio_bch_t* dst, const hio_bch_t* src, hio_oow_t len)
{
hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = src[i];
dst[i] = '\0';
return i;
}
hio_oow_t hio_copy_ucstr (hio_uch_t* dst, hio_oow_t len, const hio_uch_t* src)
{
hio_uch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
if (len > 0) *p = '\0';
return p - dst;
}
hio_oow_t hio_copy_bcstr (hio_bch_t* dst, hio_oow_t len, const hio_bch_t* src)
{
hio_bch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
if (len > 0) *p = '\0';
return p - dst;
}
hio_oow_t hio_copy_ucstr_unlimited (hio_uch_t* dst, const hio_uch_t* src)
{
hio_uch_t* org = dst;
while ((*dst++ = *src++) != '\0');
return dst - org - 1;
}
hio_oow_t hio_copy_bcstr_unlimited (hio_bch_t* dst, const hio_bch_t* src)
{
hio_bch_t* org = dst;
while ((*dst++ = *src++) != '\0');
return dst - org - 1;
}
/* ========================================================================= */
#define IS_BCH_WORD_DELIM(x,delim) (hio_is_bch_space(x) || (x) == delim)