gigebyte / cookies

Automatically exported from code.google.com/p/cookies
0 stars 0 forks source link

Support sub values #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. It would be nice to get sub values of cookies such as if a cookie 
looked like this: test1=a&test2=b&test3=c
This minimizes the amount of cookies you have to use for a website.

Here is how I currently read sub values:

function readCookie2(name, subname)
{
    var cookieData = readCookie(name);

    var nameEQ = subname + "=";
    var ca = cookieData.split('&');
    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];
        while (c.charAt(0) == ' ')
        {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0)
        {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return null;
}

I'm sure there could be some nice utilities to add and remove subvalues.

Original issue reported on code.google.com by godka...@gmail.com on 25 Feb 2009 at 12:29

GoogleCodeExporter commented 9 years ago
I'll take a look at what you're after and see if I can figure out what is 
stopping
you from doing this in my library as is, and if I can easily add this 
enhancement. 
It does seem that you should be able to format a value in any way you desire, 
so I am
definitely going to consider what you have said.

Original comment by auldrid...@gmail.com on 25 Feb 2009 at 1:43

GoogleCodeExporter commented 9 years ago

Original comment by auldrid...@gmail.com on 25 Feb 2009 at 2:20

GoogleCodeExporter commented 9 years ago
I've begun a test suite using FireUnit and have a cookie with ampersand 
separated name/value pairs and it works 
well.  It is currently on line 67 of the testing ( 
http://code.google.com/p/cookies/source/browse/trunk/testsuite.html )

Can you verify this is the sort of thing you're after and get back to me?

Thanks,
Jim

Original comment by auldrid...@gmail.com on 11 May 2009 at 7:29

GoogleCodeExporter commented 9 years ago
See: http://cass-hacks.com/articles/code/js_php_cookies/
Ih has something very similar

Original comment by malathi...@gmail.com on 9 Dec 2009 at 7:56

GoogleCodeExporter commented 9 years ago
Hello malathinil,

Is the example I gave in my test suite in comment3 not what you guys are 
looking for?  I am just not 
understanding this whole "sub value" thing.

Thanks,
Jim

Original comment by auldrid...@gmail.com on 9 Dec 2009 at 8:14

GoogleCodeExporter commented 9 years ago

Original comment by auldrid...@gmail.com on 27 Jan 2011 at 7:00