Fix unsigned/signed comparison issues. (#103)

Seen here:
https://github.com/VedantParanjape/simpPRU/runs/2613171696
This commit is contained in:
Arthur Sonzogni
2021-05-18 21:48:32 +02:00
committed by GitHub
parent 84debba10c
commit 87a1d75bf1
2 changed files with 16 additions and 6 deletions

View File

@@ -67,12 +67,12 @@ namespace ftxui {
namespace {
struct interval {
int first;
int last;
char32_t first;
char32_t last;
};
/* auxiliary function for binary search in interval table */
int bisearch(wchar_t ucs, const struct interval* table, int max) {
int bisearch(char32_t ucs, const struct interval* table, int max) {
int min = 0;
int mid;
@@ -120,11 +120,11 @@ int bisearch(wchar_t ucs, const struct interval* table, int max) {
* ISO 8859-1 and WGL4 characters, Unicode control characters,
* etc.) have a column width of 1.
*
* This implementation assumes that wchar_t characters are encoded
* This implementation assumes that char32_t characters are encoded
* in ISO 10646.
*/
int wchar_width(wchar_t ucs) {
int wchar_width(char32_t ucs) {
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
static const struct interval combining[] = {
@@ -214,7 +214,7 @@ int wchar_width(wchar_t ucs) {
* the traditional terminal character-width behaviour. It is not
* otherwise recommended for general use.
*/
int wchar_width_cjk(wchar_t ucs) {
int wchar_width_cjk(char32_t ucs) {
/* sorted list of non-overlapping intervals of East Asian Ambiguous
* characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
static const struct interval ambiguous[] = {
@@ -278,6 +278,14 @@ int wchar_width_cjk(wchar_t ucs) {
return wchar_width(ucs);
}
int wchar_width(wchar_t ucs) {
return wchar_width(char32_t(ucs));
}
int wchar_width_cjk(wchar_t ucs) {
return wchar_width_cjk(char32_t(ucs));
}
int wstring_width(const std::wstring& text) {
int width = 0;