Jump to content

list2CSVSafe & CSV2ListSafe -- nesting functions, yay


Gistya Eusebio
 Share

You are about to reply to a thread that has been inactive for 3952 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

//this code is free to use under the
//GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
//~Gistya Eusebio~ 6-23-2013

//Normally if you add two or more CSV's to a list, then convert that list into a CSV, then back to a list,
//you end up losing the structure of the original list since each member of the CSVs becomes a
//member of the new list.

//For example if you take the two-item list: ["foo","bar"], and make it into a CSV: "foo,bar", then
//make a list by doing ["foo,bar"] + ["red"], you'll get the two-item list, ["foo,bar","red"],
//and if you make that it into a CSV, you'll get the string: "foo,bar, red" ...
// and if you convert that back to a list, you'll get the three-item list: ["foo","bar","red"],
//losing the borders of the original two-item list!

//However with my new functions here, now you can make a list of CSVs, then make a CSV of that list,
//and then rebuild the original list of CSVs, preserving the original item count and boundaries between items. //list2CSVSafe lets you make a list into an escaped CSV string that contains no commas.
//So for instance ["foo","bar"] becomes the string "foo%2C%20bar"
//And ["foo%2C%20bar","red"] becomes the string "foo%252C%2520bar%2C%20red"

//So you can see that you can put CSVs into a list and turn that list into another CSV, and so on,
//without merging the lists due to the presence of commas in the nested CSV's.
//This aids in list nesting.
//When you pull one of the escaped CSV's out of a list, then to change it back into a a proper list,
//use the reverse function, CSV2ListSafe. Any further-nested CSVs in that list will remain single
//list members that will then have to also be pulled out in similar fashion.

//So for example CSV2ListSafe("foo%252C%2520bar%2C%20red") returns the two-item list:
// ["foo%2C%20bar", "red"] ... fun times eh?

string list2CSVSafe(list info) { return llEscapeURL(llList2CSV(info)); } list CSV2ListSafe(string csv) { return llCSV2List(llUnescapeURL(csv)); }

 

 Whee

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3952 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...