• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

String Explode snippet failure

Status
Not open for further replies.
Level 3
Joined
Feb 19, 2016
Messages
32
Hey there
I need a little help or explanation why Romek's StringExplode snipper causes my map not to initialize and to know if there is any alternative.
To make it clear: I'm using JNGP and syntax check returns 118 compile errors on 1.26 version of warcraft.
Any help, please?
JASS:
library ExplodeString
//  ________________________________________
// +----------------------------------------+
// |      E X P L O D E   S T R I N G       |
// +----------------------------------------+
// |            By Romek - v3               |
// |________________________________________|
// +----------------------------------------+

    struct ExpString
        //  Change the [10] to the maximum amount of substrings
        private string array S [10]
      
        readonly integer size
      
        method operator [] takes integer i returns string
            return .S[i]
        endmethod
      
        static method create takes string source, string separator, integer maxamount returns ExpString
            local ExpString this = ExpString.allocate()
            local integer i = 0
            local integer last = 0
            local integer first = 0
            local integer length
            local boolean insep = true
            if maxamount < 1 then
                set maxamount = 1
            endif
            set maxamount = maxamount - 1
            if separator == "" or separator == null then
                set separator = " "
            else
                set separator = SubString(separator, 0, 1)
            endif
            set .size = 0
            set source = separator + source
            set length = StringLength(source)
            loop
               exitwhen i > length
                    if SubString(source, i, i + 1) == separator or i == length then
                        if not insep then
                            set last = i + 1
                            set insep = true
                            if .size  == maxamount then
                                set .S[.size ] = SubString(source, first, length)
                                exitwhen true
                            endif
                            set .S[.size ] = SubString(source, first, last - 1)
                            set .size  = .size  + 1
                        endif
                    elseif insep then
                        set insep = false
                        set first = i
                    endif
                set i = i + 1
            endloop
            return this
        endmethod
    endstruct
  
    function ExplodeString takes string source, string separator, integer maxamount returns ExpString
        return ExpString.create(source, separator, maxamount)
    endfunction

endlibrary
 
Last edited:
Status
Not open for further replies.
Top