コード例 #1
0
        /// <summary>
        /// Get the name of the value's XDM type
        /// </summary>
        /// <param name="processor">The <c>Processor</c> object.
        /// This is needed for access to the NamePool,
        /// which maps the internal form of type names to their external form.</param>
        /// <returns>The type of the value, as a QName. This may be a built-in type or a user-defined
        /// atomic type.
        /// </returns>


        public QName GetTypeName(Processor processor)
        {
            int      fp   = ((JAtomicType)((JAtomicValue)value).getItemType(null)).getFingerprint();
            NamePool pool = processor.config.getNamePool();

            return(new QName(pool.getPrefix(fp),
                             pool.getURI(fp),
                             pool.getLocalName(fp)));
        }
コード例 #2
0
        /// <summary>
        /// Construct a QName from a lexical QName, supplying an element node whose
        /// in-scope namespaces are to be used to resolve any prefix contained in the QName.
        /// </summary>
        /// <remarks>
        /// <para>This constructor checks that the components of the QName are
        /// lexically valid.</para>
        /// <para>If the lexical QName has no prefix, the name is considered to be in the
        /// default namespace, as defined by <c>xmlns="..."</c>.</para>
        /// <para>If the prefix of the lexical QName is not in scope, returns null.</para>
        /// </remarks>
        /// <param name="lexicalQName">The lexical QName, in the form <code>prefix:local</code>
        /// or simply <c>local</c>.</param>
        /// <param name="element">The element node whose in-scope namespaces are to be used
        /// to resolve the prefix part of the lexical QName.</param>
        /// <exception cref="ArgumentException">If the prefix of the lexical QName is not in scope</exception>
        /// <exception cref="ArgumentException">If the lexical QName is invalid
        /// (for example, if it contains invalid characters)</exception>
        ///

        public QName(String lexicalQName, XdmNode element)
        {
            try {
                NodeInfo node = (NodeInfo)element.value;
                NamePool pool = node.getConfiguration().getNamePool();
                int      nc   = pool.allocateLexicalQName(lexicalQName, true, new InscopeNamespaceResolver(node),
                                                          node.getConfiguration().getNameChecker());
                this.uri    = pool.getURI(nc);
                this.local  = pool.getLocalName(nc);
                this.prefix = pool.getPrefix(nc);
            } catch (net.sf.saxon.trans.DynamicError err) {
                throw new ArgumentException(err.getMessage());
            }
        }
コード例 #3
0
        /// <summary>
        /// 获取名称数据
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public unsafe static char *GetNamePool(string name)
        {
            Pointer pointer;

            if (namePools.TryGetValue(name, out pointer))
            {
                return(pointer.Char);
            }
            char *value = NamePool.Get(name, 2, 2);

            *(int *)value = ',' + ('"' << 16);
            *(int *)(value + (2 + name.Length)) = '"' + (':' << 16);
            namePools.Set(name, new Pointer {
                Data = value
            });
            return(value);
        }
コード例 #4
0
        private void _init(string str)
        {
            m_str         = str;
            m_pos         = 0;
            m_curLine     = 1;
            m_defaultNS   = ASNamespace.getDefault();
            m_parserFlags = 0;

            var xmlSettings = ASXML.internalSettings;

            if (xmlSettings.ignoreComments)
            {
                m_parserFlags |= FLAG_IGNORE_COMMENTS;
            }
            if (xmlSettings.ignoreProcessingInstructions)
            {
                m_parserFlags |= FLAG_IGNORE_PI;
            }
            if (xmlSettings.ignoreWhitespace)
            {
                m_parserFlags |= FLAG_IGNORE_SPACE;
            }

            m_nsInScope.clear();
            m_nsInScopePtrs.clear();
            m_parserStack.clear();
            m_nodeStack.clear();
            m_unresolvedAttrs.clear();

            if (m_buffer == null)
            {
                m_buffer = new char[128];
            }

            if (m_namePool == null)
            {
                m_namePool = new NamePool();
            }
        }
コード例 #5
0
        /// <summary>
        /// Get an enumerator that selects all the nodes on one of the XPath
        /// axes, provided they have a given name. The nodes selected are those of the principal
        /// node kind (elements for most axes, attributes for the attribute axis, namespace nodes
        /// for the namespace axis) whose name matches the name given in the second argument.
        /// </summary>
        /// <param name="axis">
        /// The axis to be navigated, for example <c>XdmAxis.Child</c> for the child axis.
        /// </param>
        /// <param name="nodeName">
        /// The name of the required nodes, for example <c>new QName("", "item")</c> to select
        /// nodes with local name "item", in no namespace.
        /// </param>
        /// <remarks>
        /// The nodes are returned in axis order: that is, document order for a forwards
        /// axis, reverse document order for a reverse axis.
        /// </remarks>

        public IEnumerator EnumerateAxis(XdmAxis axis, QName nodeName)
        {
            int kind;

            switch (axis)
            {
            case XdmAxis.Attribute:
                kind = net.sf.saxon.type.Type.ATTRIBUTE;
                break;

            case XdmAxis.Namespace:
                kind = net.sf.saxon.type.Type.NAMESPACE;
                break;

            default:
                kind = net.sf.saxon.type.Type.ELEMENT;
                break;
            }
            NamePool pool     = ((NodeInfo)value).getConfiguration().getNamePool();
            int      nameCode = pool.allocate("", nodeName.Uri, nodeName.LocalName);
            NameTest test     = new NameTest(kind, nameCode, pool);

            return(new SequenceEnumerator(((NodeInfo)value).iterateAxis(GetAxisNumber(axis), test)));
        }
コード例 #6
0
        /// <summary>
        /// Register a QName with the <c>Processor</c>. This makes comparison faster
        /// when the QName is compared with others that are also registered with the <c>Processor</c>.
        /// </summary>
        /// <param name="processor">The Processor in which the name is to be registered.</param>

        public void Register(Processor processor)
        {
            pool        = processor.config.getNamePool();
            fingerprint = pool.allocate(prefix, uri, local) & 0xfffff;
        }
コード例 #7
0
        public bool Translate(Scene?scene, object source, TextTranslationEventArgs e, string original, out string translate)
        {
            if (Type.Count > 0)
            {
                if (!Type.Contains(e.Type))
                {
                    translate = null;
                    return(false);
                }
            }

            if (Source.Count > 0)
            {
                if (!Source.Contains(e.Source))
                {
                    translate = null;
                    return(false);
                }
            }

            if (Scene.Count > 0)
            {
                if (!Scene.Contains(scene?.name))
                {
                    translate = null;
                    return(false);
                }
            }

            if (Scene.Count > 0)
            {
                if (!Scene.Contains(scene?.name))
                {
                    translate = null;
                    return(false);
                }
            }

            if (Level.Count > 0)
            {
                if (!Level.Contains(scene?.buildIndex ?? -1))
                {
                    translate = null;
                    return(false);
                }
            }

            var objectName = (source as UnityEngine.Object)?.name;

            if (ObjectName.Count > 0)
            {
                if (!ObjectName.Contains(objectName))
                {
                    translate = null;
                    return(false);
                }
            }

            var objectId = (source as UnityEngine.Object)?.GetInstanceID();

            if (ObjectId.Count > 0)
            {
                if (!ObjectId.Contains(objectId?.ToString()))
                {
                    translate = null;
                    return(false);
                }
            }

            if ((Flag & TextTranslationFlag.TextPart) > TextTranslationFlag.None)
            {
                if ((Flag & TextTranslationFlag.Regex) > TextTranslationFlag.None)
                {
                    if (!Regex.IsMatch(original))
                    {
                        translate = null;
                        return(false);
                    }

                    translate = Regex.Replace(original, Translation);
                    if (e.Debug)
                    {
                        Logger.Log(LogLevel.Info, $"TextPart {original} >> {translate}");
                    }
                    return(true);
                }
                else
                {
                    if (original != Original)
                    {
                        translate = null;
                        return(false);
                    }

                    translate = Translation;
                    if (e.Debug)
                    {
                        Logger.Log(LogLevel.Info, $"TextPart {original} >> {translate}");
                    }
                    return(true);
                }
            }
            else
            {
                if ((Flag & TextTranslationFlag.Regex) > TextTranslationFlag.None)
                {
                    var matches = Regex.Matches(original);

                    if (matches.Count == 0)
                    {
                        translate = null;
                        return(false);
                    }

                    var originalTemp = new StringBuilder(original, 32);

                    foreach (Match match in matches)
                    {
                        var raw           = match.Value;
                        var translateTemp = new StringBuilder(Translation, 32);

                        for (var i = match.Groups.Count - 1; i >= 0; i--)
                        {
                            var group = match.Groups[i];
                            if (!NamePool.Translate(scene, source, e, group.Value, out var groupValue))
                            {
                                groupValue = group.Value;
                            }

                            translateTemp = translateTemp.Replace($"${i}", groupValue);
                            translateTemp = translateTemp.Replace($"${{{i}}}", groupValue);
                        }

                        foreach (var name in Regex.GetGroupNames())
                        {
                            var group = match.Groups[name];
                            if (!NamePool.Translate(scene, source, e, group.Value, out var groupValue))
                            {
                                groupValue = group.Value;
                            }

                            translateTemp = translateTemp.Replace($"${{{name}}}", groupValue);
                        }

                        originalTemp = originalTemp.Replace(raw, translateTemp.ToString(), match.Index, match.Length);
                    }

                    translate = originalTemp.ToString();
                    if (e.Debug)
                    {
                        Logger.Log(LogLevel.Info, $"{original} >> {translate}");
                    }
                    return(true);
                }
                else
                {
                    if (original != Original)
                    {
                        translate = null;
                        return(false);
                    }

                    translate = Translation;
                    if (e.Debug)
                    {
                        Logger.Log(LogLevel.Info, $"{original} >> {translate}");
                    }
                    return(true);
                }
            }
        }
コード例 #8
0
ファイル: Model.cs プロジェクト: nuxleus/saxonica
        /// <summary>
        /// Register a QName with the <c>Processor</c>. This makes comparison faster
        /// when the QName is compared with others that are also registered with the <c>Processor</c>.
        /// </summary>
        /// <remarks>
        /// A given <c>QName</c> object can only be registered with one <c>Processor</c>.
        /// </remarks>
        /// <param name="processor">The Processor in which the name is to be registered.</param>

        public void Register(Processor processor)
        {
            if (pool != null && pool != processor.config.getNamePool())
            {
                throw new InvalidOperationException("A QName cannot be registered with more than one Processor");
            }
            pool = processor.config.getNamePool();
            fingerprint = pool.allocate(prefix, uri, local) & 0xfffff;
        }
        /// <summary>
        /// Register a QName with the <c>Processor</c>. This makes comparison faster
        /// when the QName is compared with others that are also registered with the <c>Processor</c>.
        /// </summary>
        /// <param name="processor">The Processor in which the name is to be registered.</param>

        public void Register(Processor processor) {
            pool = processor.config.getNamePool();
            fingerprint = pool.allocate(prefix, uri, local) & 0xfffff;
        }