Difference between revisions of "User:Fred Gandt/Scripts/Functions"

From Second Life Wiki
Jump to navigation Jump to search
m (keep forgetting to add stuff...didn't affect/effect the function; Just the readability.)
m (fixed a misleading typo from the previous editor)
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{User:Fred Gandt/Template|content=
 
[[Image:FG_jpg.jpg|thumb|right]]
 
{{RightToc|right;}}
 
== My Contributions ==
 
'''I have implemented a V# system to make it more obvious if a function is updated. The V# forms part of the title of each function.'''
 
'''If you have any comments about the content of this page please post them [[User_talk:Fred_Gandt/Scripts/Functions | HERE]]'''
 
'''All my scripting is written for compilation as [[Mono|MONO]]'''
 
=== More Pages ===
 
'''[[User:Fred_Gandt/Scripts| Free Scripts]]''' (content constantly updating)
 
'''[[User:Fred_Gandt/Scripts/Continued_1| More Free Scripts]]''' (content constantly updating)
 
'''[[User:Fred_Gandt/Scripts/Continued_2| Even More Free Scripts]]''' (content constantly updating)
 
'''[[User:Fred_Gandt/Scripts/Continued_3| Even More More Free Scripts]]''' (content constantly updating)
 
'''[[User:Fred_Gandt/Scripts/Continued_4| Even More More More Free Scripts]]''' (content constantly updating)
 
'''Functions for specific tasks''' (this page)
 
=== Legal Stuff ===
 
'''[[Project:Contribution Agreement| The legal stuff about contributing to this wiki (worth reading).]]'''
 
=== PJIRA Issue Tracker ===
 
'''[https://jira.secondlife.com/secure/IssueNavigator.jspa?reset=true&reporterSelect=specificuser&reporter=Fred+Gandt The issues I have filed on the PJIRA]'''
 
== Tuition ==
 
'''[[User:Fred_Gandt/Tuition| Tuition scripts, notes, videos and screenshots etc.]]''' (hardly any content yet)


== Functions ==
== Functions ==
A collection of functions that perform defined actions. Things we can't use one [[:Category:LSL_Functions|Linden Library function]] to do.


'''Here is some stuffs wot does fings'''
=== GetUniqueListEntries ===
 
Feed a list in and get out a list which contains no duplicate entries. Fast.
{{Anchor|GetUniqueListEntries}}
=== GetUniqueListEntries ( V1 ) ===
 
'''Feed a list in and get out a list which contains no duplicate entries. Nice and fast.'''


<lsl>// V1 //
<syntaxhighlight lang="lsl2">// V1 //


list GetUniqueListEntries(list src)
list GetUniqueListEntries(list src)
Line 75: Line 34:
     {
     {
         llOwnerSay(llDumpList2String(GetUniqueListEntries(source), ", "));
         llOwnerSay(llDumpList2String(GetUniqueListEntries(source), ", "));
         // Return == "Object: How, much, wood, would, a, woodchuck, chuck, if, could, ?"
         // Return == "How, much, wood, would, a, woodchuck, chuck, if, could, ?"
     }
     }
}</lsl>
}</syntaxhighlight>
 
{{Anchor|MultiListReplace}}
=== MultiListReplace ( V1 ) ===


'''Replace entries in a list with other entries.'''
=== MultiListReplace ===
Replace entries in a list with other entries.


<lsl>// V1 //
<syntaxhighlight lang="lsl2">// V1 //


list MultiListReplace(list src, list thisnthats)
list MultiListReplace(list src, list thisnthats)
Line 111: Line 68:
     {
     {
         llOwnerSay(llDumpList2String(MultiListReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]), ", "));
         llOwnerSay(llDumpList2String(MultiListReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]), ", "));
         // Return == "Object: How, many, prims, would, a, primrezzer, rez, if, a, primrezzer, could, rez, prims, ?"
         // Return == "How, many, prims, would, a, primrezzer, rez, if, a, primrezzer, could, rez, prims, ?"
     }
     }
}</lsl>
}</syntaxhighlight>


{{Anchor|MultiStringReplace}}
=== MultiStringReplace ===
=== MultiStringReplace ( V4 ) ===
Replace parts of a string with other strings.
 
'''Replace parts of a string with other strings.'''
 
<lsl>// V4 //


<syntaxhighlight lang="lsl2">// V5 //
string MultiStringReplace(string src, list thisnthats)
string MultiStringReplace(string src, list thisnthats)
{
{
     integer index = 0;
     integer index = 0;
     integer lc = -1;
     integer lc = 0;
     integer ll = llGetListLength(thisnthats);
     integer ll = llGetListLength(thisnthats);
     do
     do
     {
     {
         string this = llList2String(thisnthats, (++lc));
         string this = llList2String(thisnthats, lc);
        ++lc;
         while((index = llSubStringIndex(src, this)) != -1)
         while((index = llSubStringIndex(src, this)) != -1)
         src = llInsertString(llDeleteSubString(src, index, (index + (llStringLength(this) - 1))),
         src = llInsertString(llDeleteSubString(src, index, (index + (llStringLength(this) - 1))), index, llList2String(thisnthats, lc));
                            index, llList2String(thisnthats, lc));
     }
     }
     while((++lc) < ll);
     while((++lc) < ll);
Line 147: Line 102:
     {
     {
         llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
         llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
         // Return == "Object: How many prims would a primrezzer rez if a primrezzer could rez prims?"
         // Return == "How many prims would a primrezzer rez if a primrezzer could rez prims?"
          
          
         llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "woodchuck", "primrezzer", "chuck", "rez"]));
         llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "woodchuck", "primrezzer", "chuck", "rez"]));
         // Return == "Object: How many prims would a primsrez rez if a primsrez could rez prims?"
         // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
          
          
         llOwnerSay(MultiStringReplace(source, ["farmers", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
         llOwnerSay(MultiStringReplace(source, ["farmers", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
         // Return == "Object: How many prims would a primsrez rez if a primsrez could rez prims?"
         // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
          
          
         llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "farmers", "primrezzer", "chuck", "rez"]));
         llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "farmers", "primrezzer", "chuck", "rez"]));
         // Return == "Object: How many prims would a primsrez rez if a primsrez could rez prims?"
         // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
          
          
         llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "farmers", "piggies", "chuck", "rez"]));
         llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "farmers", "piggies", "chuck", "rez"]));
         // Return == "Object: How many prims would a primrezzer rez if a primrezzer could rez prims?"
         // Return == "How many prims would a primrezzer rez if a primrezzer could rez prims?"
     }
     }
}</lsl>
}</syntaxhighlight>
 
{{Anchor|StrideOfList}}
=== StrideOfList ( V2 ) ===


'''Get strided entries from a list. And yes, I know about [[llList2ListStrided]]; Frankly, this works better.'''
=== StrideOfList ===
Get strided entries from a list. Note: this functionality is now directly provided by [[llList2ListSlice]].


<lsl>// V2 //
<syntaxhighlight lang="lsl2">// V2 //


list StrideOfList(list src, integer stride, integer start, integer end)
list StrideOfList(list src, integer stride, integer start, integer end)
Line 194: Line 147:
     {
     {
         llOwnerSay(llDumpList2String(StrideOfList(source, 1, 0, -1), ", "));
         llOwnerSay(llDumpList2String(StrideOfList(source, 1, 0, -1), ", "));
         // Return == "Object: How, much, wood, would, a, woodchuck, chuck, if, a, woodchuck, could, chuck, wood?"
         // Return == "How, much, wood, would, a, woodchuck, chuck, if, a, woodchuck, could, chuck, wood?"
   
   
         llOwnerSay(llDumpList2String(StrideOfList(source, 2, 0, -2), ", "));
         llOwnerSay(llDumpList2String(StrideOfList(source, 2, 0, -2), ", "));
         // Return == "Object: How, wood, a, chuck, a, could"
         // Return == "How, wood, a, chuck, a, could"
   
   
         llOwnerSay(llDumpList2String(StrideOfList(source, 4, 3, -1), ", "));
         llOwnerSay(llDumpList2String(StrideOfList(source, 4, 3, -1), ", "));
         // Return == "Object: would, if, chuck"
         // Return == "would, if, chuck"
   
   
         llOwnerSay(llDumpList2String(StrideOfList(source, 5, 3, -4), ", "));
         llOwnerSay(llDumpList2String(StrideOfList(source, 5, 3, -4), ", "));
         // Return == "Object: would, a"
         // Return == "would, a"
   
   
         llOwnerSay(llDumpList2String(StrideOfList(source, 3, -10, -7), ", "));
         llOwnerSay(llDumpList2String(StrideOfList(source, 3, -10, -7), ", "));
         // Return == "Object: would, chuck"
         // Return == "would, chuck"
   
   
         llOwnerSay(llDumpList2String(StrideOfList(source, 3, 7, -7), ", ")); // Start index is closer to end that end index.
         llOwnerSay(llDumpList2String(StrideOfList(source, 3, 7, -7), ", ")); // Start index is closer to end than end index (whoops).
         // Return == "Object: if"                                           // Start is returned only.
         // Return == "if"                                                   // Start is returned only.
     }
     }
}</lsl>
}</syntaxhighlight>


{{Anchor|ToNormal}}
=== Capitalization Functions ===
=== ToNormal ( V2 ) ===
==== ToNormal ====


'''Returns a string that holds true to a few simple rules.'''
Returns a string that holds true to a few simple rules.
*'''First person reference "I" is capitalized.'''
*First person reference "I" is capitalized.
*'''Specified names are capitalized.'''
*Specified names are capitalized.
*'''The first word of each ''proper'' sentence is capitalized.'''
*The first word of each ''proper'' sentence is capitalized.
'''I would imagine the results will be a mess if the source is not neatly written. I'll work on improving it as time goes on (it's a start).'''
:*This includes quotes. E.g. "Time is an illusion; Lunchtime, doubly so." - [http://en.wikipedia.org/wiki/Douglas_Adams Douglas Adams]
*'''New-lines disturb the results. The return is not as desired. It's on the "to-do" list.'''
:*Also new lines (see examples below).
I would imagine the results will be a mess if the source is not neatly written. I'll work on improving it as time goes on (it's a start).


<lsl>// V2 //
<syntaxhighlight lang="lsl2">// V4 //


string ToNormal(string src, list names)
string ToNormal(string src, list names)
{
{
     list abc = ["a","b","c","d","e","f","g","h","i","j","k","l","m",
     list abc = ["a","b","c","d","e","f","g","h","i","j","k","l","m", // The script needs to know what a letter is.
                 "n","o","p","q","r","s","t","u","v","w","x","y","z"];
                 "n","o","p","q","r","s","t","u","v","w","x","y","z"];
     list punc = [". ","; ","? ","! "];
     list punc = [". ","; ","? ","! ", " \"","\n"]; // Punctuation we create a new sentance after.
     src = llToLower(" " + src + " ");
     src = llToLower(" " + src + " ");
     string result = "";
     string result = "";
Line 235: Line 189:
     integer lc = 0;
     integer lc = 0;
     integer ll = 0;
     integer ll = 0;
    integer fp = 1;
     string ko = "";
     string ko = "";
     if((ll = llGetListLength(names)))
     if((ll = llGetListLength(names)))
Line 251: Line 204:
     while((index = llSubStringIndex(src, "i")) != -1)
     while((index = llSubStringIndex(src, "i")) != -1)
     {
     {
         if(fp)
         if(ko == "")
         {
         ko = llGetSubString(src, 0, (index - 1));
            ko = llGetSubString(src, 0, (index - 1));
            fp = 0;
        }
         if((llListFindList(abc, [llGetSubString(src, (index - 1), (index - 1))]) == -1)
         if((llListFindList(abc, [llGetSubString(src, (index - 1), (index - 1))]) == -1)
         && (llListFindList(abc, [llGetSubString(src, (index + 1), (index + 1))]) == -1))
         && (llListFindList(abc, [llGetSubString(src, (index + 1), (index + 1))]) == -1))
Line 285: Line 235:
         index = -1;
         index = -1;
     }
     }
     while((lc += 2) < ll);
     while((++lc) < ll);
     return llDumpList2String(names, "");
     return llDumpList2String(names, "");
}
}
Line 291: Line 241:
// Usage Example //
// Usage Example //
   
   
string source = "I can't help but wonder; \"What time should I and Sally arrive for dinner\"? For some reason, I like Tori Amos! Should I?";
//string source = "I can't help but wonder; \"What time should I and Sally arrive for dinner\"? For some reason, I like Tori Amos!! Should I?";
 
string source = "Confessions of a cigar smoker
 
I owe to smoking, more or less,
Through life the whole of my success;
With my Cigar I'm sage and wise -
Without, I'm dull as cloudy skies.
When smoking all my ideas soar,
When not, they sink upon the floor.
The greatest men have all been smokers,
And so were all the greatest jokers.
Then ye who'd bid adieu to care,
Come here and smoke it into air.";
   
   
default
default
Line 298: Line 261:
     {
     {
         source = llToUpper(source); // For whatever reason...
         source = llToUpper(source); // For whatever reason...
// source == "I CAN'T HELP BUT WONDER; "WHAT TIME SHOULD I AND SALLY ARRIVE FOR DINNER"? FOR SOME REASON, I LIKE TORI AMOS! SHOULD I?"


         llOwnerSay(ToNormal(source, ["Sally", "Tori Amos"]));
         llOwnerSay(ToNormal(source, []));
// Return == "Object: I can't help but wonder; "What time should I and Sally arrive for dinner"? For some reason, I like Tori Amos! Should I?"
       
        // OR (depending on source)
       
        //llOwnerSay(ToNormal(source, ["Sally", "Tori Amos"]));
 
// Return == "I can't help but wonder; "What time should I and Sally arrive for dinner"? For some reason, I like Tori Amos!! Should I?"
 
// OR (depending on source)
 
// Return == "Confessions of a cigar smoker
 
            //I owe to smoking, more or less,
            //Through life the whole of my success;
            //With my cigar I'm sage and wise -
            //Without, I'm dull as cloudy skies.
            //When smoking all my ideas soar,
            //When not, they sink upon the floor.
            //The greatest men have all been smokers,
            //And so were all the greatest jokers.
            //Then ye who'd bid adieu to care,
            //Come here and smoke it into air."
    }
}</syntaxhighlight>
 
==== ToTitle ====
Returns a string with ALL first letters of ALL words capitalized.
A slower (source length being equal) function than [[#ToNormal|ToNormal]] but ''possibly'' more reliable.
 
<syntaxhighlight lang="lsl2">// V2 //
string ToTitle(string src)
{
    list words = llParseString2List(llToLower(src), [], [".",";","?","!","\""," ","\n"]);
    integer ll = llGetListLength(words);
    integer lc = -1;
    string word = "";
    while((++lc) < ll)
    {
        string cap = llToUpper(llGetSubString((word = llList2String(words, lc)), 0, 0));
        words = llListReplaceList(words, [(cap + llDeleteSubString(word, 0, 0))], lc, lc);
    }
    return llDumpList2String(words, "");
}
// Usage Example //
string source = "I can't help but wonder; \"What time should I and Sally arrive for dinner\"? For some reason, I like Tori Amos!! Should I?";
//string source = "Confessions of a cigar smoker
//
//I owe to smoking, more or less,
//Through life the whole of my success;
//With my Cigar I'm sage and wise -
//Without, I'm dull as cloudy skies.
//When smoking all my ideas soar,
//When not, they sink upon the floor.
//The greatest men have all been smokers,
//And so were all the greatest jokers.
//Then ye who'd bid adieu to care,
//Come here and smoke it into air.";
default
{
    state_entry()
    {
        source = llToUpper(source); // For whatever reason...
        llOwnerSay(ToTitle(source));
// Return == "I Can't Help But Wonder; "What Time Should I And Sally Arrive For Dinner"? For Some Reason, I Like Tori Amos!! Should I?"
// OR (depending on source)
// Return == "Confessions Of A Cigar Smoker
            //I Owe To Smoking, More Or Less,
            //Through Life The Whole Of My Success;
            //With My Cigar I'm Sage And Wise -
            //Without, I'm Dull As Cloudy Skies.
            //When Smoking All My Ideas Soar,
            //When Not, They Sink Upon The Floor.
            //The Greatest Men Have All Been Smokers,
            //And So Were All The Greatest Jokers.
            //Then Ye Who'd Bid Adieu To Care,
            //Come Here And Smoke It Into Air."
     }
     }
}</lsl>
}</syntaxhighlight>}}

Latest revision as of 00:33, 26 October 2023

I get in-world very rarely these days. The knock-on effect of this, is that I am not in the best position to keep these scripts updated. Please message me in-world (forwarded to email) if you discover any bugs (that can't be simply fixed), and I'll do my best to find a solution.

My Contributions

If unsure about how to use these scripts

I have implemented a version number system to make it more obvious if a script is updated. The V# is a comment at the top of each script.

If you have any comments about the content of this page please post them HERE

All my scripts are written for compilation as MONO

More Scripts

Legal Stuff

The legal stuff about contributing to this wiki. (worth reading)

PJIRA Issue Tracker

The issues I have filed on the PJIRA

Tuition

Tuition scripts, notes, videos and screenshots etc. (hardly any content yet)

Functions

A collection of functions that perform defined actions. Things we can't use one Linden Library function to do.

GetUniqueListEntries

Feed a list in and get out a list which contains no duplicate entries. Fast.

// V1 //

list GetUniqueListEntries(list src)
{
    integer index = 0;
    list output = [];
    list entry = [];
    do
    {
        output += (entry = llList2List(src, 0, 0));
        src = llDeleteSubList(src, 0, 0);
        while((index = llListFindList(src, entry)) != -1)
        src = llDeleteSubList(src, index, index);
    }
    while(llGetListLength(src));
    return output;
}

// Usage Example //

list source = ["How", "much", "wood", "would", "a", "woodchuck", "chuck", "if", "a", "woodchuck", "could", "chuck", "wood", "?"];

default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(GetUniqueListEntries(source), ", "));
        // Return == "How, much, wood, would, a, woodchuck, chuck, if, could, ?"
    }
}

MultiListReplace

Replace entries in a list with other entries.

// V1 //

list MultiListReplace(list src, list thisnthats)
{
    integer index = 0;
    integer lc = 0;
    integer ll = llGetListLength(thisnthats);
    do
    {
        list this = llList2List(thisnthats, lc, lc);
        ++lc;
        while((index = llListFindList(src, this)) != -1)
        src = llListReplaceList(src, llList2List(thisnthats, lc, lc), index, index);
    }
    while((++lc) < ll);
    return src;
}

// Usage Example //

list source = ["How", "much", "wood", "would", "a", "woodchuck", "chuck", "if", "a", "woodchuck", "could", "chuck", "wood", "?"];

default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(MultiListReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]), ", "));
        // Return == "How, many, prims, would, a, primrezzer, rez, if, a, primrezzer, could, rez, prims, ?"
    }
}

MultiStringReplace

Replace parts of a string with other strings.

// V5 //
 
string MultiStringReplace(string src, list thisnthats)
{
    integer index = 0;
    integer lc = 0;
    integer ll = llGetListLength(thisnthats);
    do
    {
        string this = llList2String(thisnthats, lc);
        ++lc;
        while((index = llSubStringIndex(src, this)) != -1)
        src = llInsertString(llDeleteSubString(src, index, (index + (llStringLength(this) - 1))), index, llList2String(thisnthats, lc));
    }
    while((++lc) < ll);
    return src;
}

// Usage Examples //

string source = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?";

default
{
    state_entry()
    {
        llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
        // Return == "How many prims would a primrezzer rez if a primrezzer could rez prims?"
        
        llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "woodchuck", "primrezzer", "chuck", "rez"]));
        // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
        
        llOwnerSay(MultiStringReplace(source, ["farmers", "primrezzer", "much", "many", "wood", "prims", "chuck", "rez"]));
        // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
        
        llOwnerSay(MultiStringReplace(source, ["much", "many", "wood", "prims", "farmers", "primrezzer", "chuck", "rez"]));
        // Return == "How many prims would a primsrez rez if a primsrez could rez prims?"
        
        llOwnerSay(MultiStringReplace(source, ["woodchuck", "primrezzer", "much", "many", "wood", "prims", "farmers", "piggies", "chuck", "rez"]));
        // Return == "How many prims would a primrezzer rez if a primrezzer could rez prims?"
    }
}

StrideOfList

Get strided entries from a list. Note: this functionality is now directly provided by llList2ListSlice.

// V2 //

list StrideOfList(list src, integer stride, integer start, integer end)
{
    list l = [];
    integer ll = llGetListLength(src);
    if(start < 0)start += ll;
    if(end < 0)end += ll;
    if(end < start) return llList2List(src, start, start);
    while(start <= end)
    {
        l += llList2List(src, start, start);
        start += stride;
    }
    return l;
}

// Usage Examples //

list source = ["How", "much", "wood", "would", "a", "woodchuck", "chuck", "if", "a", "woodchuck", "could", "chuck", "wood?"];
 
default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(StrideOfList(source, 1, 0, -1), ", "));
        // Return == "How, much, wood, would, a, woodchuck, chuck, if, a, woodchuck, could, chuck, wood?"
 
        llOwnerSay(llDumpList2String(StrideOfList(source, 2, 0, -2), ", "));
        // Return == "How, wood, a, chuck, a, could"
 
        llOwnerSay(llDumpList2String(StrideOfList(source, 4, 3, -1), ", "));
        // Return == "would, if, chuck"
 
        llOwnerSay(llDumpList2String(StrideOfList(source, 5, 3, -4), ", "));
        // Return == "would, a"
 
        llOwnerSay(llDumpList2String(StrideOfList(source, 3, -10, -7), ", "));
        // Return == "would, chuck"
 
        llOwnerSay(llDumpList2String(StrideOfList(source, 3, 7, -7), ", ")); // Start index is closer to end than end index (whoops).
        // Return == "if"                                                    // Start is returned only.
    }
}

Capitalization Functions

ToNormal

Returns a string that holds true to a few simple rules.

  • First person reference "I" is capitalized.
  • Specified names are capitalized.
  • The first word of each proper sentence is capitalized.
  • This includes quotes. E.g. "Time is an illusion; Lunchtime, doubly so." - Douglas Adams
  • Also new lines (see examples below).

I would imagine the results will be a mess if the source is not neatly written. I'll work on improving it as time goes on (it's a start).

// V4 //

string ToNormal(string src, list names)
{
    list abc = ["a","b","c","d","e","f","g","h","i","j","k","l","m", // The script needs to know what a letter is.
                "n","o","p","q","r","s","t","u","v","w","x","y","z"];
    list punc = [". ","; ","? ","! ", " \"","\n"]; // Punctuation we create a new sentance after.
    src = llToLower(" " + src + " ");
    string result = "";
    integer index = 0;
    integer lc = 0;
    integer ll = 0;
    string ko = "";
    if((ll = llGetListLength(names)))
    {
        do
        {
            string name = llToLower(llList2String(names, lc));
            while((index = llSubStringIndex(src, name)) != -1)
            src = llInsertString(llDeleteSubString(src, index, (index + (llStringLength(name) - 1))),
                                 index, llList2String(names, lc));
        }
        while((++lc) < ll);
        index = 0;
    }
    while((index = llSubStringIndex(src, "i")) != -1)
    {
        if(ko == "")
        ko = llGetSubString(src, 0, (index - 1));
        if((llListFindList(abc, [llGetSubString(src, (index - 1), (index - 1))]) == -1)
        && (llListFindList(abc, [llGetSubString(src, (index + 1), (index + 1))]) == -1))
        {
            src = llDeleteSubString(src, index, index);
            result += ("I" + llGetSubString(src, index, (llSubStringIndex(src, "i") - 1)));
        }
        else
        {
            src = llDeleteSubString(src, index, index);
            result += ("i" + llGetSubString(src, index, (llSubStringIndex(src, "i") - 1)));
        }
    }
    names = llParseString2List(llStringTrim((result = (ko + result)), STRING_TRIM), [], punc); // Reusing variable to save bytes.
    lc = 0;
    index = -1;
    ll = llGetListLength(names);
    string ABC = llToUpper(llDumpList2String(abc, ""));
    do
    {
        string entry = llList2String(names, lc);
        do
        {
            ++index;
            result = llToUpper(llGetSubString(entry, index, index));
        }
        while(llSubStringIndex(ABC, result) == -1);
        names = llListReplaceList(names, [llInsertString(llDeleteSubString(entry, index, index), index, result)], lc, lc);
        index = -1;
    }
    while((++lc) < ll);
    return llDumpList2String(names, "");
}

// Usage Example //
 
//string source = "I can't help but wonder; \"What time should I and Sally arrive for dinner\"? For some reason, I like Tori Amos!! Should I?";

string source = "Confessions of a cigar smoker

I owe to smoking, more or less,
Through life the whole of my success;
With my Cigar I'm sage and wise -
Without, I'm dull as cloudy skies.
When smoking all my ideas soar,
When not, they sink upon the floor.
The greatest men have all been smokers,
And so were all the greatest jokers.
Then ye who'd bid adieu to care,
Come here and smoke it into air.";
 
default
{
    state_entry()
    {
        source = llToUpper(source); // For whatever reason...

        llOwnerSay(ToNormal(source, []));
        
        // OR (depending on source)
        
        //llOwnerSay(ToNormal(source, ["Sally", "Tori Amos"]));

// Return == "I can't help but wonder; "What time should I and Sally arrive for dinner"? For some reason, I like Tori Amos!! Should I?"

// OR (depending on source)

// Return == "Confessions of a cigar smoker

            //I owe to smoking, more or less,
            //Through life the whole of my success;
            //With my cigar I'm sage and wise -
            //Without, I'm dull as cloudy skies.
            //When smoking all my ideas soar,
            //When not, they sink upon the floor.
            //The greatest men have all been smokers,
            //And so were all the greatest jokers.
            //Then ye who'd bid adieu to care,
            //Come here and smoke it into air."
    }
}

ToTitle

Returns a string with ALL first letters of ALL words capitalized. A slower (source length being equal) function than ToNormal but possibly more reliable.

// V2 //
 
string ToTitle(string src)
{
    list words = llParseString2List(llToLower(src), [], [".",";","?","!","\""," ","\n"]);
    integer ll = llGetListLength(words);
    integer lc = -1;
    string word = "";
    while((++lc) < ll)
    {
        string cap = llToUpper(llGetSubString((word = llList2String(words, lc)), 0, 0));
        words = llListReplaceList(words, [(cap + llDeleteSubString(word, 0, 0))], lc, lc);
    }
    return llDumpList2String(words, "");
}
 
// Usage Example //
 
string source = "I can't help but wonder; \"What time should I and Sally arrive for dinner\"? For some reason, I like Tori Amos!! Should I?";
 
//string source = "Confessions of a cigar smoker
//
//I owe to smoking, more or less,
//Through life the whole of my success;
//With my Cigar I'm sage and wise -
//Without, I'm dull as cloudy skies.
//When smoking all my ideas soar,
//When not, they sink upon the floor.
//The greatest men have all been smokers,
//And so were all the greatest jokers.
//Then ye who'd bid adieu to care,
//Come here and smoke it into air.";
 
default
{
    state_entry()
    {
        source = llToUpper(source); // For whatever reason...
 
        llOwnerSay(ToTitle(source));
 
// Return == "I Can't Help But Wonder; "What Time Should I And Sally Arrive For Dinner"? For Some Reason, I Like Tori Amos!! Should I?"
 
// OR (depending on source)
 
// Return == "Confessions Of A Cigar Smoker
 
            //I Owe To Smoking, More Or Less,
            //Through Life The Whole Of My Success;
            //With My Cigar I'm Sage And Wise -
            //Without, I'm Dull As Cloudy Skies.
            //When Smoking All My Ideas Soar,
            //When Not, They Sink Upon The Floor.
            //The Greatest Men Have All Been Smokers,
            //And So Were All The Greatest Jokers.
            //Then Ye Who'd Bid Adieu To Care,
            //Come Here And Smoke It Into Air."
    }
}

More Scripts...

If you have any comments about the content of this page please post them HERE