Skip to content

Commit

Permalink
Define maxCharSize in config.h
Browse files Browse the repository at this point in the history
So that it can be used everywhere, without having to include the TText header.
  • Loading branch information
magiblot committed Oct 11, 2024
1 parent b01c41b commit a4d45ba
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/tvision/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions include/tvision/scrncell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion include/tvision/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions include/tvision/ttext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/tvision/teditor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/tvision/textview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4d45ba

Please sign in to comment.