About

Searches key-value tuples, matching key and value with a needle and returns the key-value tuple in a list, where the head element is the key and the tail element is the value.

Comments

  • Requires a needle in needle as a string.
  • Requires key-value data in kvp as a string.
  • Returns a key-value tuple where key is the head element and value is the tail element.

Error Handling

  • Will return the empty string if needle cannot be matched.

Remarks

  • Currently, in order to not rely on Ord, the function splits on ASCII tokens only. That means that for a hay of kvp=love♥you, a call such as wasKeyValueFindTuple("love", kvp), the function will fail to find the tuple.

Example Usage

Suppose that the key-value data contains:

string kvp = "data=empty&movement=off"

when calling the function with:

wasKeyValueGet("move", kvp);

the function will return the list:

[ "movement", "off" ];

Code

This script was tested and works on OpenSim version 0.7.4!

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
list wasKeyValueFindTuple(string needle, string kvp) {
    list a = ["!","\"","#","%","'","(",")","*","+",",","-",".","/",":",";",
        "<",">","?","@","[","\\","]","^","_","`","{","|","}","~", " "];
    list dVars = llParseString2List(kvp, ["&"], []);
    do {
        list kv = llParseString2List(llList2String(dVars, 0), ["="], []);
        list x = llParseString2List(llList2String(kv, 0), a, []);
        list y = llParseString2List(llList2String(kv, 1), a, []);
        do {
            string m = llList2String(x, 0);
            if(llSubStringIndex(llToLower(m), llToLower(needle)) != -1) return kv;
            x = llDeleteSubList(x, 0, 0);
            m = llList2String(y, 0);
            if(llSubStringIndex(llToLower(m), llToLower(needle)) != -1) return kv;
            y = llDeleteSubList(y, 0, 0);
        } while(llGetListLength(x) && llGetListLength(y));
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    return [ "", "" ];
}

fuss/data_structures/key-value_pairs/findtuple.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


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