static StackObject *ReadBlock_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 4); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @count = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Int32 @index = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 3); System.Char[] @buffer = (System.Char[]) typeof(System.Char[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 4); System.IO.TextReader instance_of_this_method = (System.IO.TextReader) typeof(System.IO.TextReader).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.ReadBlock(@buffer, @index, @count); __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method; return(__ret + 1); }
public string ReadNext() { lock (sync) { int bytesAmount = source.ReadBlock(this.buffer, 0, this.Batch); if (bytesAmount == 0) { var lastPart = this.leftFromPreviousRead.ToString(); this.leftFromPreviousRead = new StringBuilder(); return(string.IsNullOrWhiteSpace(lastPart) ? null : lastPart); } const char Space = ' '; var result = this.leftFromPreviousRead; // read stream to the end if (bytesAmount < this.Batch) { result.Append(this.buffer, 0, bytesAmount); this.leftFromPreviousRead = new StringBuilder(); return(result.ToString()); } int lastSpaceIndex = LastIndexOf(this.buffer, bytesAmount - 1, Space); if (lastSpaceIndex == -1) { throw new NotSupportedException( $"Incoming text does not have spaces at fragment of {this.Batch} bytes, try to increase buffer size"); } result.Append(this.buffer, 0, lastSpaceIndex); this.leftFromPreviousRead = new StringBuilder(new string(this.buffer, lastSpaceIndex + 1, bytesAmount - lastSpaceIndex - 1)); return(result.ToString()); } }
private void ReadIniFromTextStream(System.IO.TextReader Stream, IniReadErrorEventHandler IniReadErrorCallback) { StringBuilder lineBuffer = new StringBuilder(); int lineCount = 0; string pun = null, anothertmpStr; string[] splitBuffer = null; IniSection sectionBuffer = null; char[] buffer = new char[1]; char[] spli = new char[] { '=' }; DuplicatedKeyCollection dkc = new DuplicatedKeyCollection(); /*try * {//*/ int buffercount = Stream.ReadBlock(buffer, 0, 1); while (buffercount > 0) { switch (buffer[0]) { case ControlChars.Lf: lineCount++; pun = lineBuffer.ToString(); lineBuffer.Clear(); if (!string.IsNullOrWhiteSpace(pun)) { // move this line here because no need to check for every read char if (pun.StartsWith("[") && pun.EndsWith("]")) { anothertmpStr = pun.Substring(1, pun.Length - 2); sectionBuffer = new IniSection(false); if (!this.o_Sections.TryAdd(anothertmpStr, sectionBuffer)) { dkc.Add(anothertmpStr, lineCount, KeyType.Section); } } else if (pun.IndexOf(spli[0]) > -1) { if (sectionBuffer != null) { splitBuffer = pun.Split(spli, 2); bool isComment = false; if (splitBuffer[0].StartsWith(";")) { isComment = true; splitBuffer[0] = splitBuffer[0].Remove(0, 1); } if (!string.IsNullOrWhiteSpace(splitBuffer[0])) { anothertmpStr = splitBuffer[0].Trim(); if (splitBuffer.Length == 1) { if (!sectionBuffer.IniKeyValues.TryAdd(anothertmpStr, new IniKeyValue(string.Empty, isComment))) { dkc.Add(anothertmpStr, lineCount, KeyType.KeyValue); } } else { if (string.IsNullOrEmpty(splitBuffer[1])) { if (!sectionBuffer.IniKeyValues.TryAdd(anothertmpStr, new IniKeyValue(string.Empty, isComment))) { dkc.Add(anothertmpStr, lineCount, KeyType.KeyValue); } } else { if (string.IsNullOrWhiteSpace(splitBuffer[1])) { if (!sectionBuffer.IniKeyValues.TryAdd(anothertmpStr, new IniKeyValue(string.Empty, isComment))) { dkc.Add(anothertmpStr, lineCount, KeyType.KeyValue); } } else { if (!sectionBuffer.IniKeyValues.TryAdd(anothertmpStr, new IniKeyValue(this.UnescapeValue(splitBuffer[1].Trim()), isComment))) { dkc.Add(anothertmpStr, lineCount, KeyType.KeyValue); } } } } } } } else { dkc.Add(this.UnescapeValue(pun), lineCount, KeyType.Unknown); } } break; case ControlChars.Cr: break; case ControlChars.NullChar: break; default: lineBuffer.Append(buffer[0]); break; } buffercount = Stream.ReadBlock(buffer, 0, 1); } pun = lineBuffer.ToString(); if (!string.IsNullOrWhiteSpace(pun)) { //This will make sure last line without \n will not be discarded if (pun.StartsWith("[") && pun.EndsWith("]")) { anothertmpStr = pun.Substring(1, lineBuffer.Length - 2); sectionBuffer = new IniSection(false); if (!this.o_Sections.TryAdd(anothertmpStr, sectionBuffer)) { dkc.Add(anothertmpStr, lineCount, KeyType.Section); } lineBuffer.Clear(); } else if (pun.IndexOf(spli[0]) > -1) { splitBuffer = pun.Split(spli, 2); anothertmpStr = splitBuffer[0].Trim(); // make sure it split just one time if (!sectionBuffer.IniKeyValues.TryAdd(anothertmpStr, new IniKeyValue(this.UnescapeValue(splitBuffer[1].Trim())))) { dkc.Add(anothertmpStr, lineCount, KeyType.KeyValue); } lineBuffer.Clear(); } else { dkc.Add(this.UnescapeValue(pun), lineCount, KeyType.Unknown); } } if (dkc.Count > 0) { if (IniReadErrorCallback != null) { IniReadErrorCallback.Invoke(this, new IniReadErrorEventArgs(dkc)); } } /*} * catch (Exception ex) * { * if (IniReadErrorCallback != null) * { * if (dkc.Count > 0) * IniReadErrorCallback.Invoke(this, new IniReadErrorEventArgs(dkc, ex)); * else * IniReadErrorCallback.Invoke(this, new IniReadErrorEventArgs(ex)); * } * }//*/ spli = null; sectionBuffer = null; lineBuffer = null; splitBuffer = null; }