stock strtolower(source[])
{
for(new i; i < strlen(source); i++) switch(source[i]) {
case 168: source[i] = 184;
case 192..223: source[i] = (source[i] + 32);
default: source[i] = tolower(source[i]);
}
}
stock
ucfirst(string[])
{
string[0] = toupper(string[0]);
const dist = 'A' - 'a';
for(new i = 1, len = strlen(string), c; i < len; ++i)
{
if ('A' <= (c = string[i]) <= 'Z')
c -= dist;
string[i] = c;
}
}
|
Да. Вот:
Code:
stock
ucfirst(string[])
{
string[0] = toupper(string[0]);
const dist = 'A' - 'a';
for(new i = 1, len = strlen(string), c; i < len; ++i)
{
if ('A' <= (c = string[i]) <= 'Z')
c -= dist;
string[i] = c;
}
}
|
|
В каком смысле? Я о таком не слышал... Можете рассказать по подробнее?
|
|
Да. Вот:
Code:
stock
ucfirst(string[])
{
string[0] = toupper(string[0]);
const dist = 'A' - 'a';
for(new i = 1, len = strlen(string), c; i < len; ++i)
{
if ('A' <= (c = string[i]) <= 'Z')
c -= dist;
string[i] = c;
}
}
|
stock
ucfirst(string[])
{
string[0] = toupper(string[0]);
const dist = 'A' - 'a';
for (new i = 1, len = strlen(string), c; i < len; ++i)
{
if ('A' <= string[i] <= 'Z')
string[i] -= dist;
}
}
stock strtolower(source[], len = sizeof(source))
{
source[0] = toupper(source[0]);
for(new i = len; --i != 0;) source[i] = tolower(source[i]);
}
|
Что-то ты лишнего "наоптимизировал", так будет гораздо меньше действий:
PHP Code:
|
|
Почему бы не сделать просто так?
PHP Code:
|
|
Потому что:
- tolower будет медленнее вычитания - sizeof возвращает размер массива, а не длину строки |
stock ucfirst(source[])
{
source[0] = toupper(source[0]);
for(new i = strlen(source) + 1; --i != 0;) {
source[i] = tolower(source[i]);
}
}
|
Что-то ты лишнего "наоптимизировал", так будет гораздо меньше действий:
PHP Code:
|
stock ucfirst(source[])
{
if(islower(source[0])) {
if(source[0] == \'ё\') source[0] = \'Ё\';
else source[0] -= 32;
}
for(new i = strlen(source)+1; --i != 0;) {
if(source[i] == \'Ё\') source[i] = \'ё\';
else if(isupper(source[i])) source[i] += 32;
}
}
stock isupper(c)
{
return (\'A\' <= c <= \'Z\' || \'А\' <= c <= \'Я\' || c == \'Ё\');
}
stock islower(c)
{
return (\'a\' <= c <= \'z\' || \'а\' <= c <= \'я\' || c == \'ё\');
}
|
Точно, что-то тупанул.
update: PHP Code:
|
|
Ты решил проблему с длиной, но вычитание всё равно быстрее вызова функций, которая, кстати, вызывается для каждого символа.
|
stock
ucfirst(string[])
{
const dist = \'A\' - \'a\';
new i = strlen(string),
c;
if (string{0} != 0)
{
if (0xE0 <= (c = string{0}) <= 0xFF)
string{0} += dist;
else if (c == 0xB8)
string{0} = 0xA8;
else if (\'a\' <= c <= \'z\')
string{0} += dist;
do
{
if (0xC0 <= (c = string{i}) <= 0xDF)
c -= dist;
else if (c == 0xA8)
c = 0xB8;
else if (\'A\' <= c <= \'Z\')
c -= dist;
string{i} = c;
}
while (--i != 0);
}
else
{
if (0xE0 <= (c = string[0]) <= 0xFF)
string[0] += dist;
else if (c == 0xB8)
string[0] = 0xA8;
else if (\'a\' <= c <= \'z\')
string[0] += dist;
do
{
if (0xC0 <= (c = string[i]) <= 0xDF)
c -= dist;
else if (c == 0xA8)
c = 0xB8;
else if (\'A\' <= c <= \'Z\')
c -= dist;
string[i] = c;
}
while (--i != 0);
}
}
|
Вот функция дружит с упакованными строками и русским алфавитом:
Code:
stock
ucfirst(string[])
{
const dist = \'A\' - \'a\';
new i = strlen(string),
c;
if (string{0} != 0)
{
if (0xE0 <= (c = string{0}) <= 0xFF)
string{0} += dist;
else if (\'a\' <= c <= \'z\')
string{0} += dist;
do
{
if (0xC0 <= (c = string{i}) <= 0xDF)
c -= dist;
else if (\'A\' <= c <= \'Z\')
c -= dist;
string{i} = c;
}
while (--i != 0);
}
else
{
if (0xE0 <= (c = string[0]) <= 0xFF)
string[0] += dist;
else if (\'a\' <= c <= \'z\')
string[0] += dist;
do
{
if (0xC0 <= (c = string[i]) <= 0xDF)
c -= dist;
else if (\'A\' <= c <= \'Z\')
c -= dist;
string[i] = c;
}
while (--i != 0);
}
}
|
|
Забыл букву \'Ё\'. символы
|

static to_lower_source[0xFF char];
to_lower_init()// в OnGameModeInit()
{
for(new i = 0; i < 256; i++)
to_lower_source{i} = tolower(i);
}
stock ucfirst(source[])
{
for(new i = strlen(source) + 1; i--;)
source[i] = to_lower_source{source[i]};
source[0] = toupper(source[0]);
}
|
Самый быстрый вариант на тестах с jit compiller
![]() PHP Code:
|