Example #1
0
        private static GraceObject mBEndian(EvaluationContext ctx,
                                            MethodRequest req,
                                            UTF16CodepointsView self)
        {
            var enc = new UnicodeEncoding(true, false);

            return(new ByteString(enc.GetBytes(self.data)));
        }
Example #2
0
        private static GraceObject mAt(EvaluationContext ctx,
                                       MethodRequest req,
                                       UTF16CodepointsView self)
        {
            MethodHelper.CheckArity(ctx, req, 1);
            var arg   = req[0].Arguments[0];
            var index = arg.FindNativeParent <GraceNumber>();
            var idx   = index.GetInt() - 1;

            if (idx < 0 || idx >= self.data.Length)
            {
                ErrorReporting.RaiseError(ctx, "R2013",
                                          new Dictionary <string, string> {
                    { "index", "" + (idx + 1) },
                    { "valid", self.data.Length > 0 ?
                      "1 .. " + self.data.Length
                                : "none (empty)" }
                }, "IndexError: Index out of range");
            }
            return(GraceNumber.Create(self.data[idx]));
        }
Example #3
0
 private static GraceObject mLEndian(EvaluationContext ctx,
                                     MethodRequest req,
                                     UTF16CodepointsView self)
 {
     return(new ByteString(Encoding.Unicode.GetBytes(self.data)));
 }