private static GraceObject mAsString(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceString.Create("U+" + self.codepoint.ToString("X4") + " " + self.parts[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]); }
/// <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]); }
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]))); }
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)); }
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)); }
private static GraceObject mString(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceString.Create(Char.ConvertFromUtf32(self.codepoint))); }
private static GraceObject mTitlecase(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(mapCodepointSequenceString(self.parts[13])); }
private static GraceObject mMirrored(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceBoolean.Create(self.parts[8] == "Y")); }
private static GraceObject mDecomposition(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(mapCodepointSequenceString(self.parts[4])); }
private static GraceObject mBidirectional(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceString.Create(self.parts[3])); }
private static GraceObject mCombining(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceNumber.Create(int.Parse(self.parts[2]))); }
private static GraceObject mCodepoint(EvaluationContext ctx, MethodRequest req, CodepointObject self) { return(GraceNumber.Create(self.codepoint)); }