コード例 #1
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
                       ));
        }
コード例 #2
0
ファイル: BuiltinsOps.cs プロジェクト: gaybro8777/ironruby
        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));
        }