Difference between revisions of "LlParseString2List"

From Second Life Wiki
Jump to navigation Jump to search
(explicitly state all four preconditions)
Line 6: Line 6:
|func=llParseString2List|return_type=list
|func=llParseString2List|return_type=list
|p1_type=string|p1_name=src|p2_type=list|p2_name=separators|p3_type=list|p3_name=spacers
|p1_type=string|p1_name=src|p2_type=list|p2_name=separators|p3_type=list|p3_name=spacers
|func_footnote='''separators''' and '''spacers''' must be lists of strings, maximum of 8 each.
|func_footnote
|func_desc
|func_desc
|return_text=that is '''src''' broken into a list, discarding '''separators''', keeping '''spacers''', discards any null values generated.
|return_text=that is '''src''' broken into a list, discarding '''separators''', keeping '''spacers''', discards any null values generated.
|spec
|spec
|caveats=
|caveats=
*To avoid contradiction, every string of the '''{{LSL Param|spacers}}''' list of strings to keep must not exist in the '''{{LSL Param|separators}}''' list of strings to discard.
* Never provide more than 8 separators, never provide more than 8 spacers.
*Every element in the list will be a string, no matter what you think it should be. Cast the results of [[llList2String]] to get what you want.
* Provide lists of strings as the separators and spacers, not mixed lists of strings and floats and such.
** ''integer my_int = (integer)llList2String(my_list, i);''
* Don't let any spacer contain or equal a separator, and don't let any separator contain or equal a spacer.
*[[llList2String]] is used here, as [[llList2Integer]] can only handle integers in simple notation, ie. will not handle hexadecimal integers.  
* Do list each spacer and separator only once.
* Do expect to receive a list of strings in return. Call functions like [[llList2Integer]] to get the [[llGetListEntryType]] type that you want. Read those caveats too, ''e.g.'', cast to integer from llList2String if you want to receive a hexadecimal integer.
|constants
|constants
|examples=<pre>default
|examples=<pre>default
Line 33: Line 34:
}</pre>
}</pre>
|helpers=
|helpers=
'''Replacement functions without or very large separator/spacer count limits'''
'''Examples of processing more than 8 spacers or separators:'''
{{{!}}
{{{!}}
{{LSL DefineRow||[[ParseString2List]]|Functions exactly the same as [[llParseString2List]] and [[llParseStringKeepNulls]]}}
{{LSL DefineRow||[[ParseString2List]]|Functions exactly the same as [[llParseString2List]] and [[llParseStringKeepNulls]].}}
{{LSL DefineRow||[[Separate Words|separateWords]]|Functions the same as [[llParseString2List]] except in specific instances of overlaps between spacers and separators}}
{{LSL DefineRow||[[Separate Words|separateWords]]|Functions exactly the same as [[llParseString2List]] unless you violate the preconditions.
Also correct at a glance.}}
{{!}}}
{{!}}}
|also_functions=*{{LSLG|llParseStringKeepNulls}}
|also_functions=*{{LSLG|llParseStringKeepNulls}}

Revision as of 03:38, 2 October 2007

Summary

Function: list llParseString2List( string src, list separators, list spacers );

Returns a list that is src broken into a list, discarding separators, keeping spacers, discards any null values generated.

• string src source string
• list separators separators to be discarded
• list spacers spacers to be kept

Caveats

  • Never provide more than 8 separators, never provide more than 8 spacers.
  • Provide lists of strings as the separators and spacers, not mixed lists of strings and floats and such.
  • Don't let any spacer contain or equal a separator, and don't let any separator contain or equal a spacer.
  • Do list each spacer and separator only once.
  • Do expect to receive a list of strings in return. Call functions like llList2Integer to get the llGetListEntryType type that you want. Read those caveats too, e.g., cast to integer from llList2String if you want to receive a hexadecimal integer.
All Issues ~ Search JIRA for related Bugs

Examples

default
{
    state_entry()
    {
        // This will say:
        // <A><crazy><fox><.><Saw><the><moon><.><.>
        string my_string = "A crazy fox.  Saw the moon..";
        list my_list = llParseString2List(my_string,[" "],["."]);
        llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
        
        // This will say:
        //  <A><crazy><fox><.><><><Saw><the><moon><.><><.><>
        my_list = llParseStringKeepNulls(my_string,[" "],["."]);
        llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
    }
}

Useful Snippets

Examples of processing more than 8 spacers or separators:

•  ParseString2List Functions exactly the same as llParseString2List and llParseStringKeepNulls.
•  separateWords Functions exactly the same as llParseString2List unless you violate the preconditions.

Also correct at a glance.

Deep Notes

Search JIRA for related Issues

Signature

function list llParseString2List( string src, list separators, list spacers );