renamed hcl to hak
This commit is contained in:
272
lib/str.c
272
lib/str.c
@ -22,11 +22,11 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hcl-str.h>
|
||||
#include <hak-str.h>
|
||||
|
||||
int hcl_equal_uchars (const hcl_uch_t* str1, const hcl_uch_t* str2, hcl_oow_t len)
|
||||
int hak_equal_uchars (const hak_uch_t* str1, const hak_uch_t* str2, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
|
||||
/* NOTE: you should call this function after having ensured that
|
||||
* str1 and str2 are in the same length */
|
||||
@ -39,9 +39,9 @@ int hcl_equal_uchars (const hcl_uch_t* str1, const hcl_uch_t* str2, hcl_oow_t le
|
||||
return 1;
|
||||
}
|
||||
|
||||
int hcl_equal_bchars (const hcl_bch_t* str1, const hcl_bch_t* str2, hcl_oow_t len)
|
||||
int hak_equal_bchars (const hak_bch_t* str1, const hak_bch_t* str2, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
|
||||
/* NOTE: you should call this function after having ensured that
|
||||
* str1 and str2 are in the same length */
|
||||
@ -54,11 +54,11 @@ int hcl_equal_bchars (const hcl_bch_t* str1, const hcl_bch_t* str2, hcl_oow_t le
|
||||
return 1;
|
||||
}
|
||||
|
||||
int hcl_comp_uchars (const hcl_uch_t* str1, hcl_oow_t len1, const hcl_uch_t* str2, hcl_oow_t len2)
|
||||
int hak_comp_uchars (const hak_uch_t* str1, hak_oow_t len1, const hak_uch_t* str2, hak_oow_t len2)
|
||||
{
|
||||
hcl_uchu_t c1, c2;
|
||||
const hcl_uch_t* end1 = str1 + len1;
|
||||
const hcl_uch_t* end2 = str2 + len2;
|
||||
hak_uchu_t c1, c2;
|
||||
const hak_uch_t* end1 = str1 + len1;
|
||||
const hak_uch_t* end2 = str2 + len2;
|
||||
|
||||
while (str1 < end1)
|
||||
{
|
||||
@ -76,11 +76,11 @@ int hcl_comp_uchars (const hcl_uch_t* str1, hcl_oow_t len1, const hcl_uch_t* str
|
||||
return (str2 < end2)? -1: 0;
|
||||
}
|
||||
|
||||
int hcl_comp_bchars (const hcl_bch_t* str1, hcl_oow_t len1, const hcl_bch_t* str2, hcl_oow_t len2)
|
||||
int hak_comp_bchars (const hak_bch_t* str1, hak_oow_t len1, const hak_bch_t* str2, hak_oow_t len2)
|
||||
{
|
||||
hcl_bchu_t c1, c2;
|
||||
const hcl_bch_t* end1 = str1 + len1;
|
||||
const hcl_bch_t* end2 = str2 + len2;
|
||||
hak_bchu_t c1, c2;
|
||||
const hak_bch_t* end1 = str1 + len1;
|
||||
const hak_bch_t* end2 = str2 + len2;
|
||||
|
||||
while (str1 < end1)
|
||||
{
|
||||
@ -98,7 +98,7 @@ int hcl_comp_bchars (const hcl_bch_t* str1, hcl_oow_t len1, const hcl_bch_t* str
|
||||
return (str2 < end2)? -1: 0;
|
||||
}
|
||||
|
||||
int hcl_comp_ucstr (const hcl_uch_t* str1, const hcl_uch_t* str2)
|
||||
int hak_comp_ucstr (const hak_uch_t* str1, const hak_uch_t* str2)
|
||||
{
|
||||
while (*str1 == *str2)
|
||||
{
|
||||
@ -106,10 +106,10 @@ int hcl_comp_ucstr (const hcl_uch_t* str1, const hcl_uch_t* str2)
|
||||
str1++; str2++;
|
||||
}
|
||||
|
||||
return ((hcl_uchu_t)*str1 > (hcl_uchu_t)*str2)? 1: -1;
|
||||
return ((hak_uchu_t)*str1 > (hak_uchu_t)*str2)? 1: -1;
|
||||
}
|
||||
|
||||
int hcl_comp_bcstr (const hcl_bch_t* str1, const hcl_bch_t* str2)
|
||||
int hak_comp_bcstr (const hak_bch_t* str1, const hak_bch_t* str2)
|
||||
{
|
||||
while (*str1 == *str2)
|
||||
{
|
||||
@ -117,10 +117,10 @@ int hcl_comp_bcstr (const hcl_bch_t* str1, const hcl_bch_t* str2)
|
||||
str1++; str2++;
|
||||
}
|
||||
|
||||
return ((hcl_bchu_t)*str1 > (hcl_bchu_t)*str2)? 1: -1;
|
||||
return ((hak_bchu_t)*str1 > (hak_bchu_t)*str2)? 1: -1;
|
||||
}
|
||||
|
||||
int hcl_comp_ucstr_bcstr (const hcl_uch_t* str1, const hcl_bch_t* str2)
|
||||
int hak_comp_ucstr_bcstr (const hak_uch_t* str1, const hak_bch_t* str2)
|
||||
{
|
||||
while (*str1 == *str2)
|
||||
{
|
||||
@ -128,92 +128,92 @@ int hcl_comp_ucstr_bcstr (const hcl_uch_t* str1, const hcl_bch_t* str2)
|
||||
str1++; str2++;
|
||||
}
|
||||
|
||||
return ((hcl_uchu_t)*str1 > (hcl_bchu_t)*str2)? 1: -1;
|
||||
return ((hak_uchu_t)*str1 > (hak_bchu_t)*str2)? 1: -1;
|
||||
}
|
||||
|
||||
int hcl_comp_uchars_ucstr (const hcl_uch_t* str1, hcl_oow_t len, const hcl_uch_t* str2)
|
||||
int hak_comp_uchars_ucstr (const hak_uch_t* str1, hak_oow_t len, const hak_uch_t* str2)
|
||||
{
|
||||
/* 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 */
|
||||
const hcl_uch_t* end = str1 + len;
|
||||
const hak_uch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
if (*str1 != *str2) return ((hcl_uchu_t)*str1 > (hcl_uchu_t)*str2)? 1: -1;
|
||||
if (*str1 != *str2) return ((hak_uchu_t)*str1 > (hak_uchu_t)*str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int hcl_comp_uchars_bcstr (const hcl_uch_t* str1, hcl_oow_t len, const hcl_bch_t* str2)
|
||||
int hak_comp_uchars_bcstr (const hak_uch_t* str1, hak_oow_t len, const hak_bch_t* str2)
|
||||
{
|
||||
const hcl_uch_t* end = str1 + len;
|
||||
const hak_uch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
if (*str1 != *str2) return ((hcl_uchu_t)*str1 > (hcl_bchu_t)*str2)? 1: -1;
|
||||
if (*str1 != *str2) return ((hak_uchu_t)*str1 > (hak_bchu_t)*str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int hcl_comp_bchars_bcstr (const hcl_bch_t* str1, hcl_oow_t len, const hcl_bch_t* str2)
|
||||
int hak_comp_bchars_bcstr (const hak_bch_t* str1, hak_oow_t len, const hak_bch_t* str2)
|
||||
{
|
||||
const hcl_bch_t* end = str1 + len;
|
||||
const hak_bch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
if (*str1 != *str2) return ((hcl_bchu_t)*str1 > (hcl_bchu_t)*str2)? 1: -1;
|
||||
if (*str1 != *str2) return ((hak_bchu_t)*str1 > (hak_bchu_t)*str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
int hcl_comp_bchars_ucstr (const hcl_bch_t* str1, hcl_oow_t len, const hcl_uch_t* str2)
|
||||
int hak_comp_bchars_ucstr (const hak_bch_t* str1, hak_oow_t len, const hak_uch_t* str2)
|
||||
{
|
||||
const hcl_bch_t* end = str1 + len;
|
||||
const hak_bch_t* end = str1 + len;
|
||||
while (str1 < end && *str2 != '\0')
|
||||
{
|
||||
if (*str1 != *str2) return ((hcl_bchu_t)*str1 > (hcl_uchu_t)*str2)? 1: -1;
|
||||
if (*str1 != *str2) return ((hak_bchu_t)*str1 > (hak_uchu_t)*str2)? 1: -1;
|
||||
str1++; str2++;
|
||||
}
|
||||
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
|
||||
}
|
||||
|
||||
void hcl_copy_uchars (hcl_uch_t* dst, const hcl_uch_t* src, hcl_oow_t len)
|
||||
void hak_copy_uchars (hak_uch_t* dst, const hak_uch_t* src, hak_oow_t len)
|
||||
{
|
||||
/* take note of no forced null termination */
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
void hcl_copy_bchars (hcl_bch_t* dst, const hcl_bch_t* src, hcl_oow_t len)
|
||||
void hak_copy_bchars (hak_bch_t* dst, const hak_bch_t* src, hak_oow_t len)
|
||||
{
|
||||
/* take note of no forced null termination */
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
void hcl_copy_bchars_to_uchars (hcl_uch_t* dst, const hcl_bch_t* src, hcl_oow_t len)
|
||||
void hak_copy_bchars_to_uchars (hak_uch_t* dst, const hak_bch_t* src, hak_oow_t len)
|
||||
{
|
||||
/* copy without conversions.
|
||||
* use hcl_convbtouchars() for conversion encoding */
|
||||
hcl_oow_t i;
|
||||
* use hak_convbtouchars() for conversion encoding */
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
void hcl_copy_uchars_to_bchars (hcl_bch_t* dst, const hcl_uch_t* src, hcl_oow_t len)
|
||||
void hak_copy_uchars_to_bchars (hak_bch_t* dst, const hak_uch_t* src, hak_oow_t len)
|
||||
{
|
||||
/* copy without conversions.
|
||||
* use hcl_convutobchars() for conversion encoding */
|
||||
hcl_oow_t i;
|
||||
* use hak_convutobchars() for conversion encoding */
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bcstr_to_ucstr (hcl_uch_t* dst, hcl_oow_t len, const hcl_bch_t* src)
|
||||
hak_oow_t hak_copy_bcstr_to_ucstr (hak_uch_t* dst, hak_oow_t len, const hak_bch_t* src)
|
||||
{
|
||||
/* copy without conversions.
|
||||
* the code is the same as hcl_copy_bcstr() except type of src */
|
||||
hcl_uch_t* p, * p2;
|
||||
* the code is the same as hak_copy_bcstr() except type of src */
|
||||
hak_uch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
@ -227,10 +227,10 @@ hcl_oow_t hcl_copy_bcstr_to_ucstr (hcl_uch_t* dst, hcl_oow_t len, const hcl_bch_
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_ucstr_to_bcstr (hcl_bch_t* dst, hcl_oow_t len, const hcl_uch_t* src)
|
||||
hak_oow_t hak_copy_ucstr_to_bcstr (hak_bch_t* dst, hak_oow_t len, const hak_uch_t* src)
|
||||
{
|
||||
/* copy without conversions */
|
||||
hcl_bch_t* p, * p2;
|
||||
hak_bch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
@ -245,9 +245,9 @@ hcl_oow_t hcl_copy_ucstr_to_bcstr (hcl_bch_t* dst, hcl_oow_t len, const hcl_uch_
|
||||
}
|
||||
|
||||
|
||||
hcl_oow_t hcl_copy_uchars_to_ucstr (hcl_uch_t* dst, hcl_oow_t dlen, const hcl_uch_t* src, hcl_oow_t slen)
|
||||
hak_oow_t hak_copy_uchars_to_ucstr (hak_uch_t* dst, hak_oow_t dlen, const hak_uch_t* src, hak_oow_t slen)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
if (dlen <= 0) return 0;
|
||||
if (dlen <= slen) slen = dlen - 1;
|
||||
for (i = 0; i < slen; i++) dst[i] = src[i];
|
||||
@ -255,9 +255,9 @@ hcl_oow_t hcl_copy_uchars_to_ucstr (hcl_uch_t* dst, hcl_oow_t dlen, const hcl_uc
|
||||
return i;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bchars_to_bcstr (hcl_bch_t* dst, hcl_oow_t dlen, const hcl_bch_t* src, hcl_oow_t slen)
|
||||
hak_oow_t hak_copy_bchars_to_bcstr (hak_bch_t* dst, hak_oow_t dlen, const hak_bch_t* src, hak_oow_t slen)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
if (dlen <= 0) return 0;
|
||||
if (dlen <= slen) slen = dlen - 1;
|
||||
for (i = 0; i < slen; i++) dst[i] = src[i];
|
||||
@ -265,25 +265,25 @@ hcl_oow_t hcl_copy_bchars_to_bcstr (hcl_bch_t* dst, hcl_oow_t dlen, const hcl_bc
|
||||
return i;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_uchars_to_ucstr_unlimited (hcl_uch_t* dst, const hcl_uch_t* src, hcl_oow_t len)
|
||||
hak_oow_t hak_copy_uchars_to_ucstr_unlimited (hak_uch_t* dst, const hak_uch_t* src, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
dst[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bchars_to_bcstr_unlimited (hcl_bch_t* dst, const hcl_bch_t* src, hcl_oow_t len)
|
||||
hak_oow_t hak_copy_bchars_to_bcstr_unlimited (hak_bch_t* dst, const hak_bch_t* src, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
dst[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_ucstr (hcl_uch_t* dst, hcl_oow_t len, const hcl_uch_t* src)
|
||||
hak_oow_t hak_copy_ucstr (hak_uch_t* dst, hak_oow_t len, const hak_uch_t* src)
|
||||
{
|
||||
hcl_uch_t* p, * p2;
|
||||
hak_uch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
@ -297,9 +297,9 @@ hcl_oow_t hcl_copy_ucstr (hcl_uch_t* dst, hcl_oow_t len, const hcl_uch_t* src)
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bcstr (hcl_bch_t* dst, hcl_oow_t len, const hcl_bch_t* src)
|
||||
hak_oow_t hak_copy_bcstr (hak_bch_t* dst, hak_oow_t len, const hak_bch_t* src)
|
||||
{
|
||||
hcl_bch_t* p, * p2;
|
||||
hak_bch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
@ -314,130 +314,130 @@ hcl_oow_t hcl_copy_bcstr (hcl_bch_t* dst, hcl_oow_t len, const hcl_bch_t* src)
|
||||
}
|
||||
|
||||
|
||||
hcl_oow_t hcl_copy_ucstr_unlimited (hcl_uch_t* dst, const hcl_uch_t* src)
|
||||
hak_oow_t hak_copy_ucstr_unlimited (hak_uch_t* dst, const hak_uch_t* src)
|
||||
{
|
||||
hcl_uch_t* org = dst;
|
||||
hak_uch_t* org = dst;
|
||||
while ((*dst++ = *src++) != '\0');
|
||||
return dst - org - 1;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bcstr_unlimited (hcl_bch_t* dst, const hcl_bch_t* src)
|
||||
hak_oow_t hak_copy_bcstr_unlimited (hak_bch_t* dst, const hak_bch_t* src)
|
||||
{
|
||||
hcl_bch_t* org = dst;
|
||||
hak_bch_t* org = dst;
|
||||
while ((*dst++ = *src++) != '\0');
|
||||
return dst - org - 1;
|
||||
}
|
||||
|
||||
void hcl_fill_uchars (hcl_uch_t* dst, hcl_uch_t ch, hcl_oow_t len)
|
||||
void hak_fill_uchars (hak_uch_t* dst, hak_uch_t ch, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = ch;
|
||||
}
|
||||
|
||||
void hcl_fill_bchars (hcl_bch_t* dst, hcl_bch_t ch, hcl_oow_t len)
|
||||
void hak_fill_bchars (hak_bch_t* dst, hak_bch_t ch, hak_oow_t len)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
hak_oow_t i;
|
||||
for (i = 0; i < len; i++) dst[i] = ch;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_count_ucstr (const hcl_uch_t* str)
|
||||
hak_oow_t hak_count_ucstr (const hak_uch_t* str)
|
||||
{
|
||||
const hcl_uch_t* ptr = str;
|
||||
const hak_uch_t* ptr = str;
|
||||
while (*ptr != '\0') ptr++;
|
||||
return ptr - str;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_count_bcstr (const hcl_bch_t* str)
|
||||
hak_oow_t hak_count_bcstr (const hak_bch_t* str)
|
||||
{
|
||||
const hcl_bch_t* ptr = str;
|
||||
const hak_bch_t* ptr = str;
|
||||
while (*ptr != '\0') ptr++;
|
||||
return ptr - str;
|
||||
}
|
||||
|
||||
hcl_uch_t* hcl_find_uchar (const hcl_uch_t* ptr, hcl_oow_t len, hcl_uch_t c)
|
||||
hak_uch_t* hak_find_uchar (const hak_uch_t* ptr, hak_oow_t len, hak_uch_t c)
|
||||
{
|
||||
const hcl_uch_t* end;
|
||||
const hak_uch_t* end;
|
||||
|
||||
end = ptr + len;
|
||||
while (ptr < end)
|
||||
{
|
||||
if (*ptr == c) return (hcl_uch_t*)ptr;
|
||||
if (*ptr == c) return (hak_uch_t*)ptr;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
hcl_bch_t* hcl_find_bchar (const hcl_bch_t* ptr, hcl_oow_t len, hcl_bch_t c)
|
||||
hak_bch_t* hak_find_bchar (const hak_bch_t* ptr, hak_oow_t len, hak_bch_t c)
|
||||
{
|
||||
const hcl_bch_t* end;
|
||||
const hak_bch_t* end;
|
||||
|
||||
end = ptr + len;
|
||||
while (ptr < end)
|
||||
{
|
||||
if (*ptr == c) return (hcl_bch_t*)ptr;
|
||||
if (*ptr == c) return (hak_bch_t*)ptr;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
hcl_uch_t* hcl_rfind_uchar (const hcl_uch_t* ptr, hcl_oow_t len, hcl_uch_t c)
|
||||
hak_uch_t* hak_rfind_uchar (const hak_uch_t* ptr, hak_oow_t len, hak_uch_t c)
|
||||
{
|
||||
const hcl_uch_t* cur;
|
||||
const hak_uch_t* cur;
|
||||
|
||||
cur = ptr + len;
|
||||
while (cur > ptr)
|
||||
{
|
||||
--cur;
|
||||
if (*cur == c) return (hcl_uch_t*)cur;
|
||||
if (*cur == c) return (hak_uch_t*)cur;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
hcl_bch_t* hcl_rfind_bchar (const hcl_bch_t* ptr, hcl_oow_t len, hcl_bch_t c)
|
||||
hak_bch_t* hak_rfind_bchar (const hak_bch_t* ptr, hak_oow_t len, hak_bch_t c)
|
||||
{
|
||||
const hcl_bch_t* cur;
|
||||
const hak_bch_t* cur;
|
||||
|
||||
cur = ptr + len;
|
||||
while (cur > ptr)
|
||||
{
|
||||
--cur;
|
||||
if (*cur == c) return (hcl_bch_t*)cur;
|
||||
if (*cur == c) return (hak_bch_t*)cur;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
hcl_uch_t* hcl_find_uchar_in_ucstr (const hcl_uch_t* ptr, hcl_uch_t c)
|
||||
hak_uch_t* hak_find_uchar_in_ucstr (const hak_uch_t* ptr, hak_uch_t c)
|
||||
{
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
if (*ptr == c) return (hcl_uch_t*)ptr;
|
||||
if (*ptr == c) return (hak_uch_t*)ptr;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
hcl_bch_t* hcl_find_bchar_in_bcstr (const hcl_bch_t* ptr, hcl_bch_t c)
|
||||
hak_bch_t* hak_find_bchar_in_bcstr (const hak_bch_t* ptr, hak_bch_t c)
|
||||
{
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
if (*ptr == c) return (hcl_bch_t*)ptr;
|
||||
if (*ptr == c) return (hak_bch_t*)ptr;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return HCL_NULL;
|
||||
return HAK_NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
hcl_oow_t hcl_rotate_uchars (hcl_uch_t* str, hcl_oow_t len, int dir, hcl_oow_t n)
|
||||
hak_oow_t hak_rotate_uchars (hak_uch_t* str, hak_oow_t len, int dir, hak_oow_t n)
|
||||
{
|
||||
hcl_oow_t first, last, count, index, nk;
|
||||
hcl_uch_t c;
|
||||
hak_oow_t first, last, count, index, nk;
|
||||
hak_uch_t c;
|
||||
|
||||
if (dir == 0 || len == 0) return len;
|
||||
if ((n %= len) == 0) return len;
|
||||
@ -468,10 +468,10 @@ hcl_oow_t hcl_rotate_uchars (hcl_uch_t* str, hcl_oow_t len, int dir, hcl_oow_t n
|
||||
return len;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_rotate_bchars (hcl_bch_t* str, hcl_oow_t len, int dir, hcl_oow_t n)
|
||||
hak_oow_t hak_rotate_bchars (hak_bch_t* str, hak_oow_t len, int dir, hak_oow_t n)
|
||||
{
|
||||
hcl_oow_t first, last, count, index, nk;
|
||||
hcl_bch_t c;
|
||||
hak_oow_t first, last, count, index, nk;
|
||||
hak_bch_t c;
|
||||
|
||||
if (dir == 0 || len == 0) return len;
|
||||
if ((n %= len) == 0) return len;
|
||||
@ -504,20 +504,20 @@ hcl_oow_t hcl_rotate_bchars (hcl_bch_t* str, hcl_oow_t len, int dir, hcl_oow_t n
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
hcl_oow_t hcl_byte_to_bcstr (hcl_uint8_t byte, hcl_bch_t* buf, hcl_oow_t size, int flagged_radix, hcl_bch_t fill)
|
||||
hak_oow_t hak_byte_to_bcstr (hak_uint8_t byte, hak_bch_t* buf, hak_oow_t size, int flagged_radix, hak_bch_t fill)
|
||||
{
|
||||
hcl_bch_t tmp[(HCL_SIZEOF(hcl_uint8_t) * HCL_BITS_PER_BYTE)];
|
||||
hcl_bch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
||||
hak_bch_t tmp[(HAK_SIZEOF(hak_uint8_t) * HAK_BITS_PER_BYTE)];
|
||||
hak_bch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
||||
int radix;
|
||||
hcl_bch_t radix_char;
|
||||
hak_bch_t radix_char;
|
||||
|
||||
radix = (flagged_radix & HCL_BYTE_TO_BCSTR_RADIXMASK);
|
||||
radix_char = (flagged_radix & HCL_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A';
|
||||
radix = (flagged_radix & HAK_BYTE_TO_BCSTR_RADIXMASK);
|
||||
radix_char = (flagged_radix & HAK_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A';
|
||||
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
||||
|
||||
do
|
||||
{
|
||||
hcl_uint8_t digit = byte % radix;
|
||||
hak_uint8_t digit = byte % radix;
|
||||
if (digit < 10) *p++ = digit + '0';
|
||||
else *p++ = digit + radix_char - 10;
|
||||
byte /= radix;
|
||||
@ -540,18 +540,18 @@ hcl_oow_t hcl_byte_to_bcstr (hcl_uint8_t byte, hcl_bch_t* buf, hcl_oow_t size, i
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
int hcl_conv_bchars_to_uchars_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)
|
||||
int hak_conv_bchars_to_uchars_with_cmgr (const hak_bch_t* bcs, hak_oow_t* bcslen, hak_uch_t* ucs, hak_oow_t* ucslen, hak_cmgr_t* cmgr, int all)
|
||||
{
|
||||
const hcl_bch_t* p;
|
||||
const hak_bch_t* p;
|
||||
int ret = 0;
|
||||
hcl_oow_t mlen;
|
||||
hak_oow_t mlen;
|
||||
|
||||
if (ucs)
|
||||
{
|
||||
/* destination buffer is specified.
|
||||
* copy the conversion result to the buffer */
|
||||
|
||||
hcl_uch_t* q, * qend;
|
||||
hak_uch_t* q, * qend;
|
||||
|
||||
p = bcs;
|
||||
q = ucs;
|
||||
@ -560,7 +560,7 @@ int hcl_conv_bchars_to_uchars_with_cmgr (const hcl_bch_t* bcs, hcl_oow_t* bcslen
|
||||
|
||||
while (mlen > 0)
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
if (q >= qend)
|
||||
{
|
||||
@ -615,15 +615,15 @@ int hcl_conv_bchars_to_uchars_with_cmgr (const hcl_bch_t* bcs, hcl_oow_t* bcslen
|
||||
* a buffer with the size and call this function again with
|
||||
* the buffer. */
|
||||
|
||||
hcl_uch_t w;
|
||||
hcl_oow_t wlen = 0;
|
||||
hak_uch_t w;
|
||||
hak_oow_t wlen = 0;
|
||||
|
||||
p = bcs;
|
||||
mlen = *bcslen;
|
||||
|
||||
while (mlen > 0)
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
n = cmgr->bctouc(p, mlen, &w);
|
||||
if (n == 0)
|
||||
@ -659,16 +659,16 @@ int hcl_conv_bchars_to_uchars_with_cmgr (const hcl_bch_t* bcs, hcl_oow_t* bcslen
|
||||
return ret;
|
||||
}
|
||||
|
||||
int hcl_conv_bcstr_to_ucstr_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)
|
||||
int hak_conv_bcstr_to_ucstr_with_cmgr (const hak_bch_t* bcs, hak_oow_t* bcslen, hak_uch_t* ucs, hak_oow_t* ucslen, hak_cmgr_t* cmgr, int all)
|
||||
{
|
||||
const hcl_bch_t* bp;
|
||||
hcl_oow_t mlen, wlen;
|
||||
const hak_bch_t* bp;
|
||||
hak_oow_t mlen, wlen;
|
||||
int n;
|
||||
|
||||
for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ;
|
||||
|
||||
mlen = bp - bcs; wlen = *ucslen;
|
||||
n = hcl_conv_bchars_to_uchars_with_cmgr(bcs, &mlen, ucs, &wlen, cmgr, all);
|
||||
n = hak_conv_bchars_to_uchars_with_cmgr(bcs, &mlen, ucs, &wlen, cmgr, all);
|
||||
if (ucs)
|
||||
{
|
||||
/* null-terminate the target buffer if it has room for it. */
|
||||
@ -680,19 +680,19 @@ int hcl_conv_bcstr_to_ucstr_with_cmgr (const hcl_bch_t* bcs, hcl_oow_t* bcslen,
|
||||
return n;
|
||||
}
|
||||
|
||||
int hcl_conv_uchars_to_bchars_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_cmgr_t* cmgr)
|
||||
int hak_conv_uchars_to_bchars_with_cmgr (const hak_uch_t* ucs, hak_oow_t* ucslen, hak_bch_t* bcs, hak_oow_t* bcslen, hak_cmgr_t* cmgr)
|
||||
{
|
||||
const hcl_uch_t* p = ucs;
|
||||
const hcl_uch_t* end = ucs + *ucslen;
|
||||
const hak_uch_t* p = ucs;
|
||||
const hak_uch_t* end = ucs + *ucslen;
|
||||
int ret = 0;
|
||||
|
||||
if (bcs)
|
||||
{
|
||||
hcl_oow_t rem = *bcslen;
|
||||
hak_oow_t rem = *bcslen;
|
||||
|
||||
while (p < end)
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
if (rem <= 0)
|
||||
{
|
||||
@ -718,14 +718,14 @@ int hcl_conv_uchars_to_bchars_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen
|
||||
}
|
||||
else
|
||||
{
|
||||
hcl_bch_t bcsbuf[HCL_BCSIZE_MAX];
|
||||
hcl_oow_t mlen = 0;
|
||||
hak_bch_t bcsbuf[HAK_BCSIZE_MAX];
|
||||
hak_oow_t mlen = 0;
|
||||
|
||||
while (p < end)
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
n = cmgr->uctobc(*p, bcsbuf, HCL_COUNTOF(bcsbuf));
|
||||
n = cmgr->uctobc(*p, bcsbuf, HAK_COUNTOF(bcsbuf));
|
||||
if (n == 0)
|
||||
{
|
||||
ret = -1;
|
||||
@ -733,7 +733,7 @@ int hcl_conv_uchars_to_bchars_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen
|
||||
}
|
||||
|
||||
/* it assumes that bcsbuf is large enough to hold a character */
|
||||
/*HCL_ASSERT (hcl, n <= HCL_COUNTOF(bcsbuf));*/
|
||||
/*HAK_ASSERT (hak, n <= HAK_COUNTOF(bcsbuf));*/
|
||||
|
||||
p++; mlen += n;
|
||||
}
|
||||
@ -747,18 +747,18 @@ int hcl_conv_uchars_to_bchars_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen
|
||||
return ret;
|
||||
}
|
||||
|
||||
int hcl_conv_ucstr_to_bcstr_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_cmgr_t* cmgr)
|
||||
int hak_conv_ucstr_to_bcstr_with_cmgr (const hak_uch_t* ucs, hak_oow_t* ucslen, hak_bch_t* bcs, hak_oow_t* bcslen, hak_cmgr_t* cmgr)
|
||||
{
|
||||
const hcl_uch_t* p = ucs;
|
||||
const hak_uch_t* p = ucs;
|
||||
int ret = 0;
|
||||
|
||||
if (bcs)
|
||||
{
|
||||
hcl_oow_t rem = *bcslen;
|
||||
hak_oow_t rem = *bcslen;
|
||||
|
||||
while (*p != '\0')
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
if (rem <= 0)
|
||||
{
|
||||
@ -797,14 +797,14 @@ int hcl_conv_ucstr_to_bcstr_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen,
|
||||
}
|
||||
else
|
||||
{
|
||||
hcl_bch_t bcsbuf[HCL_BCSIZE_MAX];
|
||||
hcl_oow_t mlen = 0;
|
||||
hak_bch_t bcsbuf[HAK_BCSIZE_MAX];
|
||||
hak_oow_t mlen = 0;
|
||||
|
||||
while (*p != '\0')
|
||||
{
|
||||
hcl_oow_t n;
|
||||
hak_oow_t n;
|
||||
|
||||
n = cmgr->uctobc(*p, bcsbuf, HCL_COUNTOF(bcsbuf));
|
||||
n = cmgr->uctobc(*p, bcsbuf, HAK_COUNTOF(bcsbuf));
|
||||
if (n == 0)
|
||||
{
|
||||
ret = -1;
|
||||
@ -812,7 +812,7 @@ int hcl_conv_ucstr_to_bcstr_with_cmgr (const hcl_uch_t* ucs, hcl_oow_t* ucslen,
|
||||
}
|
||||
|
||||
/* it assumes that bcs is large enough to hold a character */
|
||||
/*HCL_ASSERT (hcl, n <= HCL_COUNTOF(bcs));*/
|
||||
/*HAK_ASSERT (hak, n <= HAK_COUNTOF(bcs));*/
|
||||
|
||||
p++; mlen += n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user