fastCSharp/web/cookie.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;

namespace fastCSharp.web
{
    /// <summary>
    /// COOKIE处理类
    /// </summary>
    public unsafe static class cookie
    {
        /// <summary>
        /// 需要格式化的cookie名称字符集合
        /// </summary>
        public const string FormatCookieNameChars = ",; -\n\r\t";
        /// <summary>
        /// 需要格式化的cookie名称字符位图
        /// </summary>
        private static readonly String.asciiMap formatCookieNameCharMap = new String.asciiMap(unmanaged.Get(String.asciiMap.mapBytes), FormatCookieNameChars, true);
        /// <summary>
        /// 最大cookie名称长度
        /// </summary>
        public const int MaxCookieNameLength = 256;
        /// <summary>
        /// 格式化Cookie名称
        /// </summary>
        /// <param name="name">Cookie名称</param>
        /// <returns>格式化后Cookie名称</returns>
        public unsafe static string FormatCookieName(string name)
        {
            if (name.length() == 0) log.Default.Throw(log.exceptionType.Null);
            if (name.Length > MaxCookieNameLength) log.Default.Throw(null, "cookie名称超过限定 " + ((uint)name.Length).toString(), false);
            fixed (char* nameFixed = name)
            {
                char* endName = nameFixed + name.Length;
                int count = unsafer.String.asciiCount(nameFixed, endName, formatCookieNameCharMap.Map, FormatCookieNameChars[0]);
                if (*nameFixed == '$') ++count;
                if (count != 0)
                {
                    char* nameChars = stackalloc char[count = name.Length + (count << 1)], nextCookieName = nameChars;
                    if (*nameFixed == '$')
                    {
                        *nextCookieName++ = '%';
                        *(uint*)nextCookieName = '2' + ('4' << 16);
                        nextCookieName += 2;
                    }
                    else *nextCookieName = *nameFixed;
                    char* nextName = nameFixed;
                    String.asciiMap formatMap = formatCookieNameCharMap;
                    while (++nextName != endName)
                    {
                        int nextValue = (int)*nextName;
                        if (formatMap.Get(nextValue))
                        {
                            *++nextCookieName = '%';
                            int highValue = nextValue >> 4;
                            *++nextCookieName = (char)(highValue < 10 ? highValue + '0' : (highValue + ('0' + 'A' - '9' - 1)));
                            nextValue &= 15;
                            *++nextCookieName = (char)(nextValue < 10 ? nextValue + '0' : (nextValue + ('0' + 'A' - '9' - 1)));
                        }
                        else *++nextCookieName = (char)nextValue;
                    }
后面还有 16 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。