当前位置: 首页>>代码示例>>C#>>正文


C# IEnvironment.CreateUriError方法代码示例

本文整理汇总了C#中IEnvironment.CreateUriError方法的典型用法代码示例。如果您正苦于以下问题:C# IEnvironment.CreateUriError方法的具体用法?C# IEnvironment.CreateUriError怎么用?C# IEnvironment.CreateUriError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEnvironment的用法示例。


在下文中一共展示了IEnvironment.CreateUriError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decode

        internal static string Decode(IEnvironment environment, string value, string reservedSet)
        {
            int b, d1v, d2v, n;
            char c, d1, d2;
            int strLen, k, start, v;
            string r, s;
            byte[] octets;

            strLen = value.Length;
            k = 0;
            r = "";

            while (k < strLen)
            {
                c = value[k];
                if (c != '%')
                {
                    s = c.ToString();
                }
                else
                {
                    start = k;
                    if (k + 2 > strLen)
                    {
                        throw environment.CreateUriError("");
                    }
                    d1 = value[++k];
                    d2 = value[++k];
                    d1v = HexValueOf(environment, d1);
                    d2v = HexValueOf(environment, d2);
                    b = (d1v * 16 + d2v);
                    if ((b & 0x80) == 0x00)
                    {
                        c = (char)b;
                        if (reservedSet.IndexOf(c) < 0)
                        {
                            s = c.ToString();
                        }
                        else
                        {
                            s = value.Substring(start, k - start);
                        }
                    }
                    else
                    {
                        for (n = 1; n < 5; n++)
                        {
                            if (((b << n) & 0x80) == 0x00)
                            {
                                break;
                            }
                        }
                        if (n == 1 || n > 4)
                        {
                            throw environment.CreateUriError("");
                        }
                        octets = new byte[n];
                        octets[0] = (byte)b;
                        if (k + (3 * (n - 1)) >= strLen)
                        {
                            throw environment.CreateUriError("");
                        }
                        for (int j = 1; j < n; j++)
                        {
                            k++;
                            if (value[k] != '%')
                            {
                                throw environment.CreateUriError("");
                            }
                            d1 = value[++k];
                            d2 = value[++k];
                            d1v = HexValueOf(environment, d1);
                            d2v = HexValueOf(environment, d2);
                            b = (d1v * 16 + d2v);
                            if ((b & 0x80) != 0x80 || (b & 0x40) != 0x00)
                            {
                                throw environment.CreateUriError("");
                            }
                            octets[j] = (byte)b;
                        }

                        try
                        {
                            v = (int)Encoding.UTF8.GetString(octets)[0];
                        }
                        catch (ArgumentException) // The byte array contains invalid Unicode code points.
                        {
                            throw environment.CreateUriError("");
                        }

                        if (v < 0x10000)
                        {
                            c = (char)v;
                            if (reservedSet.IndexOf(c) < 0)
                            {
                                s = c.ToString();
                            }
                            else
                            {
                                s = value.Substring(start, k - start);
//.........这里部分代码省略.........
开发者ID:ChaosPandion,项目名称:Machete,代码行数:101,代码来源:BGlobal.cs

示例2: Encode

        //[BuiltinFunction("iterate", "iterable", "fn"), DataDescriptor(false, false, false)]
        //internal static IDynamic Iterate(IEnvironment environment, IArgs args)
        //{
        //    var iterable = args[0].ConvertToObject();
        //    var createIterator = iterable.Get("createIterator") as ICallable;
        //    if (createIterator == null)
        //        throw environment.CreateTypeError("");
        //    var iterator = createIterator.Call(environment, iterable, environment.EmptyArgs).ConvertToObject();
        //    if (!iterator.HasProperty("current"))
        //        throw environment.CreateTypeError("");
        //    var next = iterator.Get("next") as ICallable;
        //    if (next == null)
        //        throw environment.CreateTypeError("");
        //    var fn = args[1] as ICallable;
        //    if (fn == null)
        //        throw environment.CreateTypeError("");
        //    while (next.Call(environment, iterator, environment.EmptyArgs).ConvertToBoolean().BaseValue)
        //    {
        //        var callArgs = environment.CreateArgs(new[] { iterator.Get("current") });
        //        fn.Call(environment, environment.Undefined, callArgs);
        //    }
        //    return environment.Undefined;
        //}
        //[BuiltinFunction("filter", "iterable", "predicate"), DataDescriptor(false, false, false)]
        //internal static IDynamic Filter(IEnvironment environment, IArgs args)
        //{
        //    var iterable = args[0].ConvertToObject();
        //    var predicate = args[1].ConvertToObject() as ICallable;
        //    if (predicate == null)
        //        throw environment.CreateTypeError("");
        //    return new HFilterIterable(environment, iterable, predicate);
        //}
        internal static string Encode(IEnvironment environment, string value, string unescapedSet)
        {
            byte[] octets;
            byte jOctet;
            char c;
            int strLen, k, v, kChar, j, l;
            string r;

            r = "";
            k = 0;
            strLen = value.Length;

            while (k < strLen)
            {
                c = value[k];
                if (unescapedSet.IndexOf(c) > -1)
                {
                    r += c;
                }
                else
                {
                    if (c > '\udc00' && c < '\udfff')
                    {
                        throw environment.CreateUriError("");
                    }
                    if (c < '\ud800' && c < '\udbff')
                    {
                        v = (int)c;
                    }
                    else
                    {
                        k++;
                        if (k == strLen)
                        {
                            throw environment.CreateUriError("");
                        }
                        kChar = (int)value[k];
                        if (kChar < 0xDC00 || kChar > 0xDFFF)
                        {
                            throw environment.CreateUriError("");
                        }
                        v = ((int)c - 0xD800) * 0x400 + (kChar - 0xDC00) + 0x10000;
                    }
                    octets = Encoding.UTF8.GetBytes(((char)v).ToString());
                    l = octets.Length;
                    j = 0;
                    while (j < l)
                    {
                        jOctet = octets[j];
                        r = r + "%" + jOctet.ToString("x2").ToUpper();
                        j++;
                    }
                }
                k++;
            }

            return r;
        }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:90,代码来源:BGlobal.cs

示例3: HexValueOf

 private static int HexValueOf(IEnvironment environment, char c)
 {
     if (c >= '0' && c <= '9')
     {
         return (int)c - 48;
     }
     else if (c >= 'A' && c <= 'F')
     {
         return (int)c - 55;
     }
     else if (c >= 'a' && c <= 'z')
     {
         return (int)c - 87;
     }
     else
     {
         throw environment.CreateUriError("");
     }
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:19,代码来源:BGlobal.cs

示例4: ToJsValue

 public override IJsValue ToJsValue(IEnvironment environment)
 {
     return environment.CreateUriError(Message);
 }
开发者ID:jlarsson,项目名称:Yes,代码行数:4,代码来源:JsUriException.cs


注:本文中的IEnvironment.CreateUriError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。