reorganized some string functions
This commit is contained in:
		@ -406,6 +406,16 @@ HIO_EXPORT hio_bch_t* hio_rfind_bchars_in_bchars (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* ------------------------------------ */
 | 
					/* ------------------------------------ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					HIO_EXPORT hio_oow_t hio_compact_uchars (
 | 
				
			||||||
 | 
						hio_uch_t*       str,
 | 
				
			||||||
 | 
						hio_oow_t        len
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					HIO_EXPORT hio_oow_t hio_compact_bchars (
 | 
				
			||||||
 | 
						hio_bch_t*       str,
 | 
				
			||||||
 | 
						hio_oow_t        len
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HIO_EXPORT hio_oow_t hio_rotate_uchars (
 | 
					HIO_EXPORT hio_oow_t hio_rotate_uchars (
 | 
				
			||||||
	hio_uch_t*       str,
 | 
						hio_uch_t*       str,
 | 
				
			||||||
	hio_oow_t        len,
 | 
						hio_oow_t        len,
 | 
				
			||||||
@ -461,6 +471,7 @@ HIO_EXPORT int hio_split_bcstr (
 | 
				
			|||||||
#	define hio_comp_oochars_ucstr hio_comp_uchars_ucstr
 | 
					#	define hio_comp_oochars_ucstr hio_comp_uchars_ucstr
 | 
				
			||||||
#	define hio_comp_oochars_oocstr hio_comp_uchars_ucstr
 | 
					#	define hio_comp_oochars_oocstr hio_comp_uchars_ucstr
 | 
				
			||||||
#	define hio_comp_oocstr hio_comp_ucstr
 | 
					#	define hio_comp_oocstr hio_comp_ucstr
 | 
				
			||||||
 | 
					#	define hio_comp_oocstr_limited hio_comp_ucstr_limited
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#	define hio_copy_oochars hio_copy_uchars
 | 
					#	define hio_copy_oochars hio_copy_uchars
 | 
				
			||||||
#	define hio_copy_bchars_to_oochars hio_copy_bchars_to_uchars
 | 
					#	define hio_copy_bchars_to_oochars hio_copy_bchars_to_uchars
 | 
				
			||||||
@ -483,7 +494,11 @@ HIO_EXPORT int hio_split_bcstr (
 | 
				
			|||||||
#	define hio_find_oochar_in_oochars hio_find_uchar_in_uchars
 | 
					#	define hio_find_oochar_in_oochars hio_find_uchar_in_uchars
 | 
				
			||||||
#	define hio_rfind_oochar_in_oochars hio_rfind_uchar_in_uchars
 | 
					#	define hio_rfind_oochar_in_oochars hio_rfind_uchar_in_uchars
 | 
				
			||||||
#	define hio_find_oochar_in_oocstr hio_find_uchar_in_ucstr
 | 
					#	define hio_find_oochar_in_oocstr hio_find_uchar_in_ucstr
 | 
				
			||||||
 | 
					#	define hio_find_oochars_in_oochars hio_find_uchars_in_uchars
 | 
				
			||||||
 | 
					#	define hio_rfind_oochars_in_oochars hio_rfind_uchars_in_uchars
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	define hio_compact_oochars hio_compact_uchars
 | 
				
			||||||
 | 
					#	define hio_rotate_oochars hio_rotate_uchars
 | 
				
			||||||
#	define hio_trim_oochars hio_trim_uchars
 | 
					#	define hio_trim_oochars hio_trim_uchars
 | 
				
			||||||
#	define hio_split_oocstr hio_split_ucstr
 | 
					#	define hio_split_oocstr hio_split_ucstr
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
@ -497,6 +512,8 @@ HIO_EXPORT int hio_split_bcstr (
 | 
				
			|||||||
#	define hio_comp_oochars_ucstr hio_comp_bchars_ucstr
 | 
					#	define hio_comp_oochars_ucstr hio_comp_bchars_ucstr
 | 
				
			||||||
#	define hio_comp_oochars_oocstr hio_comp_bchars_bcstr
 | 
					#	define hio_comp_oochars_oocstr hio_comp_bchars_bcstr
 | 
				
			||||||
#	define hio_comp_oocstr hio_comp_bcstr
 | 
					#	define hio_comp_oocstr hio_comp_bcstr
 | 
				
			||||||
 | 
					#	define hio_comp_oocstr_limited hio_comp_bcstr_limited
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#	define hio_copy_oochars hio_copy_bchars
 | 
					#	define hio_copy_oochars hio_copy_bchars
 | 
				
			||||||
#	define hio_copy_bchars_to_oochars hio_copy_bchars
 | 
					#	define hio_copy_bchars_to_oochars hio_copy_bchars
 | 
				
			||||||
@ -519,15 +536,25 @@ HIO_EXPORT int hio_split_bcstr (
 | 
				
			|||||||
#	define hio_find_oochar_in_oochars hio_find_bchar_in_bchars
 | 
					#	define hio_find_oochar_in_oochars hio_find_bchar_in_bchars
 | 
				
			||||||
#	define hio_rfind_oochar_in_oochars hio_rfind_bchar_in_bchars
 | 
					#	define hio_rfind_oochar_in_oochars hio_rfind_bchar_in_bchars
 | 
				
			||||||
#	define hio_find_oochar_in_oocstr hio_find_bchar_in_bcstr
 | 
					#	define hio_find_oochar_in_oocstr hio_find_bchar_in_bcstr
 | 
				
			||||||
 | 
					#	define hio_find_oochars_in_oochars hio_find_bchars_in_bchars
 | 
				
			||||||
 | 
					#	define hio_rfind_oochars_in_oochars hio_rfind_bchars_in_bchars
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	define hio_compact_oochars hio_compact_bchars
 | 
				
			||||||
 | 
					#	define hio_rotate_oochars hio_rotate_bchars
 | 
				
			||||||
#	define hio_trim_oochars hio_trim_bchars
 | 
					#	define hio_trim_oochars hio_trim_bchars
 | 
				
			||||||
#	define hio_split_oocstr hio_split_bcstr
 | 
					#	define hio_split_oocstr hio_split_bcstr
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ------------------------------------------------------------------------- */
 | 
					/* ------------------------------------------------------------------------- */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HIO_BYTE_TO_BCSTR_RADIXMASK (0xFF)
 | 
					#define HIO_BYTE_TO_OOCSTR_RADIXMASK (0xFF)
 | 
				
			||||||
#define HIO_BYTE_TO_BCSTR_LOWERCASE (1 << 8)
 | 
					#define HIO_BYTE_TO_OOCSTR_LOWERCASE (1 << 8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define HIO_BYTE_TO_UCSTR_RADIXMASK HIO_BYTE_TO_OOCSTR_RADIXMASK
 | 
				
			||||||
 | 
					#define HIO_BYTE_TO_UCSTR_LOWERCASE HIO_BYTE_TO_OOCSTR_LOWERCASE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define HIO_BYTE_TO_BCSTR_RADIXMASK HIO_BYTE_TO_OOCSTR_RADIXMASK
 | 
				
			||||||
 | 
					#define HIO_BYTE_TO_BCSTR_LOWERCASE HIO_BYTE_TO_OOCSTR_LOWERCASE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
 | 
					HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
 | 
				
			||||||
	hio_uint8_t   byte,  
 | 
						hio_uint8_t   byte,  
 | 
				
			||||||
@ -537,9 +564,6 @@ HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
 | 
				
			|||||||
	hio_bch_t     fill
 | 
						hio_bch_t     fill
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HIO_BYTE_TO_UCSTR_RADIXMASK (0xFF)
 | 
					 | 
				
			||||||
#define HIO_BYTE_TO_UCSTR_LOWERCASE (1 << 8)
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
HIO_EXPORT hio_oow_t hio_byte_to_ucstr (
 | 
					HIO_EXPORT hio_oow_t hio_byte_to_ucstr (
 | 
				
			||||||
	hio_uint8_t   byte,  
 | 
						hio_uint8_t   byte,  
 | 
				
			||||||
	hio_uch_t*    buf,
 | 
						hio_uch_t*    buf,
 | 
				
			||||||
 | 
				
			|||||||
@ -1109,6 +1109,84 @@ hio_bch_t* hio_rfind_bchars_in_bchars (const hio_bch_t* str, hio_oow_t strsz, co
 | 
				
			|||||||
	return HIO_NULL;
 | 
						return HIO_NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					hio_oow_t hio_compact_uchars (hio_uch_t* str, hio_oow_t len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						hio_uch_t* p = str, * q = str, * end = str + len;
 | 
				
			||||||
 | 
						int followed_by_space = 0;
 | 
				
			||||||
 | 
						int state = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (p < end) 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (state == 0) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (!(*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									*q++ = *p;
 | 
				
			||||||
 | 
									state = 1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else if (state == 1) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if ((*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									if (!followed_by_space) 
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										followed_by_space = 1;
 | 
				
			||||||
 | 
										*q++ = *p;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									followed_by_space = 0;
 | 
				
			||||||
 | 
									*q++ = *p;	
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							p++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (followed_by_space) ? (q - str -1): (q - str);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					hio_oow_t hio_compact_bchars (hio_bch_t* str, hio_oow_t len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						hio_bch_t* p = str, * q = str, * end = str + len;
 | 
				
			||||||
 | 
						int followed_by_space = 0;
 | 
				
			||||||
 | 
						int state = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (p < end) 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (state == 0) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (!(*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									*q++ = *p;
 | 
				
			||||||
 | 
									state = 1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else if (state == 1) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if ((*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									if (!followed_by_space) 
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										followed_by_space = 1;
 | 
				
			||||||
 | 
										*q++ = *p;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									followed_by_space = 0;
 | 
				
			||||||
 | 
									*q++ = *p;	
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							p++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (followed_by_space) ? (q - str -1): (q - str);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hio_oow_t hio_rotate_uchars (hio_uch_t* str, hio_oow_t len, int dir, hio_oow_t n)
 | 
					hio_oow_t hio_rotate_uchars (hio_uch_t* str, hio_oow_t len, int dir, hio_oow_t n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	hio_oow_t first, last, count, index, nk;
 | 
						hio_oow_t first, last, count, index, nk;
 | 
				
			||||||
 | 
				
			|||||||
@ -108,6 +108,9 @@ dnl --
 | 
				
			|||||||
fn_rfind_chars_in_chars(hio_rfind_uchars_in_uchars, hio_uch_t, hio_to_uch_lower)
 | 
					fn_rfind_chars_in_chars(hio_rfind_uchars_in_uchars, hio_uch_t, hio_to_uch_lower)
 | 
				
			||||||
fn_rfind_chars_in_chars(hio_rfind_bchars_in_bchars, hio_bch_t, hio_to_bch_lower)
 | 
					fn_rfind_chars_in_chars(hio_rfind_bchars_in_bchars, hio_bch_t, hio_to_bch_lower)
 | 
				
			||||||
dnl --
 | 
					dnl --
 | 
				
			||||||
 | 
					fn_compact_chars(hio_compact_uchars, hio_uch_t)
 | 
				
			||||||
 | 
					fn_compact_chars(hio_compact_bchars, hio_bch_t)
 | 
				
			||||||
 | 
					dnl --
 | 
				
			||||||
fn_rotate_chars(hio_rotate_uchars, hio_uch_t)
 | 
					fn_rotate_chars(hio_rotate_uchars, hio_uch_t)
 | 
				
			||||||
fn_rotate_chars(hio_rotate_bchars, hio_bch_t)
 | 
					fn_rotate_chars(hio_rotate_bchars, hio_bch_t)
 | 
				
			||||||
dnl --
 | 
					dnl --
 | 
				
			||||||
 | 
				
			|||||||
@ -612,6 +612,48 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t strsz, const _char_typ
 | 
				
			|||||||
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_to_lower_]])dnl
 | 
					popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_to_lower_]])dnl
 | 
				
			||||||
]])dnl
 | 
					]])dnl
 | 
				
			||||||
dnl ---------------------------------------------------------------------------
 | 
					dnl ---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					define([[fn_compact_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_is_space_]], $3)dnl
 | 
				
			||||||
 | 
					hio_oow_t _fn_name_ (_char_type_* str, hio_oow_t len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_char_type_* p = str, * q = str, * end = str + len;
 | 
				
			||||||
 | 
						int followed_by_space = 0;
 | 
				
			||||||
 | 
						int state = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (p < end) 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (state == 0) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (!_is_space_()(*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									*q++ = *p;
 | 
				
			||||||
 | 
									state = 1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else if (state == 1) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (_is_space_()(*p)) 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									if (!followed_by_space) 
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										followed_by_space = 1;
 | 
				
			||||||
 | 
										*q++ = *p;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else 
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									followed_by_space = 0;
 | 
				
			||||||
 | 
									*q++ = *p;	
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							p++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (followed_by_space) ? (q - str -1): (q - str);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])dnl
 | 
				
			||||||
 | 
					]])dnl
 | 
				
			||||||
 | 
					dnl ---------------------------------------------------------------------------
 | 
				
			||||||
define([[fn_rotate_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
 | 
					define([[fn_rotate_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
 | 
				
			||||||
hio_oow_t _fn_name_ (_char_type_* str, hio_oow_t len, int dir, hio_oow_t n)
 | 
					hio_oow_t _fn_name_ (_char_type_* str, hio_oow_t len, int dir, hio_oow_t n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user