From a4d45bae8a0b0adba2a5013919497dde896f02c5 Mon Sep 17 00:00:00 2001 From: magiblot Date: Fri, 11 Oct 2024 20:00:18 +0200 Subject: [PATCH] Define maxCharSize in config.h So that it can be used everywhere, without having to include the TText header. --- include/tvision/config.h | 6 ++++++ include/tvision/scrncell.h | 4 ++-- include/tvision/system.h | 2 +- include/tvision/ttext.h | 6 ------ source/tvision/teditor1.cpp | 4 ++-- source/tvision/textview.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/tvision/config.h b/include/tvision/config.h index bea015ff..b3b09648 100644 --- a/include/tvision/config.h +++ b/include/tvision/config.h @@ -31,4 +31,10 @@ const int maxReplaceStrLen = 80; const int minPasteEventCount = 3; +#if !defined( __BORLANDC__ ) +const int maxCharSize = 4; // A UTF-8-encoded character is up to 4 bytes long. +#else +const int maxCharSize = 1; // All characters are single-byte-encoded. +#endif + #endif // __CONFIG_H diff --git a/include/tvision/scrncell.h b/include/tvision/scrncell.h index e2687778..575a5d90 100644 --- a/include/tvision/scrncell.h +++ b/include/tvision/scrncell.h @@ -90,9 +90,9 @@ inline void TCellChar::moveMultiByteChar(uint32_t mbc, bool wide) inline void TCellChar::moveMultiByteChar(TStringView mbc, bool wide) { - static_assert(sizeof(_text) >= 4, ""); + static_assert(sizeof(_text) >= maxCharSize, ""); memset(this, 0, sizeof(*this)); - if (0 < mbc.size() && mbc.size() <= 4) + if (0 < mbc.size() && mbc.size() <= maxCharSize) { _flags |= -int(wide) & fWide; switch (mbc.size()) diff --git a/include/tvision/system.h b/include/tvision/system.h index 2f48c94d..c0392e46 100644 --- a/include/tvision/system.h +++ b/include/tvision/system.h @@ -206,7 +206,7 @@ struct KeyDownEvent CharScanType charScan; }; ushort controlKeyState; - char text[4]; // NOT null-terminated. + char text[maxCharSize]; // NOT null-terminated. uchar textLength; TStringView getText() const; diff --git a/include/tvision/ttext.h b/include/tvision/ttext.h index 7d33c0f6..938460b5 100644 --- a/include/tvision/ttext.h +++ b/include/tvision/ttext.h @@ -9,12 +9,6 @@ #if defined( Uses_TText ) && !defined( __TText ) #define __TText -#if !defined( __BORLANDC__ ) -const int maxCharLength = 4; // Maximum length of a UTF-8 codepoint. -#else -const int maxCharLength = 1; // All characters are single-byte-encoded. -#endif - struct TTextMetrics { uint width; diff --git a/source/tvision/teditor1.cpp b/source/tvision/teditor1.cpp index 72415f5c..a71774b0 100644 --- a/source/tvision/teditor1.cpp +++ b/source/tvision/teditor1.cpp @@ -233,7 +233,7 @@ void TEditor::changeBounds( const TRect& bounds ) TStringView TEditor::bufChars( uint P ) { - static thread_local char buf[maxCharLength]; + static thread_local char buf[maxCharSize]; if (encoding == encSingleByte) { buf[0] = bufChar(P); @@ -250,7 +250,7 @@ TStringView TEditor::bufChars( uint P ) TStringView TEditor::prevBufChars( uint P ) { - static thread_local char buf[maxCharLength]; + static thread_local char buf[maxCharSize]; if (encoding == encSingleByte) { buf[0] = bufChar(P - 1); diff --git a/source/tvision/textview.cpp b/source/tvision/textview.cpp index d70a76b1..c85ddac6 100644 --- a/source/tvision/textview.cpp +++ b/source/tvision/textview.cpp @@ -106,7 +106,7 @@ static void discardPossiblyTruncatedCharsAtEnd( const char (&s)[256], if( sLen == sizeof(s) ) { sLen = 0; - while( sLen < sizeof(s) - (maxCharLength - 1) ) + while( sLen < sizeof(s) - (maxCharSize - 1) ) sLen += TText::next( TStringView( &s[sLen], sizeof(s) - sLen ) ); } #else