예제 #1
0
 private static GraceObject mAsString(EvaluationContext ctx,
                                      MethodRequest req,
                                      CodepointObject self)
 {
     return(GraceString.Create("U+" + self.codepoint.ToString("X4")
                               + " " + self.parts[0]));
 }
예제 #2
0
        private static GraceObject mAt(EvaluationContext ctx,
                                       MethodRequest req,
                                       StringCodepoints self)
        {
            MethodHelper.CheckArity(ctx, req, 1);
            var oth = req[0].Arguments[0].FindNativeParent <GraceNumber>();

            if (oth == null)
            {
                ErrorReporting.RaiseError(ctx, "R2001",
                                          new Dictionary <string, string> {
                    { "method", req.Name },
                    { "index", "1" },
                    { "part", req.Name },
                    { "required", "Number" },
                }, "ArgumentTypeError: Index must be a number");
            }
            int idx = oth.GetInt() - 1;

            if (idx >= self.codepoints.Length || idx < 0)
            {
                ErrorReporting.RaiseError(ctx, "R2013",
                                          new Dictionary <string, string> {
                    { "index", "" + (idx + 1) },
                    { "valid", self.codepoints.Length > 0 ?
                      "1 .. " + self.codepoints.Length
                                : "none (empty)" }
                }, "IndexError: Index out of range");
            }
            if (self.codepoints[idx] == null)
            {
                self.codepoints[idx] = CodepointObject.Create(self.utf32[idx]);
            }
            return(self.codepoints[idx]);
        }
예제 #3
0
 /// <summary>
 /// Create a codepoint object for a given codepoint.
 /// </summary>
 /// <param name="cp">Codepoint to represent</param>
 /// <remarks>
 /// These objects are cached, so that only one object for
 /// a given codepoint is created.
 /// </remarks>
 public static CodepointObject Create(int cp)
 {
     if (!cache.ContainsKey(cp))
     {
         cache[cp] = new CodepointObject(cp);
     }
     return(cache[cp]);
 }
예제 #4
0
 private static GraceObject mDigit(EvaluationContext ctx,
                                   MethodRequest req,
                                   CodepointObject self)
 {
     // By convention, return -1 for non-numeric codepoints.
     if (self.parts[6] == "")
     {
         return(GraceNumber.Create(-1));
     }
     return(GraceNumber.Create(int.Parse(self.parts[6])));
 }
예제 #5
0
        private static GraceObject mGTE(EvaluationContext ctx,
                                        MethodRequest req,
                                        CodepointObject self)
        {
            MethodHelper.CheckArity(ctx, req, 1);
            var other = req[0].Arguments[0] as CodepointObject;

            if (other == null)
            {
                return(GraceBoolean.False);
            }
            return(GraceBoolean.Create(self.codepoint >= other.codepoint));
        }
예제 #6
0
        private static GraceObject mNumeric(EvaluationContext ctx,
                                            MethodRequest req,
                                            CodepointObject self)
        {
            // By convention, return -1 for non-numeric codepoints.
            if (self.parts[7] == "")
            {
                return(GraceNumber.Create(-1));
            }
            int val;

            if (int.TryParse(self.parts[7], out val))
            {
                return(GraceNumber.Create(val));
            }
            // At this point, it must be a fraction n/m.
            var bits = self.parts[7].Split('/');
            var rat  = Rational.Create(int.Parse(bits[0]), int.Parse(bits[1]));

            return(GraceNumber.Create(rat));
        }
예제 #7
0
 private static GraceObject mString(EvaluationContext ctx,
                                    MethodRequest req,
                                    CodepointObject self)
 {
     return(GraceString.Create(Char.ConvertFromUtf32(self.codepoint)));
 }
예제 #8
0
 private static GraceObject mTitlecase(EvaluationContext ctx,
                                       MethodRequest req,
                                       CodepointObject self)
 {
     return(mapCodepointSequenceString(self.parts[13]));
 }
예제 #9
0
 private static GraceObject mMirrored(EvaluationContext ctx,
                                      MethodRequest req,
                                      CodepointObject self)
 {
     return(GraceBoolean.Create(self.parts[8] == "Y"));
 }
예제 #10
0
 private static GraceObject mDecomposition(EvaluationContext ctx,
                                           MethodRequest req,
                                           CodepointObject self)
 {
     return(mapCodepointSequenceString(self.parts[4]));
 }
예제 #11
0
 private static GraceObject mBidirectional(EvaluationContext ctx,
                                           MethodRequest req,
                                           CodepointObject self)
 {
     return(GraceString.Create(self.parts[3]));
 }
예제 #12
0
 private static GraceObject mCombining(EvaluationContext ctx,
                                       MethodRequest req,
                                       CodepointObject self)
 {
     return(GraceNumber.Create(int.Parse(self.parts[2])));
 }
예제 #13
0
 private static GraceObject mCodepoint(EvaluationContext ctx,
                                       MethodRequest req,
                                       CodepointObject self)
 {
     return(GraceNumber.Create(self.codepoint));
 }