Difference between revisions of "User:Ugleh Ulrik/ListKeyCase"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with '{{LSL_Function |func=ListKeyCase |mode=user |p1_type=list|p1_name=src|p1_desc=List to change case |p2_type=integer|p2_name=case|p2_desc=1 is Upper, 0 is Lower. |return_type=list ...')
 
m (<lsl> tag to <source>)
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:
|func_footnote=
|func_footnote=
See also: [[List|Lists]]
See also: [[List|Lists]]
|spec=<lsl>list ListKeyCase(list src,integer case){
|spec=<source lang="lsl2">//This version converts all list items into strings.
list new;
list ListKeyCase(list src,integer case){
integer i;
    list new;
if (case){
    integer i;
    do
    if (case){
    new += llToUpper(llList2String(src,i));
        do
    while (llGetListLength(src)>++i);
            new += llToUpper(llList2String(src,i));
    return new;
        while (llGetListLength(src)>++i);
}else{
        return new;
    do
    }/*else*/{
    new += llToLower(llList2String(src,i));
        do
     while (llGetListLength(src)>++i);
            new += llToLower(llList2String(src,i));
     return new;
        while (llGetListLength(src)>++i);
        return new;
     }
}</source>
 
<source lang="lsl2">//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;
    }
}
}
}
</source>
</lsl>
|caveats=*[[Key]] equality (and inequality) testing is case sensitive.
|caveats
|examples=<source lang="lsl2">
|examples=<lsl>
list test = ["Apples","Bananas","Cranberrys","Donuts"];
list test = ["Apples","Bananas","Cranberrys","Donuts"];
list newtest = ListKeyCase(test,0);
list newtest = ListKeyCase(test,0);
//newtest now is ["apples","bananas","cranberrys","donuts"]</lsl>
//newtest now is ["apples","bananas","cranberrys","donuts"]</source>
|helpers
|helpers
|notes
|notes
Line 35: Line 67:
|also_articles
|also_articles
|cat1=Examples
|cat1=Examples
|cat2
|cat2=User-Defined_Functions
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 14:45, 22 January 2015

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

//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;
    }
}
//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;
    }
}

Caveats

  • Key equality (and inequality) testing is case sensitive.

Examples

list test = ["Apples","Bananas","Cranberrys","Donuts"];
list newtest = ListKeyCase(test,0);
//newtest now is ["apples","bananas","cranberrys","donuts"]