Difference between revisions of "EscapeXML"
Jump to navigation
Jump to search
m (→EscapeXML) |
m (→EscapeXML) |
||
Line 14: | Line 14: | ||
{ | { | ||
list escapeChars = ["&","&","\"",""","'","'","<","<",">",">"]; | list escapeChars = ["&","&","\"",""","'","'","<","<",">",">"]; | ||
integer i; | integer i; | ||
integer ndx; | integer ndx; | ||
for( i = 0; i < llStringLength( str ); i++ ) { | for( i = 0; i < llStringLength( str ); i++ ) { | ||
ndx = llListFindList( escapeChars, [llGetSubString(str, i, i)]); | ndx = llListFindList( escapeChars, [llGetSubString(str, i, i)]); |
Revision as of 23:32, 8 March 2008
EscapeXML
<lsl> // Escape standard reserved XML chars with entities // Copyright 2008, JB Kraft // Released under BSD license // http://www.opensource.org/licenses/bsd-license.php
// ------------------------------------------------------------------------
// escape standard reserved XML chars with entities
// ------------------------------------------------------------------------
string escapeXML( string str )
{
list escapeChars = ["&","&","\"",""","'","'","<","<",">",">"]; integer i; integer ndx;
for( i = 0; i < llStringLength( str ); i++ ) { ndx = llListFindList( escapeChars, [llGetSubString(str, i, i)]); if( ndx != -1 ) { // start if( i == 0 ) { str = llList2String( escapeChars, ndx+1) + llGetSubString( str, i+1, -1 ); } // end else if( i == llStringLength( str ) - 1) { str = llGetSubString( str, 0, -2) + llList2String( escapeChars, ndx+1); } // middle else { str = llGetSubString( str, 0, i-1) + llList2String( escapeChars, ndx+1) + llGetSubString( str, i+1, -1 ); } i += llStringLength( llList2String( escapeChars, ndx+1)); } } return str;
}
// ------------------------------------------------------------------------ // D E F A U L T // ------------------------------------------------------------------------ default {
state_entry() { llSay(0, escapeXML("<Black> & \"White\" & 'Red' & <Green>")); }
}
</lsl>