Difference between revisions of "LlFindNotecardTextSync"

From Second Life Wiki
Jump to navigation Jump to search
m (Wording, formatting)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/negative_index|false|line}}{{LSL_Function/notecard|name|uuid=true}}
|inject-2={{LSL_Function/notecard|name|uuid=true}}
|func_id=|func_sleep=0.0|func_energy=10.0
|func_id=|func_sleep=0.0|func_energy=10.0
|sort=FindNotecardTextSync
|sort=FindNotecardTextSync
Line 14: Line 14:
|func_footnote=Returns a list containing only [[NAK]] if the notecard is not cached.
|func_footnote=Returns a list containing only [[NAK]] if the notecard is not cached.
|spec=
|spec=
Searches the text of a cached notecard for lines containing the given pattern. It returns a list of any found occurrences of pattern in the notecard. If the notecard is not in
Searches the text of a cached notecard for lines containing the given pattern. If the notecard is not in the cache, returns a list containing a single [[NAK]], otherwise a list of matches of the pattern in the notecard. If no matches are found, or the notecard contains embedded items, an empty list is returned.
the cache it returns a list containing a single entry of NAK. If no matches are found, or the notecard contains embedded items, an empty list is returned.


Every match in the notecard is represented as a sequence of three integers [the row #, the column #, the length of the match]. In other words the returned list has a stride of 3.
Every match in the notecard is represented as a sequence of three integers:
<syntaxhighlight lang="lsl2">[integer row, integer column, integer length]</syntaxhighlight>
In other words the returned list has a stride of 3. A maximum of 64 matches are returned, resulting in a maximum list length of 192.


If the notecard does not exist it returns a list with a single [[NAK]] constant and will shout a message to the debug channel.  If the notecard has not been previously cached on the simulator it will return a list containing [[NAK]].
If the notecard does not exist, returns a list containing a single [[NAK]] and the script will shout an error on [[DEBUG_CHANNEL]] (but the script continues to run).


If there is an error in the regular expression this function returns an empty list and shouts a message to the debug channel.  
If there is an error in the regular expression, returns an empty list and the script will shout an error on [[DEBUG_CHANNEL]] (but the script continues to run).


Notecards are cached into a fixed-size buffer, with the oldest (least-recently read) notecard getting removed first. It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.
Notecards are cached into a fixed-size buffer, with the oldest (least-recently read) notecard getting removed first. It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.


|caveats=* If notecard contains embedded inventory items (such as textures and landmarks), an empty list will be returned, regardless of the search string.
|caveats=
* If notecard contains embedded inventory items (such as textures and landmarks), an empty list will be returned, regardless of the search string.
* No more than 64 matches are returned.
|constants
|constants
|examples
|examples

Latest revision as of 05:38, 16 November 2024

Summary

Function: list llFindNotecardTextSync( string name, string pattern, integer start, integer count, list options );
0.0 Forced Delay
10.0 Energy

Returns a list of lines and columns where the search pattern is found in the notecard.
Returns the list containing a list of integers containing the locations of the found text.

• string name a notecard in the inventory of the prim this script is in or a UUID of a notecard
• string pattern The regex pattern to search for
• integer start The number of match results to skip before returning matches. 0 will begin at the first match.
• integer count The maximum number of search results to return
• list options A list of options to pass into the search. (unused at this time, should be [])

Returns a list containing only NAK if the notecard is not cached.

Specification

Searches the text of a cached notecard for lines containing the given pattern. If the notecard is not in the cache, returns a list containing a single NAK, otherwise a list of matches of the pattern in the notecard. If no matches are found, or the notecard contains embedded items, an empty list is returned.

Every match in the notecard is represented as a sequence of three integers:

[integer row, integer column, integer length]

In other words the returned list has a stride of 3. A maximum of 64 matches are returned, resulting in a maximum list length of 192.

If the notecard does not exist, returns a list containing a single NAK and the script will shout an error on DEBUG_CHANNEL (but the script continues to run).

If there is an error in the regular expression, returns an empty list and the script will shout an error on DEBUG_CHANNEL (but the script continues to run).

Notecards are cached into a fixed-size buffer, with the oldest (least-recently read) notecard getting removed first. It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.

Caveats

  • If name is missing from the prim's inventory and it is not a UUID or it is not a notecard then an error is shouted on DEBUG_CHANNEL.
  • If name is a UUID then there are no new asset permissions consequences for the object.
    • The resulting object develops no new usage restrictions that might have occurred if the asset had been placed in the prims inventory.
  • If name is a new empty notecard (never saved) then an error "Couldn't find notecard ~NAME~" (~NAME~ being the value of name) will be shouted on the DEBUG_CHANNEL. This is because until a notecard is saved for the first time, it does not exist as an asset only as an inventory placeholder.
  • If notecard contains embedded inventory items (such as textures and landmarks), an empty list will be returned, regardless of the search string.
  • No more than 64 matches are returned.

Examples

Notes

Regular Expression Cheat Sheet

Wildcard
. Matches any character
Anchors
^ Matches the beginning of the string.
$ Matches the end of the string.
Expression Prefixes
(?i) Makes search string case insensitive. This must be the first thing that appears in the search string.

"(?i)apple" will match "apple", "APPLE", "ApPlE", and any other combination of upper and lower case characters.

$ Matches the end of the string.
Repeats
* Matches the preceding atom 0 or more times.
+ Matches the preceding atom 1 or more times.
? Matches the preceding atom 0 or 1 times.
{n}

{n,}

{n, m}

Matches the preceding atom n, n or more, or between n and m times.
Sub-expressions
(expression) Text enclosed in parentheses is a marked sub-expression. Text matched as part of a sub-expressions is split out and may be repeated.
Alternation
a | b Match either a or b.
Character Sets
[abc] Matches any one of the enumerated characters.
[a-c] Matches any character in the specified range.
[^abc] Matches any character other than the enumerated characters.
[[:name:]] Matches any character of the named class.
Any of the above character set definitions may be combined.
Escape Sequences
Specific Characters
\e ASCII 0x1B, ESC
\n New line
\r Carriage return
\t Tab
\xdd Matches an ASCII character with the code dd
Single character classes
\d

\D

Any decimal digit.
  • \d → [[:digit:]] or [0-9]
  • \D → [^[:digit:]] or [^0-9]
\l

\L

Any lower case character.
  • \l → [[:lower:]] or [a-z]
  • \L → [^[:lower:]] or [^a-z]
\s

\S

Any whitespace character.
  • \s → [[:space:]] or [ \t\r\n]
  • \S → [^[:space:]] or [^ \t\r\n]
\u

\U

Any upper case character.
  • \u → [[:upper:]] or [A-Z]
  • \U → [^[:upper:]] or [^A-Z]
\w

\W

Any "word" character.

Alphanumeric plus underscore

  • \w → [[:upper:][:lower:][:digit:]_] or [A-Za-z0-9_]
  • \W → [^[:upper:][:lower:][:digit:]_] or [^A-Za-z0-9_]
Word boundaries
\< Start of word.
\> End of word
\b
\B Not a word boundary.

*Note* LSL uses '\' as an escape character in strings. The escape characters above must be double escaped. So "\d" needs to be written in LSL as "\\d"

Please see LSL Strings, Escape Codes

Named Character Classes
alnum Any alpha-numeric character.
  • [[:alnum:]] → [0-9a-zA-Z]
  • [^[:alnum:]] → [^0-9a-zA-Z]
alpha Any alphabetic character.
  • [[:alpha:]] → [a-zA-Z]
  • [^[:alpha:]] → [^a-zA-Z]
blank Any whitespace character that is not a line separator.
cntrl Any control character
  • [[:cntrl:]] → [\x01-\x31]
  • [^[:cntrl:]] → [^\x01-\x31]
digit

d

Any decimal digit
  • [[:digit:]] → [0-9]
  • [^[:digit:]] → [^0-9]
lower

l

Any lower case character.
  • [[:lower:]] → [a-z]
  • [^[:lower:]] → [^a-z]
print Any printable character.
punct Any punctiation character.
space

s

Any whitespace character.
upper

u

Any upper case character.
  • [[:upper:]] → [A-Z]
  • [^[:upper:]] → [^A-Z]
word

w

Any control character
  • [[:word:]] → [0-9a-zA-Z_]
  • [^[:word:]] → [^0-9a-zA-Z_]
xdigit Any hexadecimal digit character
  • [[:xdigit:]] → [0-9a-fA-F]
  • [^[:xdigit:]] → [^0-9a-fA-F]

See Also

Deep Notes

Signature

function list llFindNotecardTextSync( string name, string pattern, integer start, integer count, list options );