Difference between revisions of "User:Ugleh Ulrik/ListKeyCase"
Jump to navigation
Jump to search
(converting other types to strings might not be what the user wants.) |
m |
||
Line 33: | Line 33: | ||
if (case) { | if (case) { | ||
do { | do { | ||
if(((type = (llGetListEntryType(src, i) - | if(((type = (llGetListEntryType(src, i) - TYPE_STRING))) & -2) { | ||
new += llList2List(src, i, i); | new += llList2List(src, i, i); | ||
} else if(type) { | } else if(type) { | ||
Line 44: | Line 44: | ||
} /*else*/ { | } /*else*/ { | ||
do { | do { | ||
if(((type = (llGetListEntryType(src, i) - | if(((type = (llGetListEntryType(src, i) - TYPE_STRING))) & -2) { | ||
new += llList2List(src, i, i); | new += llList2List(src, i, i); | ||
} else if(type) { | } else if(type) { |
Revision as of 22:23, 7 May 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: list ListKeyCase( list src, integer case );Returns a list that is a copy of src with all lower-case letters or all upper-case letters.
• list | src | – | List to change case | |
• integer | case | – | 1 is Upper, 0 is Lower. |
See also: Lists
Specification
<lsl>//This version converts all list items into strings. list ListKeyCase(list src,integer case){
list new; integer i; if (case){ do new += llToUpper(llList2String(src,i)); while (llGetListLength(src)>++i); return new; }/*else*/{ do new += llToLower(llList2String(src,i)); while (llGetListLength(src)>++i); return new; }
}</lsl>
<lsl>//This version preserves the types of all list items. list ListKeyCase(list src, integer case) {
list new; integer i = 0; integer j = llGetListLength(src); integer type; if (case) { do { if(((type = (llGetListEntryType(src, i) - TYPE_STRING))) & -2) { new += llList2List(src, i, i); } else if(type) { new += (key)llToUpper(llList2String(src,i)); } else { new += llToUpper(llList2String(src,i)); } } while (j>++i); return new; } /*else*/ { do { if(((type = (llGetListEntryType(src, i) - TYPE_STRING))) & -2) { new += llList2List(src, i, i); } else if(type) { new += (key)llToLower(llList2String(src,i)); } else { new += llToLower(llList2String(src,i)); } } while (j>++i); return new; }
} </lsl>
Caveats
- Key equality (and inequality) testing is case sensitive.
Examples
<lsl> list test = ["Apples","Bananas","Cranberrys","Donuts"]; list newtest = ListKeyCase(test,0);
//newtest now is ["apples","bananas","cranberrys","donuts"]</lsl>