AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reverse string stock (Unicode safe) (https://forums.alliedmods.net/showthread.php?t=228722)

pokemonmaster 10-25-2013 20:21

Reverse string stock (Unicode safe)
 
Anyone got an idea on how to make a stock that is unicode safe?

edit:
I found something on a website, but, it is for C.
http://rosettacode.org/wiki/Reverse_a_string#C
Can this be converted? I couldn't understand a thing of it

edit2:
I succeeded in something, it is ineffecient, but working at least for now :)
In case someone needed it (Not sure if it would work on all unicode characters)

Spoiler


** Still in need of a good way to reverse a string ...

^SmileY 10-25-2013 22:13

Re: Reverse string stock (Unicode safe)
 
Ps. ??

PHP Code:

new szUnicodeChar[] = "ï"

??

PHP Code:

new szUnicodeChar[2];
copy(szUnicodeChar,charsmax(szUnicodeChar),"ï"); 


TheDS1337 10-26-2013 03:31

Re: Reverse string stock (Unicode safe)
 
Quote:

Originally Posted by ^SmileY (Post 2052964)
Ps. ??

PHP Code:

new szUnicodeChar[] = "ï"

??

PHP Code:

new szUnicodeChar[2];
copy(szUnicodeChar,charsmax(szUnicodeChar),"ï"); 


doesn't matter, go read strings tutorial in pawn sections

ConnorMcLeod 10-26-2013 04:31

Re: Reverse string stock (Unicode safe)
 
Try this (for utf-8 only) :
This supposes the string is well encoded.

Based on : http://en.wikipedia.org/wiki/UTF-8

PHP Code:

RevertStringstring[], output[], maxlen )
{
    new 
len strlen(string);
    if( 
len maxlen )
    {
        return 
0;
    }

    
maxlen len;
    new 
i;
    for(--
lenlen>=0len--)
    {
        
output[i] = string[len];
    }

    new 
c;
    for(
i=0i<maxleni++)
    {
        
output[i];
        if( 
0xC0 == 0xC0 )
        {
            if( 
0xF0 == 0xF0 )
            {
                
output[i] = output[i-3];
                
output[i-3] = c;
                
output[i-2];
                
output[i-2] = output[i-1];
                
output[i-1] = c;
            }
            else if( 
0xE0 == 0xE0 )
            {
                
output[i] = output[i-2];
                
output[i-2] = c;
            }
            else
            {
                
output[i] = output[i-1];
                
output[i-1] = c;
            }
        }
    }



pokemonmaster 10-26-2013 14:19

Re: Reverse string stock (Unicode safe)
 
I guess it is working, but not correctly (I guess).

From the link you gave, according to the table (first one), arabic letters use 3 bytes (cells), but your stocks thinks that they use only 2 bytes (cells)

Either the hex values are wrong, or my string is completely ruined? :3

Thanks for trying to help me though. :bee:

ConnorMcLeod 10-26-2013 14:21

Re: Reverse string stock (Unicode safe)
 
My stock is trying to find if the utf-8 letter uses 2, 3 or 4 cells.
So, there are some errors ?


All times are GMT -4. The time now is 23:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.