Exemplo n.º 1
0
        public void ParsingTurtleW3CNumericLiterals1()
        {
            String input = "123.E+1";

            Assert.IsTrue(TurtleSpecsHelper.IsValidDouble(input));
        }
Exemplo n.º 2
0
        internal void Parse(INode n, XsdtType x)
        {
            switch (n.NodeType)
            {
            case NodeType.Uri:
                x.NetType      = typeof(Uri);
                x.ValuePart    = n.ToString();
                x.XsdtTypeName = XsdtPrimitiveDataType.XsdtAnyUri;
                ConvertValueToNet(x);
                break;

            case NodeType.Literal:
                ILiteralNode lit = (ILiteralNode)n;

                x.XsdtTypeName = XsdtPrimitiveDataType.XsdtUnknown;
                x.ValuePart    = lit.Value;

                if (lit.DataType != null)
                {
                    if (lit.DataType.ToString().StartsWith(NamespaceMapper.XMLSCHEMA))
                    {
                        x.TypePart = lit.DataType.ToString().Substring(NamespaceMapper.XMLSCHEMA.Length);
                    }
                    else
                    {
                        x.TypePart = "string";
                    }
                }
                else
                {
                    if (TurtleSpecsHelper.IsValidPlainLiteral(lit.Value))
                    {
                        if (TurtleSpecsHelper.IsValidInteger(lit.Value))
                        {
                            x.TypePart = "integer";
                        }
                        else if (TurtleSpecsHelper.IsValidDecimal(lit.Value))
                        {
                            x.TypePart = "decimal";
                        }
                        else if (TurtleSpecsHelper.IsValidDouble(lit.Value))
                        {
                            x.TypePart = "double";
                        }
                        else
                        {
                            x.TypePart = "boolean";
                        }
                    }
                    else
                    {
                        x.TypePart = "string";
                    }
                }

                foreach (int i in Enum.GetValues(typeof(XsdtPrimitiveDataType)))
                {
                    var           result = (XsdtPrimitiveDataType)i;
                    XsdtAttribute attr   = GetXsdtAttrFor(result);
                    if (attr.TypeUri == x.TypePart)
                    {
                        x.XsdtTypeName = result;
                    }
                }

                if (TypeLookup.ContainsKey(x.XsdtTypeName))
                {
                    x.NetType = TypeLookup[x.XsdtTypeName];
                }
                else
                {
                    throw new LinqToRdfException("XsdtTypeConverter does not know how to convert the XML Schema Datatype " + x.TypePart);
                }

                ConvertValueToNet(x);
                break;

            default:
                throw new LinqToRdfException("XsdtTypeConverter can only convert URI and Literal Nodes");
            }
        }