コード例 #1
0
ファイル: TmxReader.cs プロジェクト: AlissaSabre/disfr
            /// <summary>Recursively builds an inline string from an XML element.</summary>
            /// <param name="inline">An inline builder to append partial contents.</param>
            /// <param name="elem">An XML element whose contnets are appended to <paramref name="inline"/> to build an inline string.</param>
            /// <param name="X">The namespace the TMX elements are in.</param>
            private static void BuildInline(InlineBuilder inline, XElement elem, XNamespace X)
            {
                foreach (var node in elem.Nodes())
                {
                    if (node is XText)
                    {
                        inline.Add((node as XText).Value);
                    }
                    else if (node is XElement)
                    {
                        var e    = (XElement)node;
                        var ns   = e.Name.Namespace;
                        var name = e.Name.LocalName;
                        if (ns == X && name == "bpt")
                        {
                            inline.Add(BuildNativeCodeTag(Tag.B, e, true));
                        }
                        else if (ns == X && name == "ept")
                        {
                            inline.Add(BuildNativeCodeTag(Tag.E, e, true));
                        }
                        else if (ns == X && name == "hi")
                        {
                            inline.Add(BuildNativeCodeTag(Tag.B, e, false));
                            BuildInline(inline, e, X);
                            inline.Add(BuildNativeCodeTag(Tag.E, e, false));
                        }
                        else if (ns == X && name == "it")
                        {
                            Tag type;
                            switch ((string)e.Attribute("pos"))
                            {
                            case "open": type = Tag.B; break;

                            case "close": type = Tag.E; break;

                            default: type = Tag.S; break;
                            }
                            inline.Add(BuildNativeCodeTag(type, e, true));
                        }
                        else if (ns == X && (name == "ph" || name == "ut"))
                        {
                            // Replace a standalone native code element with a standalone inline tag.
                            inline.Add(BuildNativeCodeTag(Tag.S, e, true));
                        }
                        else
                        {
                            // Uunknown element.
                            // OH, I have no good idea how to handle it.  FIXME.
                            if (string.IsNullOrEmpty((string)e) && !e.HasElements)
                            {
                                inline.Add(BuildNativeCodeTag(Tag.S, e, false));
                            }
                            else
                            {
                                inline.Add(BuildNativeCodeTag(Tag.B, e, false));
                                BuildInline(inline, e, X);
                                inline.Add(BuildNativeCodeTag(Tag.E, e, false));
                            }
                        }
                    }
                    else
                    {
                        // Silently discard any other nodes; e.g., comment or pi.
                    }
                }
            }
コード例 #2
0
ファイル: XliffAsset.cs プロジェクト: AlissaSabre/disfr
 public void Add(string text)
 {
     InterSegment.Add(text);
 }