Difference between revisions of "User:Cory Fimicoloud/LSLFunctions"
m (New page: ==My Functions== ===Text=== ====String==== =====UTF8Len===== Returns the UTF-8 byte count of the string passed to it. <lsl> integer UTF8Len(string fsString) { // Author: Cory Fimicoloud ...) |
m |
||
Line 1: | Line 1: | ||
==My Functions== | ==My Functions== | ||
<div style="padding: 0.5em 0.0em 0.5em 0.5em;"> | |||
<div style="border-bottom:1px solid #AAAAAA;"> | |||
===Text=== | ===Text=== | ||
</div> | |||
<div style="padding: 0.5em 0.0em 0.5em 0.5em;"> | |||
<div style="border-bottom:1px solid #AAAAAA;"> | |||
====String==== | ====String==== | ||
</div> | |||
<div style="padding: 0.5em 0.0em 0.5em 0.5em;"> | |||
<div style="border:1px solid #AAAAAA; margin-bottom:10px;"> | |||
<div style="background-color:#F4F8FB; border-bottom:1px dotted #AAAAAA; font-weight:bold; margin:0; padding:0.2em 0.5em; text-align:left;"> | |||
=====UTF8Len===== | =====UTF8Len===== | ||
Returns the UTF-8 byte count of the string passed to it. | </div> | ||
<lsl> | <div style="padding: 0.5em;"> | ||
integer UTF8Len(string fsString) | {{User:Cory Fimicoloud/LSLFunction | ||
|desc=Returns the UTF-8 byte count of the string passed to it. | |||
|return=Returns the UTF-8 byte count of the string passed to it. | |||
|p1_type=string | |||
|p1_name=fsString | |||
|p1_desc=The string to get the UTF-8 length of. | |||
|return_type=integer | |||
|examples=<lsl>default | |||
{ | |||
state_entry() | |||
{ | |||
// 63 characters. Each of the characters uses 1 byte except for ¢ (2 bytes) and € (3 bytes). Which results in 66 bytes. | |||
string lsString = "Can I have $10 and 7¢, please? I would prefer it in €'s though."; | |||
llOwnerSay("'" + lsString + "' is " + (string)UTF8Len(lsString) + " bytes."); | |||
} | |||
}</lsl> | |||
|code=<lsl>integer UTF8Len(string fsString) | |||
{ | { | ||
// Author: Cory Fimicoloud | // Author: Cory Fimicoloud | ||
Line 22: | Line 47: | ||
} | } | ||
return liByteLen; | return liByteLen; | ||
} | }</lsl>}} | ||
default | </div></div> | ||
<div style="border:1px solid #AAAAAA; margin-bottom:10px;"> | |||
<div style="background-color:#F4F8FB; border-bottom:1px dotted #AAAAAA; font-weight:bold; margin:0; padding:0.2em 0.5em; text-align:left;"> | |||
=====UTF8Split===== | |||
</div> | |||
<div style="padding: 0.5em;"> | |||
{{User:Cory Fimicoloud/LSLFunction | |||
|desc=Returns a list containing the string passed to it, split every fiSplit bytes. | |||
|return=Returns a list containing the string passed to it, split every fiSplit bytes. | |||
|p1_type=string | |||
|p1_name=fsString | |||
|p1_desc=The string to split. | |||
|p2_type=integer | |||
|p2_name=fiSplit | |||
|p2_desc=The length of each split. | |||
|return_type=list | |||
|examples=<lsl>default | |||
{ | { | ||
state_entry() | state_entry() | ||
{ | { | ||
list laSplit = UTF8Split("Can I have $10 and 7¢, please? I would prefer it in €'s though.", 33); | |||
llOwnerSay("\nUTF8Split\n==========\n\t0: " + llList2String(laSplit, 0) + "\n\t1: " + llList2String(laSplit, 1)); | |||
llOwnerSay(" | |||
} | } | ||
}</lsl> | }</lsl> | ||
|code=<lsl>list UTF8Split(string fsString, integer fiSplit) | |||
= | |||
<lsl> | |||
list UTF8Split(string fsString, integer fiSplit) | |||
{ | { | ||
// Author: Cory Fimicoloud | // Author: Cory Fimicoloud | ||
Line 64: | Line 101: | ||
} | } | ||
return laSplit + [lsSplit]; | return laSplit + [lsSplit]; | ||
} | }</lsl>}} | ||
</div></div> | |||
</div></div> | |||
</div> | |||
Revision as of 14:51, 16 February 2009
My Functions
Text
String
UTF8Len
• string | fsString | - | The string to get the UTF-8 length of. |
{ state_entry() { // 63 characters. Each of the characters uses 1 byte except for ¢ (2 bytes) and € (3 bytes). Which results in 66 bytes. string lsString = "Can I have $10 and 7¢, please? I would prefer it in €'s though."; llOwnerSay("'" + lsString + "' is " + (string)UTF8Len(lsString) + " bytes."); }
}</lsl>{ // Author: Cory Fimicoloud // License: http://creativecommons.org/licenses/by-sa/3.0/us/ integer liLen = ~llStringLength(fsString); string lsChar = ""; string lsEnc = ""; integer liByteLen = 0; while (++liLen < 0) { lsEnc = llEscapeURL((lsChar = llGetSubString(fsString, liLen, liLen))); if (lsChar != lsEnc) liByteLen += llStringLength(lsEnc) / 3; else ++liByteLen; } return liByteLen;
}</lsl>UTF8Split
• string | fsString | - | The string to split. |
• integer | fiSplit | - | The length of each split. |
{ state_entry() { list laSplit = UTF8Split("Can I have $10 and 7¢, please? I would prefer it in €'s though.", 33); llOwnerSay("\nUTF8Split\n==========\n\t0: " + llList2String(laSplit, 0) + "\n\t1: " + llList2String(laSplit, 1)); }
}</lsl>{ // Author: Cory Fimicoloud // License: http://creativecommons.org/licenses/by-sa/3.0/us/ string lsSplit = ""; list laSplit = []; integer liLen = ~llStringLength(fsString); string lsChar = ""; string lsEnc = ""; integer liByteLen = 0; while (++liLen < 0) { lsChar = llGetSubString(fsString, liLen, liLen); lsEnc = llEscapeURL(lsChar); if (lsChar != lsEnc) liByteLen += llStringLength(lsEnc) / 3; else ++liByteLen; if (liByteLen <= fiSplit) lsSplit += lsChar; else { laSplit += [lsSplit]; lsSplit = lsChar; liByteLen = 1; } } return laSplit + [lsSplit];
}</lsl>