Consider csvtolist("10,", ",");
I would expect to get ["10", ""] as result, but I'll get ["10"].
Suggestion: Do away with the conditional here and simply *always* append the remaining string to the list. If you consider the loop above, the following should be evident then: Given a string which contains n separators, the resulting list will have n+1 items, which makes a lot of sense to me especially in the context of csv.