Snippet Explode String

> this is absolutely bugged for seperators that are longer than one char.
No it isn't. It simply doesn't support it.

> If you can't handle length n seperators, please post that.
It was useless, unneeded, and extra work.
Besides, it is posted:
"Note that if 'separator' is more than one character long, only the first character will be used."

> You even say it would work with "char(s)".
Oh damn. (s) made someone complain. =|
 
I think you should add functionality so if you put maximum as -1 it is set to unlimited. (or some very high number)
 
There's an internal limit anyway.
JASS:
.
        //  Change the [10] to the maximum amount of substrings
        private string array S [10]
 
old strings don't get cleaned when the struct is destroyed, thus it is possible to retrieve old data :/

JASS:
// These line fix the problem
        method onDestroy takes nothing returns nothing
            local integer i = 0
            loop
                exitwhen i > .size
                    
                set .S[ i ] = null
                
                set i = i + 1
            endloop
        endmethod
 
> old strings don't get cleaned when the struct is destroyed, thus it is possible to retrieve old data :/
Ermm. Ok.
Not that anyone would want to retrieve old data, but the option is there. :)
 
Hypothetical funny situation:
Code:
[ALL][COLOR="RoyalBlue"]Say_No_To_War:[/COLOR] -zoom 5000
DEBUG: Action: -zoom( 5000 )
DEBUG: Zooming In( 3700 )
[ALL][COLOR="Red"]SerraAvenger:[/COLOR] -zoom
DEBUG: Action: -zoom( 5000 )
DEBUG: Zooming In( 3700 )
[ALL][COLOR="Red"]SerraAvenger:[/COLOR] Wth?? bugged map I'll never play this again!!!
...^^
I think the option should be abolished ; )

PS: Now using this in 3 systems of Krusade. BsArc still uses my old splitter though.
 
You see, .size is there for a reason.
From [0] to [size-1], are the parts of the string that was exploded.
Everything over that is either nothing, or old strings.

So as long as you don't go over '.size', which there's no reason why you should, then it's fine.
If .size is too small, then increase it.
If the .size limit is too small, then increase it in the snippet code.

You may also want to note that if you do:
ExplodeString(somestring, " ", 5)
But it only explodes into 3 parts, as there are no more spaces, then .size will be 3.

Edit: Besides, as someone pointed out; If I did want to implement what you said, I'd do it in the create method. Same effect, but with less function calls.
 
OffTopic: Ouch, my post just vanished >_>

You are REALLY asking the user to manage the consistency of YOUR system?
I hope I just misread...

If .size is too small, then increase it.
If the .size limit is too small, then increase it in the snippet code.

You may also want to note that if you do:
ExplodeString(somestring, " ", 5)
But it only explodes into 3 parts, as there are no more spaces, then .size will be 3.

This is neither related to the problem nor necessary to spot, I know these details.

Besides, putting cleaning into initialisation is not really clean.
No need to optimise where it isn't necessary, especially when it comes at the cost of readability : /

Cheers, Davey
 
> I hope I just misread...
I think you're just misunderstanding everything.

> This is neither related to the problem nor necessary to spot, I know these details.
Oh, but it is. The fact that the extra slots could hold old strings doesn't matter if you make sure to not use the index above [size-1]

> Besides, putting cleaning into initialisation is not really clean.
Yes it is.
Cleaning all the old values, so that all the extra arrays are blank. Same effect, but more efficient.
 
>Oh, but it is. The fact that the extra slots could hold old strings doesn't matter if you make sure to not use the index above [size-1]

The stuff I quoted was not related to how old strings are managed, it was related to size managment of ExpStrings
Also you should take care that nothing invalid is returned over [size-1], not the programmer who uses your code.

What would you do with a unit indexing system that returns random stuff for units that aren't indexed?

The coder might not even know when bad stuff is returned, because the player of the map inputs invalid data (eg just typing -zoom instead of -zoom VALUE). And It should be your duty to save the avid programmer lots of time trying to locate and debug the error source.

Besides I'm a DRY programmer. I'm not going to write a check for indicies whenever I'm trying to access an array. I'll let the accessing function do it.

>Yes it is.
>Cleaning all the old values, so that all the extra arrays are blank. Same effect, but more efficient.

If you think so...
I usually let my washing mashine wash my dish after eating, not only when I see I have no clean plates anymore.

And still I don't think the few extra calls here and there really matter that much. I'm not exploding 500 strings per second, am I?^^
If I was, then most probably my code is the problem, not the few extra function calls / trigger evaluations per exploding.
 
> Also you should take care that nothing invalid is returned over [size-1], not the programmer who uses your code.
Not really. If someone chooses to deliberately misuse the system, then what can they expect, working code? :rolleyes:

> What would you do with a unit indexing system that returns random stuff for units that aren't indexed?
That's a silly comparison.

As for your -Zoom thing:
Code:
Explode: "-Zoom 5000"
[0] -> "-zoom"
[1] -> "5000"
.size = 2
Code:
Explode: "-Zoom"
[0] -> "-zoom"
.size = 1
Check if .size is greater than 1 before zooming. If it isn't, then don't do anything.
Also, if all the extra slots were "", then the game would zoom right into the ground (0 zoom).

> If you think so...
Same effect, different method.
The result will be that all unused indices will be "".
I don't know why you're dragging this on.

Also, your example works in my favour:
> I usually let my washing mashine wash my dish after eating, not only when I see I have no clean plates anymore.
Whether you wash the dishes before you eat, or you wash them after. You'll have them clean the next time you eat something.

> And still I don't think the few extra calls here and there really matter that much. I'm not exploding 500 strings per second, am I?^^
Same effect, one is shorter and more efficient. Which would you pick? :rolleyes:
 
If someone chooses to deliberately misuse the system, then what can they expect, working code? :rolleyes:

Deliberately is just such a hard word.
Accidentally fits the situation much better.
If you hit the "EVOKE FATAL ERROR" button by accident, you are glad if it pops a message "Really evoke fatal error?".
BTW, you might add this comment to your snippet:

.size will be the amount of array slots used. WARNING: Because I think it's not worth the hazzle implementing a safety check for bad indicies, note that you need to cnp the following lines whenever you're trying to access a ExpString field ( replace INDEX by the index you are requesting, CODE by the Code in which your are accessing the field and EXPSTRING by the name of the ExpString variabe you use. )
JASS:
if INDEX < EXPSTRING.size and INDEX > 0 then
    CODE
debug else
    debug call BJDebugMsg( "Bad Index requested!" )
endif

If you do not, the code may show random behaviour. Thanks for your cooperation and sorry for any inconvience caused.

...This must be the longest post for a snippet ever...

> What would you do with a unit indexing system that returns random stuff for units that aren't indexed?
That's a silly comparison.

The difference being that you return random stuff for indicies that aren't indexed instead of units that aren't indexed?

Check if .size is greater than 1 before zooming. If it isn't, then don't do anything.
DRY = DontRepeatYourself.
I'm not going to cnp 2 extra lines whenever I'm accessing a ExpString field.

Also, if all the extra slots were "", then the game would zoom right into the ground (0 zoom).

I'm checking for the parameter to have a valid value, thanks.
Because there always might be users who really end up typing really small values - even if just accidently, I'm trying to help my users.
No need for a "You stupid moron, by clicking this button the game fataled. It even says "EVOKE FATAL ERROR" !"

Whether you wash the dishes before you eat, or you wash them after you after. You'll have them clean the next time you eat something.
after I after :S?
So you hypothetically never wash your dish unless you're going to eat something, and see you have no clean plates anymore?
(assuming your dishwasher washes it almost instantly)

Same effect, one is shorter and more efficient. Which would you pick?

I'ld take the third option, which is more efficient, more readable, and shorter.
And If one is more conventional and the other one is a tiny bit more efficient (on a place where efficiency doesn't matter at all), I'll go with the conventional one.

Anyway, since we have the source I'll just fit this to my needs. No need in arguing with you about the way you code :p
 
> BTW, you might add this comment to your snippet:
No.

> after I after :S?
Scratch the last "I after", and reread.

> So you hypothetically never wash your dish unless you're going to eat something, and see you have no clean plates anymore?
This is where the whole dishwasher thing fails.
The ExpString is cleaned instantly. So time isn't an issue.
And ExpStrings don't rot and stink either. So that isn't an issue.

To be honest, you seem to be the only one with a problem about this. Nobody should use the indices equal to, or above .size. There's even a clear and easy way of checking this.
And you seem to be making up some pretty random situations in which clearing the indices would actually help. And even those aren't anything major.

> I'ld take the third option, which is more efficient, more readable, and shorter.
There are 2 options there. The first one, and the second one. :)
Neither of them are particularly 'unreadable' either. So it's just about efficiency.
And if it's more readable for you, I don't really care to be honest. This wasn't created with you reading it in mind.

> Anyway, since we have the source I'll just fit this to my needs. No need in arguing with you about the way you code
Indeed. :)
Feel free to modify the code however you like, as long as you don't resubmit it anywhere.

(I just remembered, I need to add support for multiple character separators. So much other stuff to do though. =|)
 
It's been a long time since I JASSed, so probably some syntax issues here, but this ought to be more efficient.

JASS:
function splitString takes string b, string s, integer m returns array
    local integer x = 0
    local integer y = 1
    local integer n = 0
    local string array pieces
    m = IMaxBJ(m, 1)
    set local integer l = StringLength(s)
    loop
        exitwhen y > l or n >= m
        loop
            exitwhen y > l or SubString(s, y - 1, y) == b
            set y = y + 1
        endloop
        set pieces[n] = SubString(s, x, y - 1)
        set n = n + 1
        set x = y
        set y = y + 1
    endloop
    return pieces
endfunction


splitString(" ", "Don't rock the boat baby", 4) = ["Don't","rock","the","boat"]
splitString("-", "Don't rock the boat baby", 4) = ["Don't rock the boat baby"]


to remove 'max' functionality, delete
  • , integer m
  • line "m = IMaxBJ(m, 1)"
  • " or n >= m" from line "exitwhen y > l or n >= m"

I don't see why a struct would be used for a basic function but again; very rusty.

I included "m = IMaxBJ(m, 1)" in case JASS allows optional parameters. Going by your code I'm assuming a non-opted integer would be 0.

EDIT: looked around and found that "local array pieces" must be "local string array pieces" ?
 
I'm aware that this could be made slightly more efficient, and I'm also aware that I need to add support for multiple-character separators. :p
I'm fully capable of editing minor codes, thanks.

I'll update this soon, MrApples.

Edit: It doesn't look like your code will work with multiple separator characters next to eachother;
splitString("^", "Hello^^^World", 2) ?
 
Just my opinion, but instead of search the best speed ever, i think having the less strings generated (with SubString) does more matter, because of how war3 handle them.

If it's possible thought. :)
Anyway i guess having the less SubString possible means also the best efficiency.
 
Edit: It doesn't look like your code will work with multiple separator characters next to eachother;
splitString("^", "Hello^^^World", 2) ?

The code needed 2 new lines, I've added them. I don't see a situation where that would be useful either.

splitString("^", "Hello^^^World", 2) should return ["Hello",""]. As would explode() or String.split()

I'm fully capable of editing minor codes, thanks.
What are you referencing to?

I need to add support for multiple-character separators.
What's the point? JASS has terrible string manipulation, any situation that would require this can be done in a better fashion.
 
Excuse the double post.

I've been told through the User CP that JASS doesn't allow returning arrays. Now I see why you would use a struct, but why not use a global?

explodeString() sets results to global udg_explodeString

It may seem awkward but JASS itself is awkward.
 
Other than the fact that you have to clear them up, dynamic arrays/structs are a much neater way of doing this.
Besides, what if one wants to keep the results for a while?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    Currently in the middle of getting the probate process going. We're doing the informal probate process.
    +3
  • Varine Varine:
    A probate is usually done with a will, yes? If so I am sorry for your loss
    +1
  • The Helper The Helper:
    Yeah Tom, me too sorry for your loss buddy my mom told me she finds out her olds friend died from Google searching them. She had not talked to one of her old friends in a year and found out she died from Google. Also another one in the same session. RIP all of them my sincere condolences Tom
    +1
  • Varine Varine:
    We have some elderly guests that regularly come hang out at the bar at the end of the night, and every once in a while we don't see someone for a few weeks and then someone shows up with their obituary.
  • Varine Varine:
    We usually let them do their memorials there in the morning if they want to and I'll make them some snacks and drinks. There was one guy named Tom that came in like every night and would sit by himself and get a bunch of soup and a glass of wine. idk why but he LOVED our fucking soup, like he would order a fucking quart of it at a time and would always get so sad when we stop doing it for the summer.
    +1
  • Varine Varine:
    But he also loved our calamari, which is another thing I hate but it sells super well so I can't change it. There was one day he came in and was asking me how to make it, because he tried to at home once in the off season when we stop running it and he really wanted it lol
  • Varine Varine:
    I think he's one of the only people I've made recipes for for free because he really wanted a broccoli cheddar, and it was like dude I don't have a recipe, it's just whatever I have, but here, this is how you do it
  • Varine Varine:
    I don't think he ever figured out how to do the calamari in a pan though, like idk how to do that either. He was afraid of the at home deep fryers though and it's like yeah, that's fair, I am too
  • Varine Varine:
    He was just such a sweet old man, we had two servers pregnant and they held a baby shower together, he was soooooo fucking excited to get to see a baby. Unfortunately he died a month or so before they were born
  • The Helper The Helper:
    So I decided to Google some people that I had not seen or heard from in a while and sure enough one of my old best friends, we had a falling out years ago but whatever, find out he died of Pancreatic Cancer in January. I have also lost a few of my closer acquaintances from growing up the last year. Getting old - people die - I kinda thought it was going to be this way a few years ago....
    +2
  • The Helper The Helper:
    Forum running super slow again
  • Ghan Ghan:
    Not really clear from the stats as to what is causing the slowness.
  • Ghan Ghan:
    We get a lot of guest traffic so it may just be the load is getting too high and not from any particular source.
  • Ghan Ghan:
    Looks like the server is maxed out on CPU.
  • Ghan Ghan:
    Oh it looks like a lot of the traffic is Silkroad Forums. That domain isn't protected by Cloudflare.
  • Ghan Ghan:
    But the old Silkroad site is still on its own server. I just had a test site set up on this server for it.
  • Ghan Ghan:
    I just disabled that test site. Let's see if that helps the load.
  • Ghan Ghan:
    Looks much better already.
  • The Helper The Helper:
    I had actually forgot about the Silkroad site. I had asked
  • The Helper The Helper:
    SD Ryoko about it and he said the couple of people left on there really like it, that was a few years ago, maybe I should check back
  • jonas jonas:
    I guess when you're getting old, and the last day of soup season draws near, you start wondering
  • jonas jonas:
    will I make it to the start of the next season? or was this the last time I'll ever have my favorite dish?
  • The Helper The Helper:
    I am doing my first Vibe Coding project. In installed the environment and tools according to instructions but it is all chat doing this for me at my direction. It is fun really and holy shit I might finish in 2 hours what it would have taken a day to in my Access and this would be an electron app complete new
  • Ghan Ghan:
    Good stuff.
  • Ghan Ghan:
    Just make sure it is secure. :)

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top