コード例 #1
0
        public void HasMoreShouldBeTrue_WhenIndex_IsLowerThanLength()
        {
            ParseStream stream = new ParseStream("/text");

            stream.Next();
            Assert.True(stream.HasMore);
        }
コード例 #2
0
        public void Forward_ShouldReturnNullChar_When_LastCharacterIsReached()
        {
            ParseStream stream = new ParseStream("/t");

            stream.Forward();
            Assert.AreEqual('\0', stream.Forward());
        }
コード例 #3
0
        public void NextShouldIncrementIndex()
        {
            ParseStream stream = new ParseStream("/text");

            stream.Next();

            Assert.AreEqual(stream.Index.Index, 1);
        }
コード例 #4
0
        public void CurrentCharShouldTheCharOfTheIndex()
        {
            ParseStream stream = new ParseStream("/text");

            stream.Next();

            Assert.AreEqual(stream.Current, 't');
        }
コード例 #5
0
ファイル: AuthorityPath.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Static method to build the correct AuthorityPath obj from a String
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        public static AuthorityPath buildAuthorityPath(string sPath)
        {
            ParseStream oStream = new ParseStream(sPath);
            AuthorityPath oPath = scanAuthority(oStream);

            // only return the path if the entire stream was consumed
            return (oStream.getData().Length == 0) ? oPath : null;
        }
コード例 #6
0
        public void NextCantMove_When_LastCharacterIsReached()
        {
            ParseStream stream = new ParseStream("/t");

            stream.Next();
            stream.Next();
            stream.Next();

            Assert.AreEqual(stream.Index.Index, 1);
        }
コード例 #7
0
        public void ShouldThrowError_WhenTheSecondCharIsNot_Letter()
        {
            ParseStream parseStream = new ParseStream("/1ab");
            TagParser   parser      = new TagParser(parseStream);

            UnexpectedTokenException ex = Assert.Throws <UnexpectedTokenException>(() => parser.Parse());

            Assert.AreEqual(1, ex.TokenIndex.Index);
            Assert.AreEqual('1', ex.Character);
        }
コード例 #8
0
        public void Create(string codeText, string value, string tagName, int index)
        {
            ParseStream parseStream = new ParseStream(codeText);
            TagParser   parser      = new TagParser(parseStream);
            TagToken    token       = parser.Parse();

            Assert.AreEqual(value, token.Value);
            Assert.AreEqual(tagName, token.TagName);
            Assert.AreEqual(index, parseStream.Index.Index);
        }
コード例 #9
0
        public void Create()
        {
            ParseStream stream = new ParseStream("/text");

            Assert.AreEqual(stream.Text, "/text");
            Assert.AreEqual(stream.Index.Line, 0);
            Assert.AreEqual(stream.Index.Index, 0);
            Assert.AreEqual(stream.Current, '/');
            Assert.False(stream.Launched);
        }
コード例 #10
0
        public void HasMoreShouldBeFalse_WhenIndex_IsAtTheLastCharacter()
        {
            ParseStream stream = new ParseStream("/text");

            stream.Next();
            stream.Next();
            stream.Next();
            stream.Next();

            Console.WriteLine(stream.Text.Length + "=" + stream.Index.Index);
            Assert.AreEqual(stream.Current, 't');
            Assert.False(stream.HasMore);
        }
コード例 #11
0
ファイル: XRIFragment.cs プロジェクト: AArnott/dotnetxri
        bool doScan(ParseStream oStream)
        {
            if (oStream.empty() || oStream.getData()[0] != '#')
                return false;

            oStream.consume(1);

            // read the characters, it is ok if they are empty
            int n = scanIFragmentChars(oStream.getData());
            oStream.consume(n);

            return true;
        }
コード例 #12
0
ファイル: XRINoSchemePath.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            // NOTE: A RelativePath can be empty
            if (oStream.empty())
            {
                return true;
            }

            // doesn't matter if this works or not, will consume what it needs to
            scanXRISegments(oStream);

            return true;
        }
コード例 #13
0
        public void Unfiltered2()
        {
            Parser p = new Parser(StringToStream("1 0 obj<</Length 2>>stream\rde\nendstream\nendobj"));
            ParseIndirectObject i = p.ParseIndirectObject() as ParseIndirectObject;

            Assert.NotNull(i);
            Assert.True(i.Id == 1);
            Assert.True(i.Gen == 0);
            Assert.NotNull(i.Object);

            ParseStream o = i.Object as ParseStream;

            Assert.NotNull(o);
            Assert.True(o.Value == "de");
        }
コード例 #14
0
        public void DeserializationMultipleMessageEntrepriseApplication()
        {
            Message message = new Message(0, 1, "Serialization - Message dans le bon format", "21/03/2015");
            User    user    = new User("Vincent", "Couvignou", "*****@*****.**", "19/03/2015", "masculin", true, null, null, null);
            DataContractJsonSerializer jsMessage = new DataContractJsonSerializer(typeof(Message));
            DataContractJsonSerializer jsUser    = new DataContractJsonSerializer(typeof(User));
            MemoryStream m = new MemoryStream();

            jsUser.WriteObject(m, user);
            jsMessage.WriteObject(m, message);

            m.Position = 0;
            StreamReader  s        = new StreamReader(m, Encoding.UTF8);
            List <string> listJson = ParseStream.ParseStreamToString(s);

            Assert.IsTrue(listJson.Count == 2);

            Message me = null;
            User    u  = null;

            foreach (var jsonItem in listJson)
            {
                StreamReader itemStream = new StreamReader(ParseStream.GenerateStreamFromString(jsonItem), Encoding.UTF8);
                var          userObject = JsonValue.Load(itemStream) as JsonObject;
                Assert.IsNotNull(userObject);
                MemoryStream mItem = new MemoryStream(Encoding.ASCII.GetBytes(jsonItem));
                if ((int)userObject["message_type"] == (int)MessageType.USER_INFORMATION)
                {
                    u = jsUser.ReadObject(mItem) as User;
                    Assert.IsTrue(true);
                }
                else if ((int)userObject["message_type"] == (int)MessageType.MESSAGE)
                {
                    me = jsMessage.ReadObject(mItem) as Message;
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.IsTrue(false);
                }
            }

            Assert.IsNotNull(u);
            Assert.IsNotNull(me);
            Assert.IsTrue(me.Equals(message));
            Assert.IsTrue(u.Equals(user) && me.Equals(message));
        }
コード例 #15
0
ファイル: RelativeXRI.cs プロジェクト: AArnott/dotnetxri
        static XRIPath scanXRIPath(ParseStream oStream)
        {
            // check for a local path regardless of scanAuthority outcome
            XRIAbsolutePath oPath = new XRIAbsolutePath();
            if (oPath.scan(oStream))
            {
                return oPath;
            }
            else
            {
                XRINoSchemePath oRelativePath = new XRINoSchemePath();
                if (oRelativePath.scan(oStream))
                {
                    return oRelativePath;
                }
            }

            return null;
        }
コード例 #16
0
ファイル: AuthorityPath.cs プロジェクト: AArnott/dotnetxri
        internal static AuthorityPath scanAuthority(ParseStream oParseStream)
        {
            GCSAuthority oGCSAuthority = new GCSAuthority();
            if (oGCSAuthority.scan(oParseStream))
            {
                return oGCSAuthority;
            }

            XRefAuthority oXRefAuthority = new XRefAuthority();
            if (oXRefAuthority.scan(oParseStream))
            {
                return oXRefAuthority;
            }

            IRIAuthority oIRIAuthority = new IRIAuthority();
            if (oIRIAuthority.scan(oParseStream))
            {
                return oIRIAuthority;
            }

            return null;
        }
コード例 #17
0
        public void ParseStreamToStringTest_1()
        {
            StreamReader s = new StreamReader("UserCorrectFormat_1.json", Encoding.UTF8);

            List <string> listJson = ParseStream.ParseStreamToString(s);

            Assert.IsTrue(listJson.Count == 1);
            MemoryStream memory       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(memory);

            streamWriter.Write(listJson[0]);
            streamWriter.Flush();
            memory.Position = 0;
            var user = JsonValue.Load(memory) as JsonObject;

            Assert.IsNotNull(user);
            Assert.IsTrue((int)user["message_type"] == (int)MessageType.USER_INFORMATION);

            s.Close();
            s = new StreamReader("UserCorrectFormat_1.json", Encoding.UTF8);
            DataContractJsonSerializer jsonUser = new DataContractJsonSerializer(typeof(User));
            MemoryStream m         = new MemoryStream(Encoding.ASCII.GetBytes(s.ReadToEnd()));
            User         userClass = jsonUser.ReadObject(m) as User;
        }
コード例 #18
0
ファイル: XRIAbsolutePath.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            // make sure we start with a slash
            if (oStream.empty() || (oStream.getData()[0] != '/'))
            {
                return false;
            }

            // consume the slash
            oStream.consume(1);

            // now scan the XRI segments as we are supposed to
            base.scanXRISegments(oStream);

            // return true no matter what, we got the slash
            return true;
        }
コード例 #19
0
ファイル: IRIAuthority.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Scans the Stream for a valid IRI-Authority
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        bool doScan(ParseStream oStream)
        {
            bool bVal = false;
            int n = scanChars(oStream.getData());
            string sData = oStream.getData().Substring(0, n);
            try
            {
                moURI = new Uri("http", sData, null, null, null);
                String sHost = moURI.Host;
                if ((sHost != null) && (sHost.Length > 0))
                {
                    char cFirst = sHost[0];
                    bool bCheckIP = char.IsDigit(cFirst) ||
                        (cFirst == '[');
                    bVal = bCheckIP ? verifyIP(sHost) : verifyDNS(sHost);
                }
            }
            catch (UriFormatException e)
            { }

            // consume and return true if valid
            if (bVal)
            {
                oStream.consume(n);
                return true;
            }

            return false;
        }
コード例 #20
0
 public CommentParser(ParseStream stream) : base(stream)
 {
 }
コード例 #21
0
ファイル: GCSAuthority.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            if (!scanGCSChar(oStream))
            {
                return false;
            }

            // read in a segment, but bail if it isn't persistent in the ! namespace
            XRISegment oSegment = new XRISegment(true, true, !msGCSRoot.Equals("!"));
            if (oSegment.scan(oStream))
            {
                moSegment = oSegment;
            }

            return true;
        }
コード例 #22
0
ファイル: XRIPath.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into XRISegmentVals
        /// </summary>
        /// <param name="oPathStream">The input stream to scan from</param>
        protected void scanXRISegments(ParseStream oPathStream)
        {
            // sets whether colons are allowed
            bool bAllowColon = mbAllowColon;

            // loop through the XRI segments as long as we are consuming something
            bool bConsumed = true;
            while (!oPathStream.empty() && bConsumed)
            {
                bConsumed = false;
                ParseStream oStream = oPathStream.begin();
                bool bStartsWithSlash = (oStream.getData()[0] == '/');

                // if this is the first segment, it must not start with slash
                if ((bStartsWithSlash) && (moSegments.Count == 0))
                {
                    break;
                }

                // if this is not the first segment, we expect a slash
                if ((!bStartsWithSlash) && (moSegments.Count > 0))
                {
                    break;
                }

                // consume the slash if necessary
                if (bStartsWithSlash)
                {
                    bConsumed = true;
                    oStream.consume(1);
                }

                // if there is actually a segment, add it to the list
                XRISegment oSegment = new XRISegment(true, bAllowColon, true);
                if (oSegment.scan(oStream))
                {
                    bConsumed = true;
                    moSegments.Add(oSegment);
                }

                // consume whatever we used (even if the segment was empty)
                oPathStream.end(oStream);

                // after the first segment, colons are allowed
                bAllowColon = true;
            }
        }
コード例 #23
0
ファイル: Parsable.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the set value.
        /// </summary>
        /// <remarks>
        /// Throws XRIParseException if entire value could not be parsed into the
        /// obj
        /// </remarks>
        protected void parse()
        {
            string value = msValue;

            // only do work if the value isn't already parsed
            if (!mbParsed)
            {
                ParseStream oStream = new ParseStream(msValue);

                if (scan(oStream))
                {
                    // Did we consume the entire string?
                    mbParseResult = oStream.getData().Length == 0;
                }

                // Set to true even if we fail, no need to fail over and over again.
                mbParsed = true;
            }

            // throw an exception if things failed
            if (!mbParseResult)
            {
                throw new XRIParseException(
                        "Not a valid " + this.GetType().Name +
                        " class: \"" + value + "\"");
            }
        }
コード例 #24
0
ファイル: GCSAuthority.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the GCS Character String
        /// </summary>
        /// <param name="oParseStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed</returns>
        private bool scanGCSChar(ParseStream oParseStream)
        {
            if (oParseStream.empty())
            {
                return false;
            }

            switch (oParseStream.getData()[0])
            {
                case '+':
                case '=':
                case '@':
                case '$':
                case '!':
                    {
                        // this way provides a clean copy, whereas substring does not
                        msGCSRoot = char.ToString(oParseStream.getData()[0]);
                        oParseStream.consume(1);
                        return true;
                    }
            }

            return false;
        }
コード例 #25
0
ファイル: XRISubSegment.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            if (oStream.getData()[0] == XRI.PDELIM)
            {
                this.mbPersistant = true;
                oStream.consume(1);
            }
            else if (oStream.getData()[0] == XRI.RDELIM)
            {
                oStream.consume(1);
            }
            else if (!mbAllowImpliedDelimiter)
            {
                return false;
            }

            // if there is a cross-reference, it has priority in scanning
            XRef oXRef = new XRef();
            if (oXRef.scan(oStream))
            {
                moXRef = oXRef;
                return true;
            }

            // read the characters, it is ok if they are empty
            int n = scanPChars(oStream.getData());
            oStream.consume(n);

            return true;
        }
コード例 #26
0
 public AttributeListParser(ParseStream stream) : base(stream)
 {
 }
コード例 #27
0
 public void BeforeEach()
 {
     stream = new ParseStream(text);
 }
コード例 #28
0
ファイル: Parsable.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Scans the stream for parts that can be parsed into the obj
        /// </summary>
        /// <param name="oParseStream">The input stream to read from</param>
        /// <returns>Returns true if all or part of the stream could be
        /// parsed into the obj</returns>
        public bool scan(ParseStream oParseStream)
        {
            if (oParseStream == null)
            {
                return false;
            }

            ParseStream oStream = oParseStream.begin();

            if (doScan(oStream))
            {
                setParsedValue(oParseStream.getConsumed(oStream));
                oParseStream.end(oStream);
                return true;
            }

            return false;
        }
コード例 #29
0
ファイル: RelativeXRI.cs プロジェクト: AArnott/dotnetxri
 /// <summary>
 /// Parses the input stream into the obj
 /// </summary>
 /// <param name="oStream">The input stream to scan from</param>
 /// <returns>True if part of the Stream was consumed into the obj</returns>
 bool doScan(ParseStream oStream)
 {
     moXRIPath = scanXRIPath(oStream);
     return true;
 }
コード例 #30
0
ファイル: XRef.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Returns a non-null String if an IRI is consumed from the stream
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        static string scanIRI(ParseStream oStream)
        {
            int n = scanIRIChars(oStream.getData());
            string data = oStream.getData().Substring(0, n);

            try
            {
                // try parsing to check validity, Java's URI parser may not be IRI compliant so
                // this is a TODO
                Uri u = new Uri(data);
                if (!u.IsAbsoluteUri)
                {
                    return null;
                }
            }
            catch (UriFormatException)
            {
                return null;
            }

            oStream.consume(n);
            return data;
        }
コード例 #31
0
 public HtmlCodeParser(ParseStream stream) : base(stream)
 {
 }
コード例 #32
0
 public Parser(ParseStream stream)
 {
     this.stream = stream;
 }
コード例 #33
0
        public void Forward_ShouldReturn_TheCurrentCharacter()
        {
            ParseStream stream = new ParseStream("/text");

            Assert.AreEqual('t', stream.Forward());
        }
コード例 #34
0
ファイル: Parsable.cs プロジェクト: AArnott/dotnetxri
 /// <summary>
 /// Scans the stream for parts that can be parsed into the obj
 /// </summary>
 /// <param name="oParseStream">The input stream to read from</param>
 /// <returns>Returns true if all or part of the stream could be
 /// parsed into the obj</returns>
 protected abstract bool doScan(ParseStream oParseStream);
コード例 #35
0
 public TagParser(ParseStream stream) : base(stream)
 {
 }
コード例 #36
0
ファイル: XRefAuthority.cs プロジェクト: AArnott/dotnetxri
        bool doScan(ParseStream oStream)
        {
            if (oStream.empty())
            {
                return false;
            }

            ParseStream oTempStream = oStream.begin();

            // make sure we have a valid XRI Value
            XRef oXRef = new XRef();
            if (!oXRef.scan(oTempStream))
            {
                return false;
            }

            // at this point, we know we have enough for a valid xref
            oStream.end(oTempStream);
            moXRoot = oXRef;

            // the cross-reference MAY be followed by an XRI Segment
            // where the star cannot be assumed
            XRISegment oSegment = new XRISegment(false, true, true);
            if (oSegment.scan(oStream))
            {
                moSegment = oSegment;
            }

            return true;
        }
コード例 #37
0
ファイル: XRef.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Returns a non-null XRIReference if an XRIReference is consumed from the 
        /// stream
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        static XRIReference scanXRIReference(ParseStream oStream)
        {
            // make sure we have a valid XRI Value
            XRI oXRI = new XRI();
            if (oXRI.scan(oStream))
            {
                return oXRI;
            }

            // try parsing it as a relative XRI
            RelativeXRI oRelXRI = new RelativeXRI();
            if (oRelXRI.scan(oStream))
            {
                return oRelXRI;
            }

            return null;
        }
コード例 #38
0
ファイル: XRef.cs プロジェクト: AArnott/dotnetxri
        bool doScan(ParseStream oStream)
        {
            if (oStream.empty())
            {
                return false;
            }

            if (oStream.getData()[0] != '(')
            {
                return false;
            }

            ParseStream oTempStream = oStream.begin();
            oTempStream.consume(1);

            String sIRI = null;
            // make sure we have a valid XRI reference
            XRIReference oRef = scanXRIReference(oTempStream);
            if (oRef == null || oTempStream.empty() || (oTempStream.getData()[0] != ')'))
            {
                // if we got a reference, but the resulting temp stream is empty or does not begin with ')'
                // it got parsed wrongly (happens if the XRef is an IRI). Retry parsing with an IRI
                if (oRef != null)
                {
                    oTempStream = oStream.begin();
                    oTempStream.consume(1);
                }
                // if there is no XRI Reference, see if it is an IRI
                sIRI = scanIRI(oTempStream);
                if (sIRI == null)
                {
                    return false;
                }
            }

            // make sure we have the trailing ')'
            if (oTempStream.empty() || (oTempStream.getData()[0] != ')'))
            {
                return false;
            }

            // at this point, complete consumption and return true
            oTempStream.consume(1);
            oStream.end(oTempStream);
            moXRIRef = oRef;
            msIRI = sIRI;

            return true;
        }
コード例 #39
0
 public HtmlEntityParser(ParseStream stream) : base(stream)
 {
 }
コード例 #40
0
ファイル: XRISegment.cs プロジェクト: AArnott/dotnetxri
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oXRISegStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oXRISegStream)
        {
            moSubSegments = new List<XRISubSegment>();
            bool bAllowImpliedDelimiter = mbAllowImpliedDelimiter;
            bool bAllowReassignable = mbAllowReassignable;

            // loop through the stream, but don't consume the real string unless
            // we are successful
            while (!oXRISegStream.empty())
            {
                // determine if we have a delimiter for the next subsegment
                char c = oXRISegStream.getData()[0];

                // break out if the first character has to be persistent and isn't
                if ((!bAllowReassignable) && (c != XRI.PDELIM))
                {
                    break;
                }

                // check if we have a valid non-null subsegment
                XRISubSegment oSubSegment = new XRISubSegment(bAllowImpliedDelimiter, mbAllowColon);
                if (oSubSegment.scan(oXRISegStream))
                {
                    // if we had a valid sub-segment, consume it and add it to the list
                    moSubSegments.Add(oSubSegment);
                }
                else
                {
                    break;
                }

                bAllowImpliedDelimiter = false;
                bAllowReassignable = true;
            }

            // if we have subsegments, we are good.  Otherwise, it is an error
            if (moSubSegments.Count > 0)
            {
                return true;
            }

            moSubSegments = null;
            return false;
        }