Difference between revisions of "User:SignpostMarv Martin/LSL2/csv ampersandise"

From Second Life Wiki
Jump to navigation Jump to search
(dumping trivial function on the wiki)
 
m (<lsl> tag to <source>)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
<div style="font-size:1.4em;"><lsl>/**
<source lang="lsl2">/**
/*    @package LSL
/*    @package LSL
/*    @subpackage strings
/*    @subpackage strings
Line 40: Line 40:
     }
     }
}
}
</lsl></div>
</source>
[[Category:LSL Library|random:location]]
[[Category:LSL Library|csv ampersandise]]

Latest revision as of 10:55, 25 January 2015

/**
/*     @package LSL
/*     @subpackage strings
/*     @author SignpostMarv Martin
/*     @license Creative Commons BY-SA UK 2.0 http://creativecommons.org/licenses/by-sa/2.0/uk/
/*     trivial function for converting a list to an ampersandised csv ("foo & baz" or "foo, bar & baz" type strings).
**/

/**
/*     @param list items The list to convert to an ampersandised csv
/*     @return string an ampersandised csv
**/
string csv_ampersandise(list items)
{
/**
*   Stores the last entry in the list in a variable since it is used in two different places.
*/
    string last = llList2String(items,-1);
/**
*   Return an empty string if the list is empty
*/
    if(llGetListLength(items) == 0)
    {
        return "";
    }
/**
*   return last if it is the only entry in the list.
*/
    else if(llGetListLength(items) == 1)
    {
        return last;
    }
/**
*   if the list length is 2, output will be along the lines of "foo & bar"
*   if the list length is 3 or more, output will be along the lines of "foo, bar & baz"
*/
    else
    {
        return llDumpList2String(llDeleteSubList(items,-1,-1),", ") + " & " + last;
    }
}