diff --git a/ChangeLog.md b/ChangeLog.md index dfc14c3..8c4585a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/lib/fort.c b/lib/fort.c index 1fefa4c..3815b00 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -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; diff --git a/src/wcwidth.c b/src/wcwidth.c index f97b879..2e10ed0 100644 --- a/src/wcwidth.c +++ b/src/wcwidth.c @@ -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;