Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Implement graphemewidth


On Fri, 27 Oct 2017 00:15:16 -0400, "S. Gilles" <sgilles@xxxxxxxxxxxx> wrote:

>  - Moved tables into chartype (so cellwidth goes there)
> 
>  - Moved strcellwidth into utf.myr
> 
>  - Added tests for cellwidth, strcellwidth, and fmt

Sounds good. I think this patch is getting close.
 
> For now, I've kept my interval lists. Since we aren't combining
> sets in any sort of way, an inversion list doesn't make anything
> easier, and would be a bit less clear to read (in my opinion).

Agreed, no need for an inversion list.
 
> Plus, since reading Gillam, I agree that the Right Way to do this
> would be to use something like a compact array (which is definitely
> what musl uses). That's a project for mkchartab, and would affect
> the whole file.

Yep. Let's get this landed first, though.

> ---
>  lib/std/chartype.myr      | 490 ++++++++++++++++++++++++++++++++++++++++++++++
>  lib/std/fmt.myr           |  10 +-
>  lib/std/test/chartype.myr |  15 ++
>  lib/std/test/fmt.myr      |   4 +
>  lib/std/test/utf.myr      | Bin 0 -> 1285 bytes
>  lib/std/utf.myr           |  29 +++
>  6 files changed, 539 insertions(+), 9 deletions(-)
>  create mode 100644 lib/std/test/utf.myr
> 
> diff --git a/lib/std/chartype.myr b/lib/std/chartype.myr
> index dd31e200..6465b258 100644
> --- a/lib/std/chartype.myr
> +++ b/lib/std/chartype.myr
> @@ -26,6 +26,8 @@ pkg std =
>  	const totitle	: (c : char -> char)
>  
>  	generic charval : (c : char, base : int -> @a::(integral,numeric))
> +
> +	const cellwidth	: (c : char -> int)
>  ;;
>  
>  extern const put	: (fmt : byte[:], args : ... -> size)
> @@ -1061,6 +1063,450 @@ const rtotitle1 = [
>  	0x01f3, 499	/* dz Dz */
>  ]
>  
> +type interval = struct
> +	first : char
> +	last : char
> +;;
> +
> +/* Unintelligent binary search */
> +const in_range = { c : char, t : interval[:]
> +	if c < t[0].first || c > t[t.len - 1].last
> +		-> false
> +	;;
> +
> +	while t.len >= 1
> +		var j : size = t.len / 2
> +		if c < t[j].first
> +			t = t[0:j]
> +		elif c > t[j].last
> +			t = t[j+1:]
> +		else
> +			-> true
> +		;;
> +	;;
> +
> +	-> false
> +}

There's already a binary search implementation in this file
(findc). I think it can be used in place of this function, if
we represent the table as an array with a stride of two.

-- 
    Ori Bernstein

Follow-Ups:
[PATCH v3] Implement graphemewidth"S. Gilles" <sgilles@xxxxxxxxxxxx>
References:
Re: [PATCH] implement graphemewidth"S. Gilles" <sgilles@xxxxxxxxxxxx>
[PATCH] Implement graphemewidth"S. Gilles" <sgilles@xxxxxxxxxxxx>