wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-18-2009, 01:30 PM   #1
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default StringLib

StringLib is a set of functions/structs to help manipulate strings.

Requires JassHelper.

Available APIs:
  • function StringTrim takes string str returns string
    Creates and returns a new string by trimming all leading and trailing whitespaces from str.
  • function StringTrimLeft takes string str returns string
    Creates and returns a new string by trimming all leading whitespaces from str.
  • function StringTrimRight takes string str returns string
    Creates and returns a new string by trimming all trailing whitespaces from str.
  • function StringIndexOf takes string source, string toFind, boolean caseSensitive returns integer
    Finds the index of toFind in source from the start. Returns STRING_INDEX_NONE if could not be found.
  • function StringIndexOfReverse takes string source, string toFind, boolean caseSensitive returns integer
    Finds the index of toFind in source from the end. Returns STRING_INDEX_NONE if could not be found.
  • function StringReplace takes string source, string old, string new, boolean caseSensitive returns string
    Creates and returns a new string by replacing all old to new in source.
  • function StringHashCS takes string s returns integer
    Computes a case-sensitive hash of the string s.
  • function IsStringAscii takes string s returns boolean
    If s only consists of ascii characters, returns true. Otherwise, returns false.
  • function StringAsciiAt takes string s, integer index returns integer
    Returns the ascii value of indexth character of s.
  • function StringLengthUtf8 takes string s returns integer
    Returns the actual length of s in terms of unicode characters.
  • function IsStringValidUtf8 takes string s returns boolean
    If s is a valid UTF-8 string, returns true. Otherwise, returns false
  • struct StringSegments
    StringSegments splits a source string into multiple strings, divided by another delimiter (separator) string you provide. It can be used to split and extract text command components from a single input string from user, such as color components or a list of items.
    The interfaces are inspired by StringTokenizer in Java.

    Interfaces:
    • public static method create takes string source, string delimiter returns StringSegments
      Creates a StringSegments instance with supplied source and delimiter (separator) strings.
    • public method countSegments takes nothing returns integer
      Returns number of possible .nextSegment calls left.
    • public method hasMoreSegments takes nothing returns boolean
      If there are more segments to return, returns true. Otherwise, returns false.
    • public method nextSegment takes nothing returns string
      Gets next string segment with current delimiter (separator). Default is the one supplied on .create(). If there are no more segments, this method will return STRING_INVALID_SEGMENT.
    • public method nextSegmentEx takes string delimiter returns string
      Gets next string segment using delimiter as the delimiter (separator). After the call, delimiter becomes the current delimiter. If there are no more segments, this method will return STRING_INVALID_SEGMENT.

    How to use:
    1. Create an instance by calling StringSegments.create(source, delimiter)
    2. Check .hasMoreSegments(). If true, continue processing.
    3. Use .nextSegment() or .nextSegmentEx(delimiter) to get segments.
    4. When done, call .destroy() to clean up properly.

Expand Library Code:

Expand Example Code:

Last edited by ToukoAozaki : 09-19-2009 at 08:12 AM.
ToukoAozaki is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-18-2009, 04:27 PM   #2
Seshiro
User
 
Seshiro's Avatar
 
Join Date: Aug 2008
Posts: 158

Submissions (1)

Seshiro is on a distinguished road (20)

Default

Looks good, but could you maybe add a .reset() method, to reset the tokenizer, for more usage, and maybe add something that saves all members, wehn they are used, so second usage will be more faster :)

Greez
Seshiro is offline   Reply With Quote
Old 07-18-2009, 04:39 PM   #3
Kwah
Christmassy.
 
Kwah's Avatar
 
Join Date: Jun 2008
Posts: 644

Submissions (4)

Kwah will become famous soon enough (43)Kwah will become famous soon enough (43)

Default

Tokenizer is a pretty damn strange name for it.
Kwah is offline   Reply With Quote
Old 07-18-2009, 04:53 PM   #4
Seshiro
User
 
Seshiro's Avatar
 
Join Date: Aug 2008
Posts: 158

Submissions (1)

Seshiro is on a distinguished road (20)

Default

Maybe Php-Style: exploder :D
Seshiro is offline   Reply With Quote
Old 07-18-2009, 05:01 PM   #5
Kwah
Christmassy.
 
Kwah's Avatar
 
Join Date: Jun 2008
Posts: 644

Submissions (4)

Kwah will become famous soon enough (43)Kwah will become famous soon enough (43)

Default

Split, would seem like a more normal one to me, but meh. Good job on it though.

Last edited by Kwah : 07-18-2009 at 05:01 PM.
Kwah is offline   Reply With Quote
Old 07-18-2009, 05:07 PM   #6
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Thanks for the feedback. StringSplitter seems better to me, too. However, I don't have any good method names for that :(

Quote:
Looks good, but could you maybe add a .reset() method, to reset the tokenizer, for more usage, and maybe add something that saves all members, wehn they are used, so second usage will be more faster :)

Good idea, but won't be possible due to custom delimiter...

Last edited by ToukoAozaki : 07-18-2009 at 05:19 PM.
ToukoAozaki is offline   Reply With Quote
Old 07-18-2009, 06:40 PM   #7
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Your submissions should have paragraphs explaining the value, purpose, and intended use in layman's terms. Right now, I'm sitting here reading the first post to no avail.
__________________
Rising_Dusk is offline   Reply With Quote
Old 07-18-2009, 06:44 PM   #8
Kwah
Christmassy.
 
Kwah's Avatar
 
Join Date: Jun 2008
Posts: 644

Submissions (4)

Kwah will become famous soon enough (43)Kwah will become famous soon enough (43)

Default

Splits strings into sub-strings based on a character separator, which is often whitespace?
Kwah is offline   Reply With Quote
Old 07-18-2009, 07:28 PM   #9
Seshiro
User
 
Seshiro's Avatar
 
Join Date: Aug 2008
Posts: 158

Submissions (1)

Seshiro is on a distinguished road (20)

Default

You could Also Use Commas for kind of Comma Seperated Lists would be fucking cool for a map with many cimbinable gamemodes like DotA..just seperate gamemodes by comma or whitepsace...

And what would be great too, but i think it's kinda unnecessary, would be the wohle, but in Reversed Format...

Greez
Seshiro is offline   Reply With Quote
Old 07-18-2009, 11:24 PM   #10
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

What if I want the delimiter to be ", "?
__________________
Anitarf is offline   Reply With Quote
Old 07-19-2009, 02:04 AM   #11
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Anitarf
What if I want the delimiter to be ", "?

No problem at all. The code is designed to take care of delimiters longer than one character; the only drawback is the longer the delimiter, the more combinations will be added to the string table.

Last edited by ToukoAozaki : 07-19-2009 at 02:05 AM.
ToukoAozaki is offline   Reply With Quote
Old 08-20-2009, 10:59 PM   #12
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by ToukoAozaki
No problem at all. The code is designed to take care of delimiters longer than one character; the only drawback is the longer the delimiter, the more combinations will be added to the string table.
It would be quite possible to avoid that if the string were compared to the delimiter one character at a time.
__________________
Anitarf is offline   Reply With Quote
Old 08-21-2009, 03:18 PM   #13
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Anitarf
It would be quite possible to avoid that if the string were compared to the delimiter one character at a time.

That is possible, but I'm afraid it would add extra complexity. Also, now I think a bit of extra entries on string table could be a trivial issue.

BTW I'm trying to make some test cases, making sure it guarantees the same behavior as StringTokenizer from Java.

Last edited by ToukoAozaki : 08-21-2009 at 03:19 PM.
ToukoAozaki is offline   Reply With Quote
Old 09-09-2009, 08:19 PM   #14
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

I would rename the library to "StringSegments," because that makes it more obvious as to what the heck this does. I've since figured out what it does, but at first glance the name Tokenizer is very confusing.

Also, I can see a very niche application for this. If you have tested this thoroughly and have verified that it works for all of your test cases, then fix the script name and I think that this can be approved. (Unless Anitarf wants to chime in and follow-up on his previous comment about the string table growth)
__________________
Rising_Dusk is offline   Reply With Quote
Old 09-14-2009, 05:53 AM   #15
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Rising_Dusk
I would rename the library to "StringSegments," because that makes it more obvious as to what the heck this does. I've since figured out what it does, but at first glance the name Tokenizer is very confusing.

Also, I can see a very niche application for this. If you have tested this thoroughly and have verified that it works for all of your test cases, then fix the script name and I think that this can be approved. (Unless Anitarf wants to chime in and follow-up on his previous comment about the string table growth)

Aye. StringSegments sounds good enough for me. BTW the work is still in progress...

Edit: It seems that the one in Java treats delimiter string as set of delimiters. This means a single delimiter cannot be of length more than 1. Now I have to decide whether to stick to the original code, or Java one. Any suggestions on this?

Last edited by ToukoAozaki : 09-14-2009 at 06:14 AM.
ToukoAozaki is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


All times are GMT. The time now is 06:27 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services