Skip to content

Commit

Permalink
fix text formatting and version information
Browse files Browse the repository at this point in the history
  • Loading branch information
nexquery authored May 12, 2023
1 parent bdeeafc commit 147478d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugin_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

#define MINOR (2)
#define MAJOR (0)
#define PATCH (0)
#define PATCH (2)
48 changes: 47 additions & 1 deletion src/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in
// Formatlanacak metini al
std::string metin = getString(amx, params[text_index]);

// Argüman sayýsý 1 deðilse formatlama aþamasýna geç
// Argüman sayýsý offset sayýsýna ulaþýyor ve geçiyorsa formatlama aþamasýna geç
if (max_args >= args_offset)
{
// Metini tarayacak index deðerimiz
Expand Down Expand Up @@ -93,6 +93,8 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in
amx_GetAddr(amx, params[args_count++], &deger);

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<int>(*deger)));

continue;
}

// Float
Expand All @@ -104,36 +106,50 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in
amx_GetAddr(amx, params[args_count++], &deger);

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<float>(amx_ctof(*deger))));

continue;
}

// String
else if (metin[index] == 's')
{
int yuzde = index - 1;
metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), getString(amx, params[args_count++])));
continue;
}

// Char
else if (metin[index] == 'c')
{
bool degistir = false;

int yuzde = index - 1;

cell* deger = nullptr;
amx_GetAddr(amx, params[args_count++], &deger);

if (*deger == 0x25)
{
degistir = true;
metin.replace(yuzde, index - yuzde + 1, "%%");
}
else
{
degistir = true;
metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<char>(*deger)));
}

if (degistir)
{
continue;
}
}

// %02d, %02f vs..
else if (metin[index] >= '0' && metin[index] <= '9')
{
bool degistir = false;

int yuzde = index - 1;

while (!isalpha(metin[index]))
Expand All @@ -147,19 +163,30 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in
amx_GetAddr(amx, params[args_count++], &deger);

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<int>(*deger)));

degistir = true;
}
else if (metin[index] == 'f' || metin[index] == 'F' || metin[index] == 'a' || metin[index] == 'A' || metin[index] == 'g' || metin[index] == 'G')
{
cell* deger = nullptr;
amx_GetAddr(amx, params[args_count++], &deger);

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<float>(amx_ctof(*deger))));

degistir = true;
}

if (degistir)
{
continue;
}
}

// %.*s, %.*f
else if (metin[index] == '.' && metin[index + 1] == '*')
{
bool degistir = false;

int yuzde = index - 1;

while (!isalpha(metin[index]))
Expand All @@ -169,6 +196,8 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in

if (metin[index] == 's')
{
degistir = true;

cell* deger = nullptr;
amx_GetAddr(amx, params[args_count++], &deger);

Expand All @@ -177,6 +206,8 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in

else if (metin[index] == 'f' || metin[index] == 'F' || metin[index] == 'a' || metin[index] == 'A' || metin[index] == 'g' || metin[index] == 'G')
{
degistir = true;

cell* deger = nullptr;
amx_GetAddr(amx, params[args_count++], &deger);

Expand All @@ -185,11 +216,18 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<int>(*deger), static_cast<float>(amx_ctof(*deger2))));
}

if (degistir)
{
continue;
}
}

// %.1s, %.1f
else if (metin[index] == '.' && metin[index + 1] != '*')
{
bool degistir = false;

int yuzde = index - 1;

while (!isalpha(metin[index]))
Expand All @@ -199,16 +237,24 @@ std::string service::formattedString(AMX* amx, cell* params, cell text_index, in

if (metin[index] == 's')
{
degistir = true;
metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), getString(amx, params[args_count++])));
}

else if (metin[index] == 'f' || metin[index] == 'F' || metin[index] == 'a' || metin[index] == 'A' || metin[index] == 'g' || metin[index] == 'G')
{
degistir = true;

cell* deger = nullptr;
amx_GetAddr(amx, params[args_count++], &deger);

metin.replace(yuzde, index - yuzde + 1, fmt::sprintf(metin.substr(yuzde, index - yuzde + 1), static_cast<float>(amx_ctof(*deger))));
}

if (degistir)
{
continue;
}
}
}
index++;
Expand Down

0 comments on commit 147478d

Please sign in to comment.