Replace std::strlen with stringLength

This commit is contained in:
Markus Gans 2021-06-07 00:34:08 +02:00
parent 2dc8d7f2d3
commit de4ac269e4
8 changed files with 41 additions and 36 deletions

View File

@ -1,6 +1,7 @@
2021-06-06 Markus Gans <guru.mail@muenster.de>
* Bug fixing in FString and FTermDetection
* FTermDetection now has clean code by using FString instead of char*
* Replace std::strlen with stringLength
2021-06-03 Markus Gans <guru.mail@muenster.de>
* Some FString optimizations

View File

@ -249,7 +249,7 @@ inline FKey FKeyboard::getMouseProtocolKey() const
if ( ! mouse_support )
return NOT_SET;
const std::size_t buf_len = std::strlen(fifo_buf);
const std::size_t buf_len = stringLength(fifo_buf);
// x11 mouse tracking
if ( buf_len >= 6 && fifo_buf[1] == '[' && fifo_buf[2] == 'M' )
@ -282,7 +282,7 @@ inline FKey FKeyboard::getTermcapKey()
for (auto&& entry : *key_map)
{
const char* kstr = entry.string;
const std::size_t len = kstr ? std::strlen(kstr) : 0;
const std::size_t len = kstr ? stringLength(kstr) : 0;
if ( kstr && std::strncmp(kstr, fifo_buf, len) == 0 ) // found
{
@ -312,7 +312,7 @@ inline FKey FKeyboard::getKnownKey()
for (auto&& entry : fc::fkey_table)
{
const char* kstr = entry.string; // The string is never null
const std::size_t len = std::strlen(kstr);
const std::size_t len = stringLength(kstr);
if ( std::strncmp(kstr, fifo_buf, len) == 0 ) // found
{
@ -355,7 +355,7 @@ inline FKey FKeyboard::getSingleKey()
if ( utf8_input && (firstchar & 0xc0) == 0xc0 )
{
std::array<char, 5> utf8char{}; // Init array with '\0'
const std::size_t buf_len = std::strlen(fifo_buf);
const std::size_t buf_len = stringLength(fifo_buf);
if ( (firstchar & 0xe0) == 0xc0 )
len = 2;
@ -482,14 +482,14 @@ void FKeyboard::parseKeyBuffer()
{
key = fkey;
mouseTracking();
fifo_offset = int(std::strlen(fifo_buf));
fifo_offset = int(stringLength(fifo_buf));
break;
}
if ( fkey != FKey::Incomplete )
{
fkey_queue.push(fkey);
fifo_offset = int(std::strlen(fifo_buf));
fifo_offset = int(stringLength(fifo_buf));
}
}

View File

@ -739,7 +739,7 @@ void FMouseSGR::setRawData (FKeyboard::keybuffer& fifo_buf)
// Import the X11 xterm mouse protocol (SGR-Mode) raw mouse data
const std::size_t fifo_buf_size = sizeof(fifo_buf);
std::size_t len = std::strlen(fifo_buf);
std::size_t len = stringLength(fifo_buf);
std::size_t n{3};
while ( n < len && n <= MOUSE_BUF_SIZE + 1 )
@ -969,7 +969,7 @@ void FMouseUrxvt::setRawData (FKeyboard::keybuffer& fifo_buf)
// Import the X11 xterm mouse protocol (Urxvt-Mode) raw mouse data
const std::size_t fifo_buf_size = sizeof(fifo_buf);
std::size_t len = std::strlen(fifo_buf);
std::size_t len = stringLength(fifo_buf);
std::size_t n{2};
while ( n < len && n <= MOUSE_BUF_SIZE )

View File

@ -608,7 +608,7 @@ int FOptiMove::repeatedAppend ( std::string& dst
, const Capability& o
, int count ) const
{
const std::size_t src_len = std::strlen(o.cap);
const std::size_t src_len = stringLength(o.cap);
const std::size_t dst_len = dst.length();
int total{0};

View File

@ -381,7 +381,7 @@ void FTermcapQuirks::sunConsole()
fc::fkey_cap_table[i].string = "\b"; // backspace key
if ( std::strncmp(fc::fkey_cap_table[i].tname, "kD", 2) == 0
&& std::strlen(fc::fkey_cap_table[i].tname) == 2 )
&& stringLength(fc::fkey_cap_table[i].tname) == 2 )
fc::fkey_cap_table[i].string = "\177"; // delete-character key
if ( std::strncmp(fc::fkey_cap_table[i].tname, "@7", 2) == 0 )

View File

@ -390,14 +390,14 @@ bool FTermDetection::get256colorEnvString()
color_env.string7 = std::getenv("COLORFGBG");
color_env.string8 = std::getenv("KITTY_WINDOW_ID");
if ( color_env.string1 != nullptr
|| color_env.string2 != nullptr
|| color_env.string3 != nullptr
|| color_env.string4 != nullptr
|| color_env.string5 != nullptr
|| color_env.string6 != nullptr
|| color_env.string7 != nullptr
|| color_env.string8 != nullptr )
if ( ! color_env.string1.isEmpty()
|| ! color_env.string2.isEmpty()
|| ! color_env.string3.isEmpty()
|| ! color_env.string4.isEmpty()
|| ! color_env.string5.isEmpty()
|| ! color_env.string6.isEmpty()
|| ! color_env.string7.isEmpty()
|| ! color_env.string8.isEmpty() )
return true;
return false;
@ -408,9 +408,8 @@ FString FTermDetection::termtype_256color_quirks()
{
FString new_termtype{};
if ( color_env.string2
|| (color_env.string1
&& std::strncmp(color_env.string1, "gnome-terminal", 14) == 0) )
if ( ! color_env.string2.isEmpty()
|| color_env.string1 == "gnome-terminal" )
{
terminal_type.gnome_terminal = true;
// Each gnome-terminal should be able to use 256 colors
@ -439,21 +438,20 @@ FString FTermDetection::termtype_256color_quirks()
new_termtype = "mlterm-256color";
if ( termtype.left(4) == "rxvt"
&& color_env.string1
&& std::strncmp(color_env.string1, "rxvt-xpm", 8) == 0 )
&& color_env.string1.left(8) == "rxvt-xpm" )
{
new_termtype = "rxvt-256color";
terminal_type.rxvt = true;
}
if ( (color_env.string5 && std::strlen(color_env.string5) > 0)
|| (color_env.string6 && std::strlen(color_env.string6) > 0) )
if ( color_env.string5.getLength() > 0
|| color_env.string6.getLength() > 0 )
{
terminal_type.kde_konsole = true;
new_termtype = "konsole-256color";
}
if ( color_env.string3 && std::strlen(color_env.string3) > 0 )
if ( color_env.string3.getLength() > 0 )
decscusr_support = true;
return new_termtype;
@ -538,7 +536,7 @@ FString FTermDetection::getXTermColorName (FColor color) const
if ( pos > 4 && std::sscanf(temp.data(), parse, &index, buf.data()) == 2 )
{
std::size_t n = std::strlen(buf.data());
auto n = stringLength(buf.data());
// BEL + '\0' = string terminator
if ( n >= 6 && buf[n - 1] == BEL[0] && buf[n] == '\0' )

View File

@ -170,14 +170,14 @@ class FTermDetection final
private:
struct colorEnv
{
char* string1{nullptr};
char* string2{nullptr};
char* string3{nullptr};
char* string4{nullptr};
char* string5{nullptr};
char* string6{nullptr};
char* string7{nullptr};
char* string8{nullptr};
FString string1{};
FString string2{};
FString string3{};
FString string4{};
FString string5{};
FString string6{};
FString string7{};
FString string8{};
};
struct secondaryDA

View File

@ -119,12 +119,18 @@ std::unique_ptr<T> make_unique (Args&&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template<typename Iter>
template <typename Iter>
constexpr std::reverse_iterator<Iter> make_reverse_iterator (Iter iter)
{
return std::reverse_iterator<Iter>(iter);
}
template <typename T>
constexpr std::size_t stringLength (T&& array)
{
return std::string(std::forward<T>(array)).length();
}
using charSubstitution = std::unordered_map<wchar_t, wchar_t>;
struct FCharAttribute