public FieldImpl(PlexOfField startPlex, PlexOfField separatorPlex, PlexOfField endPlex) { if (startPlex == null) { throw new ArgumentException("startPlex == null"); } if (endPlex == null) { throw new ArgumentException("endPlex == null"); } if (startPlex.Fld.GetBoundaryType() != FieldDescriptor.FIELD_BEGIN_MARK) { throw new ArgumentException("startPlex (" + startPlex + ") is not type of FIELD_BEGIN"); } if (separatorPlex != null && separatorPlex.Fld.GetBoundaryType() != FieldDescriptor.FIELD_SEPARATOR_MARK) { throw new ArgumentException("separatorPlex" + separatorPlex + ") is not type of FIELD_SEPARATOR"); } if (endPlex.Fld.GetBoundaryType() != FieldDescriptor.FIELD_END_MARK) { throw new ArgumentException("endPlex (" + endPlex + ") is not type of FIELD_END"); } this.startPlex = startPlex; this.separatorPlex = separatorPlex; this.endPlex = endPlex; }
private String DumpPlexes(List <PlexOfField> fieldsPlexes) { StringBuilder dump = new StringBuilder(); for (int i = 0; i < fieldsPlexes.Count; i++) { PlexOfField flds = fieldsPlexes[i]; dump.Append(flds.ToString() + "\n"); } return(dump.ToString()); }
private void ParseFieldStructureImpl(List <PlexOfField> plexOfFields, int startOffsetInclusive, int endOffsetExclusive, List <FieldImpl> result) { int next = startOffsetInclusive; while (next < endOffsetExclusive) { PlexOfField startPlexOfField = plexOfFields[next]; if (startPlexOfField.Fld.GetBoundaryType() != FieldDescriptor.FIELD_BEGIN_MARK) { /* Start mark seems to be missing */ next++; continue; } /* * we have start node. end offset points to next node, separator or * end */ int nextNodePositionInList = BinarySearch(plexOfFields, next + 1, endOffsetExclusive, startPlexOfField.FcEnd); if (nextNodePositionInList < 0) { /* * too bad, this start field mark doesn't have corresponding end * field mark or separator field mark in fields table */ next++; continue; } PlexOfField nextPlexOfField = plexOfFields [nextNodePositionInList]; switch (nextPlexOfField.Fld.GetBoundaryType()) { case FieldDescriptor.FIELD_SEPARATOR_MARK: { PlexOfField separatorPlexOfField = nextPlexOfField; int endNodePositionInList = BinarySearch(plexOfFields, nextNodePositionInList, endOffsetExclusive, separatorPlexOfField.FcEnd); if (endNodePositionInList < 0) { /* * too bad, this separator field mark doesn't have * corresponding end field mark in fields table */ next++; continue; } PlexOfField endPlexOfField = plexOfFields [endNodePositionInList]; if (endPlexOfField.Fld.GetBoundaryType() != FieldDescriptor.FIELD_END_MARK) { /* Not and ending mark */ next++; continue; } FieldImpl field = new FieldImpl(startPlexOfField, separatorPlexOfField, endPlexOfField); result.Add(field); // Adding included fields if (startPlexOfField.FcStart + 1 < separatorPlexOfField .FcStart - 1) { ParseFieldStructureImpl(plexOfFields, next + 1, nextNodePositionInList, result); } if (separatorPlexOfField.FcStart + 1 < endPlexOfField .FcStart - 1) { ParseFieldStructureImpl(plexOfFields, nextNodePositionInList + 1, endNodePositionInList, result); } next = endNodePositionInList + 1; break; } case FieldDescriptor.FIELD_END_MARK: { // we have no separator FieldImpl field = new FieldImpl(startPlexOfField, null, nextPlexOfField); result.Add(field); // Adding included fields if (startPlexOfField.FcStart + 1 < nextPlexOfField .FcStart - 1) { ParseFieldStructureImpl(plexOfFields, next + 1, nextNodePositionInList, result); } next = nextNodePositionInList + 1; break; } case FieldDescriptor.FIELD_BEGIN_MARK: default: { /* something is wrong, ignoring this mark along with start mark */ next++; continue; } } } }