Table of Contents

About

Escapes the keys and values of a key-value data string and making them compliant with RFC1738.

In other words, wasKeyValueURLEscape will encode the keys and values whilst leaving the key-value separators untouched (=, &). This is useful in order to be able to send data without having to worry about collisions with reserved syntax elements.

Example Usage

When called with:

string data = "hello=world&good=day sir&life=good!";
wasKeyValueURLEscape($data);

the function will return the string:

hello=world&good=day+sir&life=good%21

Code

LSL

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
// escapes a string in conformance with RFC1738
string wasURLEscape(string i) {
    if(i == "") return "";
    string o = llGetSubString(i, 0, 0);
    i = llDeleteSubString(i, 0, 0);
    if(o == " ") return "+" + wasURLEscape(i);
    if(o == "\n") return "%0D%0A" + wasURLEscape(i);
    return llEscapeURL(o) + wasURLEscape(i); 
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueURLEscape(string data) {
    list i = llParseString2List(data, ["&", "="], []);
    list output = [];
    do {
        output += wasURLEscape(llList2String(i, 0)) + "=" + 
            wasURLEscape(llList2String(i, 1));
        i = llDeleteSubList(i, 0, 1);
    } while(llGetListLength(i) != 0);
    return llDumpList2String(output, "&");
}

fuss/data_structures/key-value_pairs/rfc1738/to.txt ยท Last modified: 2019/01/03 01:38 (external edit)

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.