} //readIndexes // Get card data for MGC format file private String mgcData(BinaryReader br) { // Read the file but for text only, ignore Graphics // format when either Graphics (G), Text (T) or both G&T // Byte numbers // G & T T G // 0 : 1 0:1 0 : 1 Length of graphic bitmap (lob) // 2 : 3 2 : 3 Width // 4 : 5 4 : 5 Height // 6 : 7 6 : 7 X-co-ord // 8 : 9 8 : 9 Y-co-ord // 10 : eob 10 : eob Bitmap Graphic // eob+1 : // +2 2:3 eob+1 : // +2 Length of text entry (lot) // eob +3 : // end 4:lot eob +3 : // end Text data Int16 bitmapLen = br.ReadInt16(); // 1st two bytes of card data Int16 num = br.ReadInt16(); // 2nd two bytes - either text length (T) or bitmap width (G & GT) String txtData = String.Empty; if (bitmapLen + num == 0) { CardFile.Log.writeLn("Card with no data"); } else if (bitmapLen == 0 && num > 0) // Text only card { debugLn("Text only card"); Int16 txtLen = num; txtData = new string( chrd.ReadChars(txtLen), 0, txtLen ); // last arg is length debugLn("Card Text Length: " + txtLen); CardFile.Log.writeLn("Card Data:"); CardFile.Log.writeLn(txtData); debugLn("End of Text only card\n"); } else // Graphic data, maybe text too { CardFile.Log.writeLn("Has Graphic"); debugLn("Bitmap length: " + bitmapLen); Int16 bitmapWidth = num; Int16 bitmapHeight = br.ReadInt16(); Int16 Xoffset = br.ReadInt16(); Int16 Yoffset = br.ReadInt16(); br.ReadBytes(bitmapLen); // read but discard bitmap, to advance file ptr Int16 txtLen = br.ReadInt16(); // text length field //char[] txtData = chrd.ReadChars(txtLen); txtData = new string( chrd.ReadChars(txtLen), 0, txtLen ); // last arg is length CardFile.Log.writeLn("Card data: "); CardFile.Log.writeLn(txtData); debugLn("End of Text only card\n"); } //if return(txtData); } //mgcData
public String[] ReadFields() { Char previewChar = Char.MinValue; Char currentChar = Char.MinValue; Char nextChar = Char.MinValue; if (_charReader.ReadChars(out currentChar, out nextChar) == false) { return(null); } Int32 currentFieldNumber = -1; FieldBuilder currentFieldBuilder; this.PrepareNextField(ref currentFieldNumber, out currentFieldBuilder); Boolean quoteMode = false; do { if (currentChar == '"') { if (quoteMode) { if (nextChar == '"') { currentFieldBuilder.Append('"'); _charReader.SkipNextChar(); } else if (nextChar == Char.MinValue || // конец файла nextChar == ',' || // конец поля nextChar == '\r' // конец записи ) { quoteMode = false; } else { currentFieldBuilder.Append('"'); } } else { if (previewChar == Char.MinValue || // начало файла previewChar == ',' || // начало поля previewChar == '\n' // начало записи ) { quoteMode = true; } else { currentFieldBuilder.Append('"'); } } } else if (currentChar == ',') { if (quoteMode) { currentFieldBuilder.Append(currentChar); } else { this.PrepareNextField(ref currentFieldNumber, out currentFieldBuilder); } } else if (currentChar == '\r') { if (nextChar != '\n') { currentFieldBuilder.AppendEndLine(); } } else if (currentChar == '\n') { if (quoteMode == false && previewChar == '\r') { break; } else { currentFieldBuilder.AppendEndLine(); } } else { currentFieldBuilder.Append(currentChar); } previewChar = currentChar; } while (_charReader.ReadChars(out currentChar, out nextChar)); String[] fields = new String[currentFieldNumber + 1]; for (Int32 i = 0; i < fields.Length; i += 1) { FieldBuilder fieldBuilder = _fieldBuilderList[i]; fields[i] = fieldBuilder.ToString(); } return(fields); }