Merge pull request #23 from seleznevae/wchar-mk_wcwidth

[R] Rewrote `mk_wcwidth` function
This commit is contained in:
Seleznev Anton 2019-12-01 16:45:44 +03:00 committed by GitHub
commit 3ec64691ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View File

@ -8,6 +8,7 @@
- Fix compilation for compilers other than gcc, clang, msvc.
- Add build with tcc to CI.
- Rewrote `mk_wcwidth` function.
## v0.3.1

View File

@ -7180,12 +7180,12 @@ void vector_clear(f_vector_t *vector)
struct interval {
wchar_t first;
wchar_t last;
int32_t first;
int32_t last;
};
/* auxiliary function for binary search in interval table */
static int bisearch(wchar_t ucs, const struct interval *table, int max)
static int bisearch(int32_t ucs, const struct interval *table, int max)
{
int min = 0;
@ -7237,7 +7237,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max)
* in ISO 10646.
*/
static int mk_wcwidth(wchar_t ucs)
static int mk_wcwidth(wchar_t wcs)
{
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
@ -7292,6 +7292,14 @@ static int mk_wcwidth(wchar_t ucs)
{ 0xE0100, 0xE01EF }
};
/* We convert wchar_t to int32_t to avoid compiler warnings
* about implicit integer conversions
* https://github.com/seleznevae/libfort/issues/20
*
* note: didn't test if we can do it
*/
int32_t ucs = (int32_t)wcs;
/* test for 8-bit control characters */
if (ucs == 0)
return 0;

View File

@ -65,12 +65,12 @@
struct interval {
wchar_t first;
wchar_t last;
int32_t first;
int32_t last;
};
/* auxiliary function for binary search in interval table */
static int bisearch(wchar_t ucs, const struct interval *table, int max)
static int bisearch(int32_t ucs, const struct interval *table, int max)
{
int min = 0;
@ -122,7 +122,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max)
* in ISO 10646.
*/
static int mk_wcwidth(wchar_t ucs)
static int mk_wcwidth(wchar_t wcs)
{
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
@ -177,6 +177,14 @@ static int mk_wcwidth(wchar_t ucs)
{ 0xE0100, 0xE01EF }
};
/* We convert wchar_t to int32_t to avoid compiler warnings
* about implicit integer conversions
* https://github.com/seleznevae/libfort/issues/20
*
* note: didn't test if we can do it
*/
int32_t ucs = (int32_t)wcs;
/* test for 8-bit control characters */
if (ucs == 0)
return 0;