Difference between revisions of "User:Void Singer/Functions"

From Second Life Wiki
Jump to navigation Jump to search
m (updated)
m (clean up)
Line 5: Line 5:


{{void-box
{{void-box
|title=List: Find Last Index
|title=uListFindListLast
|content=
|content=
* This function is a companion to [[llListFindList]].
* This function is a companion to [[llListFindList]].
** '''SPECIAL NOTE''': this is only designed to work on string data that will NOT contain the "•" character(alt+7)... please use a different character to suit your needs.
** '''SPECIAL NOTE''': this is only designed to work on string data that will NOT contain the "•" character(alt+7)... please use a different character to suit your needs.
=== Get Last Index of List Test in List Source ===
'''Get Last Index of List Test in List Source'''
<lsl>integer uGetLstIdxRev( list vLstSrc, list vLstTst ){
<lsl>integer uListFindListLast( list vLstSrc, list vLstTst ){
     integer vIdxFnd =
     integer vIdxFnd =
       (vLstSrc != []) +
       (vLstSrc != []) +
Line 34: Line 34:


{{void-box
{{void-box
|title=List: Multi-Find Index (First or Last)
|title=uListFindAny*
|content=
|content=
* These functions are companions to [[llListFindList]].
* These functions are companions to [[llListFindList]].
=== Get First Index in List Source of any element in List Test ===
** '''SPECIAL NOTE''': this is only designed to work on string data that will NOT contain the "•" character(alt+7)... please use a different character to suit your needs.
<lsl>integer uMatchLstIdxFwd( list vLstSrc, list vLstTst ){
<div style="display:none"><h3>uListFindAnyFirst</h3></div>'''Get the First index in List Source of Any element in List Test'''
<lsl>integer uListFindAnyFirst( list vLstSrc, list vLstTst ){
   return ((llParseString2List(  
   return ((llParseString2List(  
             llList2String(
             llList2String(
               llParseStringKeepNulls(
               llParseStringKeepNulls(
                 llDumpList2String( vLstSrc, ";" ),
                 llDumpList2String( vLstSrc, "" ),
                 vLstTst, [] ),
                 vLstTst, [] ),
               0 ),
               0 ),
             (list)";", [] ) != []) + 1) %
             (list)"", [] ) != []) + 1) %
         ((vLstSrc != []) + 1) - 1;
         ((vLstSrc != []) + 1) - 1;
}
}
Line 54: Line 55:
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</lsl>


=== Get Last Index in List Source of any element in List Test ===
<div style="display:none"><h3>uListFindAnyLast</h3></div>'''Get the Last index in List Source of Any element in List Test'''
<lsl>integer uMatchLstIdxRev( list vLstSrc, list vLstTst ){
<lsl>integer uListFindAnyLast( list vLstSrc, list vLstTst ){
   return (vLstSrc != []) -
   return (vLstSrc != []) -
     (llParseString2List(
     (llParseString2List(
       llList2String(
       llList2String(
         llParseString2List(  
         llParseString2List(  
           llDumpList2String( vLstSrc, ";" ),
           llDumpList2String( vLstSrc, "" ),
           vLstTst, [] ),
           vLstTst, [] ),
         -1 ),
         -1 ),
       (list)";",
       (list)"",
       [] ) != []) - 1;
       [] ) != []) - 1;
}
/*//--                      Anti-License Text                        --//*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
:[[User:Void_Singer/Functions#Return_to_Void_Singers_user_page|Return to top]]
}}
{{void-box
|title=Timestamp: Converters
|content=
* These Functions are companions to [[llGetUnixTime]] and [[llGetTimestamp]].
=== Unix time code to list format. ===
'''UPDATED:''' Jan. 27, 2010.
<lsl>
/*//-- Notes:
Time codes before the year 1902 or past the end of 2037
  are capped to the first second of 1902 and 2038 respectively
Output is [Y, M, D, h, m, s] list format.
This version could be improved.
//*/
list uUnix2StampLst( integer vIntDat ){
if (vIntDat / 2145916800){
vIntDat = 2145916800 * (1 | vIntDat >> 31);
}
integer vIntYrs = 1970 + ((((vIntDat %= 126230400) >> 31) + vIntDat / 126230400) << 2);
vIntDat -= 126230400 * (vIntDat >> 31);
integer vIntDys = vIntDat / 86400;
list vLstRtn = [vIntDat % 86400 / 3600, vIntDat % 3600 / 60, vIntDat % 60];
if (789 == vIntDys){
vIntYrs += 2;
vIntDat = 2;
vIntDys = 29;
}else{
vIntYrs += (vIntDys -= (vIntDys > 789)) / 365;
vIntDys %= 365;
vIntDys += vIntDat = 1;
integer vIntTmp;
while (vIntDys > (vIntTmp = (30 | (vIntDat & 1) ^ (vIntDat > 7)) - ((vIntDat == 2) << 1))){
++vIntDat;
vIntDys -= vIntTmp;
}
}
return [vIntYrs, vIntDat, vIntDys] + vLstRtn;
}
/*//--                      Anti-License Text                        --//*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
=== List format to Unix time code. ===
'''Updated:''' Mar. 17, 2010
<lsl>/*//-- Notes:
Time codes before the year 1902 or past the end of 2037
are capped to the first second of 1902 or 2038 respectively
Input format is [Y, M, D, h, m, s] in numerals. Strings are converted.
Elements past the end are safely ignored, for compatibility with
llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )
Short [Y, M, D] format is supported for compatibility with
llParseString2List( llGetDate(), ["-"], [] )
//*/
//-- unsafe version (missing day/month or bad values not handled)
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
  vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
  (((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
  (~-llList2Integer( vLstStp, 2 )) ) +
  llList2Integer( vLstStp, 3 ) * 3600 +
  llList2Integer( vLstStp, 4 ) * 60 +
  llList2Integer( vLstStp, 5 );
}
return vIntRtn;
}
//-- this version safely supports missing Day/Month
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
integer vIntDays = ~-llList2Integer( vLstStp, 2 );
vIntMnth += !~vIntMnth;
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
  vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
  (((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
  vIntDays + !~vIntDays ) +
  llList2Integer( vLstStp, 3 ) * 3600 +
  llList2Integer( vLstStp, 4 ) * 60 +
  llList2Integer( vLstStp, 5 );
}
return vIntRtn;
}
//-- Double Safe (as previous, with bad input capping)
integer uStamp2UnixInt( list vLstStp ){
integer vIntYear = llList2Integer( vLstStp, 0 ) - 1902;
integer vIntRtn;
if (vIntYear >> 31 | vIntYear / 136){
vIntRtn = 2145916800 * (1 | vIntYear >> 31);
}else{
integer vIntMnth = ~-llList2Integer( vLstStp, 1 );
integer vIntDays = ~-llList2Integer( vLstStp, 2 );
vIntMnth = llAbs( (vIntMnth + !~vIntMnth) % 12 );
vIntRtn = 86400 * ((integer)(vIntYear * 365.25 + 0.25) - 24837 +
  vIntMnth * 30 + (vIntMnth - (vIntMnth < 7) >> 1) + (vIntMnth < 2) -
  (((vIntYear + 2) & 3) > 0) * (vIntMnth > 1) +
  llAbs( (vIntDays + !~vIntDays) % 31 ) ) +
  llAbs( llList2Integer( vLstStp, 3 ) % 24 ) * 3600 +
  llAbs( llList2Integer( vLstStp, 4 ) % 60 ) * 60 +
  llAbs( llList2Integer( vLstStp, 5 ) % 60 );
}
return vIntRtn;
}
/*//--                      Anti-License Text                        --//*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
:[[User:Void_Singer/Functions#Return_to_Void_Singers_user_page|Return to top]]
}}
{{void-box
|title=Timestamp: Get Weekday from timestamp
|content=
* These Functions are related to [[llGetUnixTime]] and [[llGetTimestamp]].
=== Weekday from Unix timestamp ===
* Updated 29 May, 2010
<lsl>/*//-- Note:
Accurate from 1901 to 2099 (no limiting code)
//*/
string uUnix2WeekdayStr( integer vIntDat ){
    return llList2String( ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"],
                          vIntDate % 604800 / 86400  + (vIntDate >> 31) );
}
/*//--                      Anti-License Text                        --//*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
=== Weekday from ( Y, M, D ) format ===
<lsl>/*//-- Note:
Accurate from 1901 to 2099 (no limiting code)
This version could be improved.
//*/
string uStamp2WeekdayStr( integer vIntYear, integer vIntMonth, integer vIntDay ){
return llList2String ( ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"],
                      (vIntYear + (vIntYear >> 2) - ((vIntMonth < 3) & !(vIntYear & 3)) + vIntDay
                      + (integer)llGetSubString( "_033614625035", vIntMonth, vIntMonth )) % 7 );
}
}
/*//--                      Anti-License Text                        --//*/
/*//--                      Anti-License Text                        --//*/

Revision as of 16:17, 12 October 2010

uListFindListLast

  • This function is a companion to llListFindList.
    • SPECIAL NOTE: this is only designed to work on string data that will NOT contain the "•" character(alt+7)... please use a different character to suit your needs.

Get Last Index of List Test in List Source <lsl>integer uListFindListLast( list vLstSrc, list vLstTst ){

   integer vIdxFnd =
     (vLstSrc != []) +
     ([] != vLstTst) +
     ([] != llParseString2List(
              llList2String(
                llParseStringKeepNulls(
                  llDumpList2String( vLstSrc, "•" ),
                  (list)llDumpList2String( vLstTst, "•" ),
                  [] ),
                -1 ),
              (list)"•",
              [] ));
return (vIdxFnd

uListFindAny*

  • These functions are companions to llListFindList.
    • SPECIAL NOTE: this is only designed to work on string data that will NOT contain the "•" character(alt+7)... please use a different character to suit your needs.

uListFindAnyFirst

Get the First index in List Source of Any element in List Test

<lsl>integer uListFindAnyFirst( list vLstSrc, list vLstTst ){

 return ((llParseString2List( 
            llList2String(
              llParseStringKeepNulls(
                llDumpList2String( vLstSrc, "•" ),
                vLstTst, [] ),
              0 ),
            (list)"•", [] ) != []) + 1) %
        ((vLstSrc != []) + 1) - 1;

} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>

uListFindAnyLast

Get the Last index in List Source of Any element in List Test

<lsl>integer uListFindAnyLast( list vLstSrc, list vLstTst ){

 return (vLstSrc != []) -
   (llParseString2List(
      llList2String(
        llParseString2List( 
          llDumpList2String( vLstSrc, "•" ),
          vLstTst, [] ),
        -1 ),
      (list)"•",
      [] ) != []) - 1;

} /*//-- Anti-License Text --//*/ /*// Contributed Freely to the Public Domain without limitation. //*/ /*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*//-- --//*/</lsl>

Return to top

Questions or Comments?

Feel free to leave me a note on my User Talk page.