(LSL) string strURL2Use = URL_POLL_DATA; strURL2Use += llEscapeURL("?proj=" + strExpenseProjectData); strURL2Use += llEscapeURL("?type=" + strExpenseTypeData); strURL2Use += llEscapeURL("?amount=" + strExpenseAmount); strURL2Use += llEscapeURL("?note=" + strExpenseTypeNote);
// klEscapeURL(string src) // Returns the string src with URL escaping. (Replaces spaces by %20, etc) string klEscapeURL(string src) { string tmp; integer pos; // i read somewhere that jumps were more efficient than for loops. Haven't tested it myself, but using them anyway. @loop0; pos = llSubStringIndex(src, "%"); if(pos != -1) { // There's probably a more effecient way to do this, but i wrote this quickly without thinking too much up front. // Can't do llSubStringIndex() constantly because it would keep returning the first, replacing it with %25 and then // reporting the % in that one, so making an endless loop. So i take the first part of the string out and store it // temporarily, then continue on the remaining part until there's no more %'s in it. tmp += llGetSubString(src, 0, --pos) + "%25"; src = llDeleteSubString(src, 0, ++pos); jump loop0; } src = tmp + src; @loop1; pos = llSubStringIndex(src, " "); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%20"); jump loop1; } @loop2; pos = llSubStringIndex(src, "<"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3C"); jump loop2; } @loop3; pos = llSubStringIndex(src, ">"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3E"); jump loop3; } @loop4; pos = llSubStringIndex(src, "#"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%23"); jump loop4; } @loop5; pos = llSubStringIndex(src, "{"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%7B"); jump loop5; } @loop6; pos = llSubStringIndex(src, "}"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%7D"); jump loop6; } @loop7; pos = llSubStringIndex(src, "|"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%7C"); jump loop7; } @loop8; pos = llSubStringIndex(src, "\\"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%5C"); jump loop8; } @loop9; pos = llSubStringIndex(src, "^"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%5E"); jump loop9; } @loop10; pos = llSubStringIndex(src, "~"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%7E"); jump loop10; } @loop11; pos = llSubStringIndex(src, "["); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%5B"); jump loop11; } @loop12; pos = llSubStringIndex(src, "]"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%5D"); jump loop12; } @loop13; pos = llSubStringIndex(src, "`"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%60"); jump loop13; } @loop14; pos = llSubStringIndex(src, ";"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3B"); jump loop14; } @loop15; pos = llSubStringIndex(src, "/"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%2F"); jump loop15; } @loop16; pos = llSubStringIndex(src, "?"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3F"); jump loop16; } @loop17; pos = llSubStringIndex(src, ":"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3A"); jump loop17; } @loop18; pos = llSubStringIndex(src, "@"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%40"); jump loop18; } @loop19; pos = llSubStringIndex(src, "="); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%3D"); jump loop19; } @loop20; pos = llSubStringIndex(src, "&"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%26"); jump loop20; } @loop21; pos = llSubStringIndex(src, "$"); if(pos != -1) { src = llDeleteSubString(src, pos, pos); src = llInsertString(src, pos, "%24"); jump loop21; } return src; }
list chars = [ "%", "%25", // MUST BE FIRST. "\n", "%0A", " ", "%20", "#", "%23", "$", "%24", "&", "%26", "+", "%2B", ",", "%2C", "/", "%2F", ":", "%3A", ";", "%3B", "<", "%3C", "=", "%3D", ">", "%3E", "?", "%3F", "@", "%40", "[", "%5B", "\\", "%5C", "]", "%5D", "^", "%5E", "`", "%60", "{", "%7B", "|", "%7C", "}", "%7D", "~", "%7E" ]; // Replaces all instances of toReplace in str with replaceWith. string replaceAll(string str, string toReplace, string replaceWith) { return llDumpList2String(llParseStringKeepNulls(str, [toReplace], []), replaceWith); } string escapeURL(string src) { integer i; integer len = llGetListLength(chars); for (i = 0; i < len; i += 2) { src = replaceAll(src, llList2String(chars, i), llList2String(chars, i+1)); } return src; }
string hexc="0123456789ABCDEF"; string int2hex(integer x) { integer x0 = x & 0xF; string res = llGetSubString(hexc, x0, x0); x = (x >> 4) & 0x0FFFFFFF; //otherwise we get infinite loop on negatives. while( x != 0 ) { x0 = x & 0xF; res = llGetSubString(hexc, x0, x0) + res; x = x >> 4; } return res; } // Replaces all instances of toReplace in str with replaceWith. string replaceAll(string str, string toReplace, string replaceWith) { return llDumpList2String(llParseStringKeepNulls(str, [toReplace], []), replaceWith); } string escapeURL(string src) { integer i; for (i = 0; i < 256; ++i) { string escaped = int2hex(i); if (llStringLength(escaped) == 1) escaped = "0" + escaped; escaped = "%" + escaped; string char = llUnescapeURL(escaped); if (llEscapeURL(char) == escaped) { src = replaceAll(src, char, escaped); } } return src; }
list chars = [ "%", "%25", // MUST BE FIRST. "\n", "%0A", " ", "%20", "#", "%23", "$", "%24", "&", "%26", "+", "%2B", ",", "%2C", "/", "%2F", ":", "%3A", ";", "%3B", "<", "%3C", "=", "%3D", ">", "%3E", "?", "%3F", "@", "%40", "[", "%5B", "\\", "%5C", "]", "%5D", "^", "%5E", "`", "%60", "{", "%7B", "|", "%7C", "}", "%7D", "~", "%7E" ]; // Replaces all instances of toReplace in str with replaceWith. string replaceAll(string str, string toReplace, string replaceWith) { return llDumpList2String(llParseStringKeepNulls(str, [toReplace], []), replaceWith); } string escapeURL(string src) { integer i; integer len = llGetListLength(chars); for (i = 0; i < len; i += 2) { src = replaceAll(src, llList2String(chars, i), llList2String(chars, i+1)); } return src; }
string hexc="0123456789ABCDEF"; string int2hex(integer x) { integer x0 = x & 0xF; string res = llGetSubString(hexc, x0, x0); x = (x >> 4) & 0x0FFFFFFF; //otherwise we get infinite loop on negatives. while( x != 0 ) { x0 = x & 0xF; res = llGetSubString(hexc, x0, x0) + res; x = x >> 4; } return res; } // Replaces all instances of toReplace in str with replaceWith. string replaceAll(string str, string toReplace, string replaceWith) { return llDumpList2String(llParseStringKeepNulls(str, [toReplace], []), replaceWith); } string escapeURL(string src) { integer i; // first handle % src = replaceAll(src, "%", "%25"); // before % for (i = 0x0; i < 0x25; ++i) { string encoded = int2hex(i); if (llStringLength(encoded) == 1) encoded = "0" + encoded; encoded = "%" + encoded; string char = llUnescapeURL(encoded); if (llEscapeURL(char) == encoded) { src = replaceAll(src, char, encoded); } } // after % for (i = 0x26; i < 0xFF; ++i) { string encoded = int2hex(i); if (llStringLength(encoded) == 1) encoded = "0" + encoded; encoded = "%" + encoded; string char = llUnescapeURL(encoded); if (llEscapeURL(char) == encoded) { src = replaceAll(src, char, encoded); } } return src; }
string myEscapeURL(string str) { if (llSubStringIndex(str, "^") != -1) { list out = []; list data = llParseStringKeepNulls(str, ["^"], []); integer len = llGetListLength(data); integer i; for (i = 0; i < len; i++) { out += [llEscapeURL(llList2String(data,i))]; } return llDumpList2String(out, llEscapeURL("^")); } else { return llEscapeURL(str); } }