CSV Parsing

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Pikachu

Supporter
Addon Developer
Jan 25, 2017
870
144
43
USA
Request:
The addition of CSV parsing to skript, basically like skript-json but for CSV

Example:
Input CSV:
Code:
Player Name,Position,Nicknames,Years Active
Skippy Peterson,First Base,"""Blue Dog"", ""The Magician""",1908-1913
Bud Grimsby,Center Field,"""The Reaper"", ""Longneck""",1910-1917
Vic Crumb,Shortstop,"""Fat Vic"", ""Very, Very Fat Vic""",1911-1912

Output list:
code_language.skript:
{_l::0::0} = """Player Name"""
{_l::0::1} = "Position"
{_l::0::2} = "Nicknames"
{_l::0::3} = "Years Active"
{_l::1::0} = "Skippy Peterson"
And so on

Syntax:
Pretty much a direct steal from skript-json:
code_language.skript:
(map|copy) [the] csv [(of|from)] %text% to [the] [var[iable]] %list variable%"
Not really important but would be cool:
code_language.skript:
[the] csv (form|representation) of %list variable%
code_language.skript:
%list variable%'[s] csv (form|representation)

Why:
You could make a simple CSV parser in skript, but it would be a lot of work to account for lots of different cases and needless work when well thought out parsers that would be faster and better than mine already exist.
 
  • Like
Reactions: KingAlterIV
You suggest it everytime, and we always give the same answer.
Indeed it would be cool, but useless. We would do the same thing in java as in Skript.
You just need to use some addon to get a list of lines from some file (since it is just a text file), then parse that line:
Basic way:
code_language.skript:
set {_values::*} to split {_line} at ","
Or more advanced one, in case you want to put Strings in these values (since you can put a comma without conflicting).

code_language.skript:
set {_chars::*} to {_line} split at ""
set {_current} to ""
set {_escape} to false
loop {_chars::*}:
    If loop-value is ",":
        if {_escape} is false:
            add {_current} to {_values::*}
            set {_current} to ""
    else:
        if loop-value is """":
            #just to invert the boolean
            #you can do it with one line using SkQuery
            #set {_escape} to not {_escape}
            if {_escape} is true:
                set {_escape} to false
            else:
                set {_escape} to true
        set {_current} to "%{_current}%%loop-value%"
Also, you can use MundoSK async feature to parse a file, cause everything is safe to used there, unless you dont use nothing from bukkit/minecraft (such as getting a player from a uuid or a world from a string).