public override IEnumerable <TokenBase> GetTokens() { var top = new TokenIndex(); string line; while ((line = _reader.ReadLine()) != null) { if (string.IsNullOrEmpty(line)) { continue; } var p = new XElement("p"); var property = new TextVisualProperties { TextIndent = 32.0, Inline = false }; yield return(new TagOpenToken(top.Index++, p, property, -1)); foreach (TokenBase baseToken in ParseText(line, top)) { yield return(baseToken); } yield return(new TagCloseToken(top.Index++, -1)); } }
private void DeleteIndex(Block block) { if (block.Transactions == null) { return; } if (block.Header.Index == 0) //genesis block { OwnerIndex.DeleteIndex(); } foreach (var record in block.Transactions) { if (record is TransactionToken) { TokenIndex.DeleteIndex(record as TransactionToken); } else if (record is TransactionTransfer) { BalanceIndex.DeleteIndex(record as TransactionTransfer); } else if (record is TransactionOrderLimit) { OrderIndex.DeleteIndex(record as TransactionOrderLimit); } } }
private void ProcessAnchors(TokenIndex top, XElement xelement) { XAttribute attribute = xelement.Attributes().FirstOrDefault(t => (t.Name.LocalName == "id")); if (attribute != null) { _anchors[attribute.Value] = top.Index; } }
public void TokenShouldHaveHaveStartIndexHasIndex() { TagParser parser = new TagParser(stream); TokenIndex startIndex = parser.Index; TagToken token = parser.Parse(); Assert.AreEqual(startIndex.Index, token.Index.Index); }
public override IEnumerable <TokenBase> GetTokens() { var propertiesStack = new Stack <TextVisualProperties>(); var item = new TextVisualProperties(); propertiesStack.Push(item); var top = new TokenIndex(); return(_root.Elements(_ns + "body").SelectMany(b => ParseNodes(b, propertiesStack, top, 0))); }
private void ParseAnchors(TokenIndex top, EpubPath path, HtmlNode node) { foreach (string str in new[] { "id", "name" }) { string attributeValue = node.GetAttributeValue(str, string.Empty); if (!string.IsNullOrEmpty(attributeValue)) { AddAnchor(top, path.CurrentFilePath + "#" + attributeValue); } } }
private void ProcessTitleData(TokenIndex top, XElement xelement, int bookLevel) { var item = new BookChapter { Level = bookLevel, Title = GetText(xelement), TokenID = top.Index }; _chapters.Add(item); }
public void Test_Id_TokenIndexSetter_FhirString_IsNull() { //Arrange Id Id = null; TokenIndex Index = new TokenIndex(); //Act ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(Id, Index) as TokenIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>()); }
public void UpdateIndex(Block block) { if (block.Transactions == null) { return; } if (block.Header.Index == 0) //genesis block { //Create owner index string ownerAddress = null; foreach (var record in block.Transactions) { if (record is TransactionTransfer) { ownerAddress = ((TransactionTransfer)record).ToAddress; break; } } OwnerIndex.AddToIndex(ownerAddress); } foreach (var record in block.Transactions) { if (record is TransactionToken) { TokenIndex.AddToIndex(record as TransactionToken); } else if (record is TransactionTransfer) { BalanceIndex.AddToIndex(record as TransactionTransfer); } else if (record is TransactionOrderLimit) { OrderIndex.AddToIndex(record as TransactionOrderLimit); } else if (record is TransactionOrderMatch) { OrderIndex.UpdateIndexForMatchedOrder(record as TransactionOrderMatch); } else if (record is TransactionOrderCancel) { OrderIndex.DeleteSingleTransaction((record as TransactionOrderCancel).OrderTransactionId); } else if (record is TransactionBlockFee) { BalanceIndex.AddToFeeIndex(record as TransactionBlockFee); } } //Delete expired orders from index OrderIndex.DeleteExpiredOrders(block.Header.Index); }
public void Test_PositiveInt_TokenIndexSetter_Identifier_IsNull() { //Arrange PositiveInt PositiveInt = null; TokenIndex Index = new TokenIndex(); //Act ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(PositiveInt, Index) as TokenIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>()); }
public void Test_Quantity_TokenIndexSetter_Quantity_IsNull() { //Arrange Quantity Quantity = null; TokenIndex Index = new TokenIndex(); //Act ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(Quantity, Index) as TokenIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>()); }
public void Test_Address_TokenIndexSetter_No_Code_Set() { //Arrange var Code = new Code <Bundle.BundleType>(); TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_ContactPoint_TokenIndexSetter_No_Code_Set() { //Arrange var Code = new ContactPoint(); TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
protected IEnumerable <TokenBase> ParseText(string text, TokenIndex top) { foreach (string word in text.BreakToWords()) { if (string.IsNullOrEmpty(word)) { yield return(new WhitespaceToken(top.Index++)); } else { yield return(new TextToken(top.Index++, HttpUtility.HtmlDecode(word))); } } }
public void Test_Quantity_TokenIndexSetter_Value_IsNull() { //Arrange var Quantity = new Quantity(); Quantity.Value = null; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Quantity, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_FhirBoolean_TokenIndexSetter_No_Code_Set_As_Null() { //Arrange var FhirBoolean = new FhirBoolean(); FhirBoolean.Value = null; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirBoolean, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_PositiveInt_TokenIndexSetter_Value_IsNull() { //Arrange var PositiveInt = new PositiveInt(); PositiveInt.Value = null; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(PositiveInt, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_Coding_TokenIndexSetter_OnlySystem() { //Arrange string TheSystem = "SomeCodeSystem"; var Coding = new Coding(); Coding.System = TheSystem; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Coding, Index) as TokenIndex; //Assert Assert.IsNull(Index.Code); Assert.AreEqual(Index.System, TheSystem); }
public void Test_Id_TokenIndexSetter_EmptyString() { //Arrange string TheCode = string.Empty; var Id = new Id(); Id.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Id, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_Code_TokenIndexSetter_No_Code_Set() { //Arrange string CodeString = ""; var Code = new Code(); Code.Value = CodeString; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_FhirString_TokenIndexSetter_EmptyString() { //Arrange string TheCode = string.Empty; var FhirDateTime = new FhirString(); FhirDateTime.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirDateTime, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_FhirDate_TokenIndexSetter_BadFormat() { //Arrange string TheCode = "2012-12-28T09:03:04+11:90"; var FhirDateTime = new FhirDateTime(); FhirDateTime.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirDateTime, Index) as TokenIndex; //Assert Assert.IsNull(Index); }
public void Test_ContactPoint_TokenIndexSetter_OnlyCode() { //Arrange string TheValue = "*****@*****.**"; var ContactPoint = new ContactPoint(); ContactPoint.Value = TheValue; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(ContactPoint, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, TheValue); Assert.IsNull(Index.System); }
public void Test_Address_TokenIndexSetter_CodeT_IsNull() { //Arrange Bundle.BundleType TheCode = Bundle.BundleType.Document; string CodeString = TheCode.GetLiteral(); //string CodeString = Hl7.Fhir.Introspection.EnumMapping.Create(typeof(Hl7.Fhir.Model.Bundle.BundleType)).GetLiteral(TheCode); Code <Bundle.BundleType> Code = null; TokenIndex Index = new TokenIndex(); //Act ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>()); }
/// <summary> /// Returns the TokenIndex of the next token in File or null if no such token exists. /// </summary> /// <exception cref="FileContentException"> /// The line or index are no longer within the associated file. /// </exception> public TokenIndex?Next() { if (!this.IsWithinFile()) { throw new FileContentException("Token index is no longer valid within its associated file."); } var res = new TokenIndex(this); if (++res.Index < res.file.GetTokenizedLine(res.Line).Length) { return(res); } res.Index = 0; while (++res.Line < res.file.NrTokenizedLines() && res.file.GetTokenizedLine(res.Line).Length == 0) { } return(res.Line == res.file.NrTokenizedLines() ? null : res); }
/// <summary> /// Returns the TokenIndex of the previous token in File or null if no such token exists. /// </summary> /// <exception cref="FileContentException"> /// The line or index are no longer within the associated file. /// </exception> public TokenIndex?Previous() { if (!this.IsWithinFile()) { throw new FileContentException("Token index is no longer valid within its associated file."); } var res = new TokenIndex(this); if (res.Index-- > 0) { return(res); } while (res.Index < 0 && res.Line-- > 0) { res.Index = res.file.GetTokenizedLine(res.Line).Length - 1; } return(res.Line < 0 ? null : res); }
public void Test_Code_TokenIndexSetter_GoodFormat() { //Arrange string CodeString = "SomeCode"; var Code = new Code(); Code.Value = CodeString; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, CodeString); Assert.IsNull(Index.System); }
public void Test_FhirBoolean_TokenIndexSetter_GoodFormatFalse() { //Arrange bool TheCode = false; var Code = new FhirBoolean(); Code.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, "false"); Assert.IsNull(Index.System); }
public void Test_FhirString_TokenIndexSetter_GoodFormat() { //Arrange string TheCode = "Some string stuff"; var FhirDateTime = new FhirString(); FhirDateTime.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirDateTime, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, TheCode); Assert.IsNull(Index.System); }
public void Test_Id_TokenIndexSetter_GoodFormat() { //Arrange string TheCode = "4d09741b-e407-4a1f-808a-4b9bf864d956"; var Id = new Id(); Id.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Id, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, TheCode); Assert.IsNull(Index.System); }
/// <summary> /// Gets the next token. /// </summary> /// <returns> /// The next token. /// </returns> public Token GetNextToken() { //first: skip all whitespace and comments on the way SkipWhitespaceOrComments(); //check for eof if (AtEndOfSource) { return null; } //between a and z -> word if (current >= CharLowercaseA && current <= CharLowercaseZ) { TokenWord token = new TokenWord(); token.Line = line; token.Column = column; List<byte> buffer = new List<byte>(); do { buffer.Add(current); ReadNextChar(); } while (!AtEndOfSource && ((current >= CharLowercaseA && current <= CharLowercaseZ) || current == CharUnderscore)); token.Word = Encoding.ASCII.GetString(buffer.ToArray()); return token; } //[ -> index if (current == CharLeftBracket) { TokenIndex token = new TokenIndex(); token.Line = line; token.Column = column; ReadNextChar(); if (current < CharZero || current > CharNine) { ThrowInvalidCharException(); } else { token.I = current - CharZero; } ReadNextChar(); if (current != CharRightBracket) { ThrowInvalidCharException(); } ReadNextChar(); return token; } //" -> string if (current == CharDoubeQuote) { TokenString token = new TokenString(); token.Line = line; token.Column = column; List<byte> buffer = new List<byte>(); while (current == CharDoubeQuote) { while (true) { ReadNextChar(); CheckForUnexpectedEndOfSource(); if (current == CharDoubeQuote) { break; } else if (current == CharBackslash) { //escape sequence! ReadNextChar(); if (current == CharLowercaseA) { //a buffer.Add(CharBell); } else if (current == 0x62) { //b buffer.Add(CharBackspace); } else if (current == 0x73) { //t buffer.Add(CharTab); } else if (current == 0x6E) { //n buffer.Add(CharLineFeed); } else if (current == 0x76) { //v buffer.Add(CharVerticalTab); } else if (current == 0x66) { //f buffer.Add(CharFormFeed); } else if (current == 0x72) { //r buffer.Add(CharCarriageReturn); } else if (current == CharDoubeQuote) { //" buffer.Add(CharDoubeQuote); } else if (current == CharSingleQuote) { //' buffer.Add(CharSingleQuote); } else if (current == CharQuestionMark) { //? buffer.Add(CharQuestionMark); } else if (current == CharBackslash) { //\ buffer.Add(CharBackslash); } else { ThrowInvalidCharException(); } } else { buffer.Add(current); } } //there may be another string right behind which needs to be concatenated ReadNextChar(); SkipWhitespaceOrComments(); } token.Data = buffer.ToArray(); return token; } //the char has to be invalid ThrowInvalidCharException(); return null; }