Ejemplo n.º 1
0
 public static Node /*!*/ ToYaml(RubyRegex /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(
                rep.GetTagUri(self),
                self.Inspect().ToAsciiString(),
                ScalarQuotingStyle.None
                ));
 }
Ejemplo n.º 2
0
 public static Node /*!*/ ToYaml(RubyRegex /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(
                rep.GetTagUri(self),
                self.Inspect().ToAsciiString(rep.Context.RubyOptions.Compatibility < RubyCompatibility.Ruby19),
                ScalarQuotingStyle.None
                ));
 }
Ejemplo n.º 3
0
 public static Node /*!*/ ToYaml(RubySymbol /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(
                // TODO: we should use RubySymbol but that would require ResolverScanner to recognize symbols in order not to emit a tag
                Tags.Str,
                SymbolOps.Inspect(rep.Context, self).ToAsciiString(),
                ScalarQuotingStyle.None
                ));
 }
Ejemplo n.º 4
0
        public static Node /*!*/ ToYaml(double self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            if (Double.IsNaN(self))
            {
                return(rep.Scalar(Tags.Float, ".NaN", ScalarQuotingStyle.None));
            }

            if (Double.IsNegativeInfinity(self))
            {
                return(rep.Scalar(Tags.Float, "-.Inf", ScalarQuotingStyle.None));
            }

            if (Double.IsPositiveInfinity(self))
            {
                return(rep.Scalar(Tags.Float, ".Inf", ScalarQuotingStyle.None));
            }

            return(rep.Scalar(Tags.Float, ClrFloat.ToS(rep.Context, self).ToString(), ScalarQuotingStyle.None));
        }
Ejemplo n.º 5
0
        public static Node /*!*/ ToYaml(UnaryOpStorage /*!*/ beginStorage, UnaryOpStorage /*!*/ endStorage, UnaryOpStorage /*!*/ exclStorage,
                                        Range /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            var begin = beginStorage.GetCallSite("begin");
            var end   = endStorage.GetCallSite("end");

            var map = new Dictionary <object, object>();

            rep.AddYamlProperties(map, self, false);
            return(rep.Map(
                       new Dictionary <Node, Node> {
                { rep.Scalar(null, "begin", ScalarQuotingStyle.None), rep.RepresentItem(begin.Target(begin, self)) },
                { rep.Scalar(null, "end", ScalarQuotingStyle.None), rep.RepresentItem(end.Target(end, self)) },
                { rep.Scalar(null, "excl", ScalarQuotingStyle.None), rep.Scalar(self.ExcludeEnd) },
            },
                       rep.GetTagUri(self),
                       map,
                       FlowStyle.Block
                       ));
        }
Ejemplo n.º 6
0
        public static Node /*!*/ ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            if (!self.IsEmpty && ContainsBinaryData(self))
            {
                return(rep.BaseCreateNode(self.ToByteArray()));
            }

            Debug.Assert(self.IsAscii());
            string str = self.ToString();

            ScalarQuotingStyle style = ScalarQuotingStyle.None;

            if (str.StartsWith(":", StringComparison.Ordinal))
            {
                style = ScalarQuotingStyle.Double;
            }
            else
            {
                style = rep.GetYamlStyle(self);
            }

            var   tag = rep.GetTagUri(self, Tags.Str, typeof(MutableString));
            IList instanceVariableNames = rep.ToYamlProperties(self);

            if (instanceVariableNames.Count == 0)
            {
                return(rep.Scalar(tag, str, style));
            }

            var map = new Dictionary <object, object>();

            rep.AddYamlProperties(map, self, instanceVariableNames, false);
            return(rep.Map(
                       new Dictionary <Node, Node> {
                { rep.Scalar(null, "str", style), rep.Scalar(null, str, style) }
            },
                       tag,
                       map,
                       FlowStyle.Block
                       ));
        }
Ejemplo n.º 7
0
        public static Node /*!*/ ToYaml(RubyTime /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            TimeSpan offset     = self.GetCurrentZoneOffset();
            long     fractional = self.Microseconds;
            string   value      = String.Format(CultureInfo.InvariantCulture,
                                                "{0:yyyy-MM-dd HH:mm:ss}" + (fractional == 0 ? "" : ".{1:D6}") + (self.Kind == DateTimeKind.Utc ? " Z" : " {2}{3:D2}:{4:D2}"),
                                                self.DateTime,
                                                fractional,
                                                offset.Hours >= 0 ? "+" : "",
                                                offset.Hours,
                                                offset.Minutes
                                                );

            return(rep.Scalar(rep.GetTagUri(self), value, ScalarQuotingStyle.None));
        }
Ejemplo n.º 8
0
        public static Node ToYamlNode(UnaryOpStorage /*!*/ messageStorage, Exception /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            var site = messageStorage.GetCallSite("message", 0);
            var map  = new Dictionary <object, object>();

            rep.AddYamlProperties(map, self, false);
            return(rep.Map(
                       new Dictionary <Node, Node> {
                { rep.Scalar(null, "message", ScalarQuotingStyle.None), rep.RepresentItem(site.Target(site, self)) }
            },
                       rep.GetTagUri(self),
                       map,
                       FlowStyle.Block
                       ));
        }
Ejemplo n.º 9
0
        public static Node /*!*/ ToYamlNode(RubyStruct /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            var fieldNames = self.GetNames();

            var fields = new Dictionary <Node, Node>(fieldNames.Count);

            for (int i = 0; i < fieldNames.Count; i++)
            {
                fields[rep.Scalar(null, fieldNames[i], ScalarQuotingStyle.None)] = rep.RepresentItem(self.Values[i]);
            }

            var map = new Dictionary <object, object>();

            rep.AddYamlProperties(map, self, false);
            return(rep.Map(fields, rep.GetTagUri(self), map, FlowStyle.Block));
        }
Ejemplo n.º 10
0
        public static Node /*!*/ ToYaml(double self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            MutableString str = RubySites.ToS(rep.Context, self);

            if (str != null)
            {
                if (str.Equals("Infinity"))
                {
                    str = MutableString.Create(".Inf");
                }
                else if (str.Equals("-Infinity"))
                {
                    str = MutableString.Create("-.Inf");
                }
                else if (str.Equals("NaN"))
                {
                    str = MutableString.Create(".NaN");
                }
            }
            return(rep.Scalar(self, str));
        }
Ejemplo n.º 11
0
        public static Node ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            if (RubyOps.IsTrue(_IsBinaryData.Target(_IsBinaryData, rep.Context, self)))
            {
                return(rep.BaseCreateNode(self.ConvertToBytes()));
            }

            string    str   = self.ConvertToString();
            RubyArray props = RubyRepresenter.ToYamlProperties(rep.Context, self);

            if (props.Count == 0)
            {
                MutableString taguri = RubyRepresenter.TagUri(rep.Context, self);

                char style = (char)0;
                if (str.StartsWith(":"))
                {
                    style = '"';
                }
                else
                {
                    MutableString styleStr = RubyRepresenter.ToYamlStyle(rep.Context, self) as MutableString;
                    if (styleStr != null && styleStr.Length > 0)
                    {
                        style = styleStr.GetChar(0);
                    }
                }

                return(rep.Scalar(taguri != null ? taguri.ConvertToString() : "", str, style));
            }

            Hash map = new Hash(rep.Context);

            map.Add(MutableString.Create("str"), str);
            RubyRepresenter.AddYamlProperties(rep.Context, self, map, props);
            return(rep.Map(self, map));
        }
Ejemplo n.º 12
0
        public static Node /*!*/ ToYaml(ConversionStorage <MutableString> /*!*/ tosConversion, object /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            string value = Protocols.ConvertToString(tosConversion, self).ToString();

            return(rep.Scalar(rep.GetTagUri(self), value, ScalarQuotingStyle.None));
        }
Ejemplo n.º 13
0
 public static Node /*!*/ ToYaml([NotNull] BigInteger self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(Tags.Bignum, self.ToString(CultureInfo.InvariantCulture), ScalarQuotingStyle.None));
 }
Ejemplo n.º 14
0
 public static Node /*!*/ ToYaml(ConversionStorage <MutableString> /*!*/ tosConversion, bool self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(self));
 }
Ejemplo n.º 15
0
 public static Node ToYaml(object self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(self, null));
 }
Ejemplo n.º 16
0
 public static Node ToYaml(object self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(self, RubySites.ToS(rep.Context, self)));
 }
Ejemplo n.º 17
0
        public static Node ToYaml(DateTime self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            string format = (self.Millisecond != 0) ? "yyyy-MM-dd HH:mm:ss.fffffff K" : "yyyy-MM-dd HH:mm:ss K";

            return(rep.Scalar(self, MutableString.Create(self.ToString(format))));
        }
Ejemplo n.º 18
0
 public static Node /*!*/ ToYaml(object self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(Tags.Null, null, ScalarQuotingStyle.None));
 }
Ejemplo n.º 19
0
 public static Node /*!*/ ToYaml(int self, [NotNull] RubyRepresenter /*!*/ rep)
 {
     return(rep.Scalar(Tags.Int, self.ToString(), ScalarQuotingStyle.None));
 }