Raised This Month: $ Target: $400
 0% 

Reverse string stock (Unicode safe)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 10-25-2013 , 20:21   Reverse string stock (Unicode safe)
Reply With Quote #1

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 ...
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 10-25-2013 at 20:52.
pokemonmaster is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 10-25-2013 , 22:13   Re: Reverse string stock (Unicode safe)
Reply With Quote #2

Ps. ??

PHP Code:
new szUnicodeChar[] = "ï"
??

PHP Code:
new szUnicodeChar[2];
copy(szUnicodeChar,charsmax(szUnicodeChar),"ï"); 
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 10-26-2013 , 03:31   Re: Reverse string stock (Unicode safe)
Reply With Quote #3

Quote:
Originally Posted by ^SmileY View Post
Ps. ??

PHP Code:
new szUnicodeChar[] = "ï"
??

PHP Code:
new szUnicodeChar[2];
copy(szUnicodeChar,charsmax(szUnicodeChar),"ï"); 
doesn't matter, go read strings tutorial in pawn sections
TheDS1337 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-26-2013 , 04:31   Re: Reverse string stock (Unicode safe)
Reply With Quote #4

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;
            }
        }
    }

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 10-26-2013 at 04:33.
ConnorMcLeod is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 10-26-2013 , 14:19   Re: Reverse string stock (Unicode safe)
Reply With Quote #5

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?

Thanks for trying to help me though.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-26-2013 , 14:21   Re: Reverse string stock (Unicode safe)
Reply With Quote #6

My stock is trying to find if the utf-8 letter uses 2, 3 or 4 cells.
So, there are some errors ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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