/// <summary> /// READ keyword /// Read a string from the device into a substring of the specified fixed string. /// </summary> /// <param name="readManager">A ReadManager instance to use</param> /// <param name="iostat">A reference variable that will be set to the I/O status</param> /// <param name="start">The 1-based start index of the target string</param> /// <param name="end">The 1-based end index of the target string</param> /// <param name="fixedstrVar">The fixed string identifier to read into</param> /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns> public static int READ(ReadManager readManager, ref int iostat, int start, int end, ref FixedString fixedstrVar) { if (readManager == null) { throw new ArgumentNullException("readManager"); } if (fixedstrVar == null) { throw new ArgumentNullException("fixedstrVar"); } if (end == -1) { end = fixedstrVar.Length; } FixedString fixedString = new FixedString((end - start) + 1); int charsRead = readManager.ReadString(ref fixedString); if (charsRead == -1) { iostat = IOError.ReadError; } else { fixedstrVar.Set(fixedString, start - 1, end - 1); } return charsRead; }
// Read a string, formatted from the file. int ReadStringFormatted(ref FixedString fixedstrVar) { int fieldWidth = 0; int charsRead = 0; int strSize = fixedstrVar.Length; // Handle a repeat count first if (_valueRepeatCount > 0) { if (_hasValueRepeat) { fixedstrVar = _valueRepeat.ToString(); } --_valueRepeatCount; return _valueCharCount; } // For input formats, only the field width is used and it // determines the fixed number of characters to read. FormatRecord record = Record(); if (record != null) { fieldWidth = record.FieldWidth; } if (fieldWidth > 0) { string realString = ReadChars(fieldWidth); int index = Math.Max(0, realString.Length - strSize); int length = Math.Min(strSize, realString.Length); fixedstrVar.Set(realString.Substring(index)); charsRead = length; } else { StringBuilder str = new StringBuilder(); char ch = ReadNonSpaceChar(); if (ch == '\'' && record == null) { ch = ReadChar(); while (ch != EOF && ch != EOL) { if (ch == '\'') { ch = ReadChar(); if (ch != '\'') { break; } } str.Append(ch); ++charsRead; ch = ReadChar(); } SkipSeparators(ch); } else { while (charsRead < strSize && ch != EOL && ch != EOF) { str.Append(ch); ch = ReadChar(); ++charsRead; } BackChar(); } fixedstrVar.Set(str.ToString()); } return charsRead; }