bool FastLogReader::ReadTextColumns(REF std::wstring16& buffer, REF std::vector<FastLogReader::Seg>& segs, WCHAR separator) { if (IsEof()) return false; buffer.clear(); segs.clear(); int pb = 0, pc = 0; while (!IsEof()) { WCHAR ch = ReadChar(); buffer += ch; if (ch == separator) { segs.push_back(Seg(pb, pc - pb)); pb = pc + 1; } else if (ch == 10) // \n { segs.push_back(Seg(pb, pc - pb)); return true; } else if (ch == 13) // \r, \r\n { if (PeekByte() == 10) ReadByte(); segs.push_back(Seg(pb, pc - pb)); return true; } ++pc; } return true; }
ref<StringArrayList> FastLogReader::ReadTextColumns(WCHAR separator) { if (IsEof()) return NULL; std::wstring16 seg; ref<StringArrayList> r = gc_new<StringArrayList>(); while (!IsEof()) { WCHAR ch = ReadChar(); if (ch == separator) { r->Add(stringx(seg)); seg.clear(); } else if (ch == 10) // \n { r->Add(stringx(seg)); return r; } else if (ch == 13) // \r, \r\n { if (PeekByte() == 10) ReadByte(); r->Add(stringx(seg)); return r; } else seg += ch; } r->Add(stringx(seg)); return r; }
String Deserializer::ReadLine() { String ret; while (!IsEof()) { char c = ReadByte(); if (c == 10) break; if (c == 13) { // Peek next char to see if it's 10, and skip it too if (!IsEof()) { char next = ReadByte(); if (next != 10) Seek(position_ - 1); } break; } ret += c; } return ret; }
BOOL CADORecordset::Find(LPCTSTR lpFind, int nSearchDirection) { m_strFind = lpFind; m_nSearchDirection = nSearchDirection; ASSERT(!m_strFind.IsEmpty()); if(m_nSearchDirection == searchForward) { m_pRecordset->Find(_bstr_t(m_strFind), 0, adSearchForward, ""); if(!IsEof()) { m_varBookFind = m_pRecordset->Bookmark; return TRUE; } } else if(m_nSearchDirection == searchBackward) { m_pRecordset->Find(_bstr_t(m_strFind), 0, adSearchBackward, ""); if(!IsBof()) { m_varBookFind = m_pRecordset->Bookmark; return TRUE; } } else { TRACE("Unknown parameter. %d", nSearchDirection); m_nSearchDirection = searchForward; } return FALSE; }
unsigned File::GetChecksum() { if (offset_ || checksum_) return checksum_; #ifdef __ANDROID__ if ((!handle_ && !assetHandle_) || mode_ == FILE_WRITE) #else if (!handle_ || mode_ == FILE_WRITE) #endif return 0; ATOMIC_PROFILE(CalculateFileChecksum); unsigned oldPos = position_; checksum_ = 0; Seek(0); while (!IsEof()) { unsigned char block[1024]; unsigned readBytes = Read(block, 1024); for (unsigned i = 0; i < readBytes; ++i) checksum_ = SDBMHash(checksum_, block[i]); } Seek(oldPos); return checksum_; }
unsigned HttpRequest::Read(void* dest, unsigned size) { #ifdef URHO3D_THREADING mutex_.Acquire(); unsigned char* destPtr = (unsigned char*)dest; unsigned sizeLeft = size; unsigned totalRead = 0; for (;;) { unsigned bytesAvailable; for (;;) { bytesAvailable = CheckEofAndAvailableSize(); if (bytesAvailable || IsEof()) break; // While no bytes and connection is still open, block until has some data mutex_.Release(); Time::Sleep(5); mutex_.Acquire(); } if (bytesAvailable) { if (bytesAvailable > sizeLeft) bytesAvailable = sizeLeft; if (readPosition_ + bytesAvailable <= READ_BUFFER_SIZE) memcpy(destPtr, readBuffer_.Get() + readPosition_, bytesAvailable); else { // Handle ring buffer wrap unsigned part1 = READ_BUFFER_SIZE - readPosition_; unsigned part2 = bytesAvailable - part1; memcpy(destPtr, readBuffer_.Get() + readPosition_, part1); memcpy(destPtr + part1, readBuffer_.Get(), part2); } readPosition_ += bytesAvailable; readPosition_ &= READ_BUFFER_SIZE - 1; sizeLeft -= bytesAvailable; totalRead += bytesAvailable; destPtr += bytesAvailable; } if (!sizeLeft || !bytesAvailable) break; } // Check for end-of-file once more after reading the bytes CheckEofAndAvailableSize(); mutex_.Release(); return totalRead; #else // Threading disabled, nothing to read return 0; #endif }
uint32 File::ReadLine(void * pointerToData, uint32 bufferSize) { uint8 *inPtr = (uint8*)pointerToData; while(!IsEof()) { uint8 nextChar; uint32 actuallyRead = Read(&nextChar, 1); if(actuallyRead != 1)break; if(nextChar == '\n')break; if(nextChar == 0)break; if(nextChar == '\r') { if(Read(&nextChar, 1) && nextChar != '\n') { Seek(-1, File::SEEK_FROM_CURRENT); } break; } *inPtr = nextChar; inPtr++; } *inPtr = 0; return (uint32)(inPtr - (uint8*)pointerToData); }
BOOL CGuiRecordSet::Find(LPCTSTR Criteria , long SkipRecords , SearchDirectionEnum SearchDirection,_variant_t Start) { CString szCri=Criteria; if (!szCri.IsEmpty()) m_Criteria=Criteria; else return FALSE; try{ m_rs->Find(_bstr_t(Criteria),SkipRecords,SearchDirection,Start); if (SearchDirection ==adSearchForward) { if (!IsEof()) { vtPointer= m_rs->Bookmark; return TRUE; } }else if (SearchDirection ==adSearchBackward) { if (!IsBof()) { vtPointer= m_rs->Bookmark; return TRUE; } }else return FALSE; }catch(_com_error &e) { GetError(e); return FALSE; } return FALSE; }
void tick(bool includeOldAudio = false){ bool success = false; StreamFrameMap streamFrames; streamFrames[videoStream] = Frame::CreateEmpty(); streamFrames[audioStream] = Frame::CreateEmpty(); while(!IsEof() && !success) { try { int audioQueueTargetSize = audioDevice->GetBlockSize() * 4; while( frameQueue.size() < (unsigned int)targetFrameQueueSize || (hasAudioStream() && audioHandler->getAudioQueueSize() < audioQueueTargetSize)) { if(frameQueue.size() >= (unsigned int)maxFrameQueueSize) break; bool frameDecoded = decodeFrame(streamFrames); if(!frameDecoded) throw VideoException(VideoException::EDecodingVideo); if(streamFrames[videoStream]->finished != 0){ frameQueue.push(streamFrames[videoStream]->Clone()); streamFrames[videoStream] = Frame::CreateEmpty(); } if(streamFrames[audioStream]->finished != 0){ // only enqueue audio that's newer than the current video time, // eg. on seeking we might encounter audio that's older than the frames in the frame queue. if(streamFrames[audioStream]->GetSamples().size() > 0 && (includeOldAudio || streamFrames[audioStream]->GetSamples()[0].ts >= timeHandler->GetTime())) { audioHandler->EnqueueAudio(streamFrames[audioStream]->GetSamples()); }else{ FlogD("skipping old audio samples: " << streamFrames[audioStream]->GetSamples().size()); } streamFrames[audioStream] = Frame::CreateEmpty(); } } // sync framequeue target size with number of frames needed for audio queue if(targetFrameQueueSize < (int)frameQueue.size()){ targetFrameQueueSize = std::max((int)frameQueue.size(), minFrameQueueSize); } success = true; } catch(VideoException e) { Retry(Str("Exception in tick: " << e.what())); } } }
/******************************************************************* * * CharGet * *******************************************************************/ char CSVload::CharGet() { if( !IsFile() ){ return EOF; } char result = m_lastChar; if(!IsEof()){ m_lastChar = fgetc(m_filePointer); } return result; }
void XmlParser::Skip() { if(IsEof()) throw XmlError("Unexpected end of file"); if(cdata.GetCount() && type != XML_TEXT) cdata.Clear(); else if(IsTag()) { String n = ReadTag(); while(!End()) { if(IsEof()) throw XmlError("Unexpected end of file expected when skipping tag \'" + n + "\'"); Skip(); } } else Next(); }
String GenericXMLParser::ParseToSemicolon() { StartTrace(GenericXMLParser.ParseToSemicolon); String value; int c; while (!IsEof() && ';' != (c = Get())) { value.Append(char(c)); } return value; }
void GenericXMLParser::SkipWhitespace() { StartTrace(GenericXMLParser.SkipWhitespace); int c; while (!IsEof() && (c = Peek()) != 0 && c != EOF) { if (!isspace(c)) { return; } c = Get(); } }
/******************************************************************* * * CSVRead * *******************************************************************/ string CSVload::Read() { if( !IsFile() ){ return ""; } string result = ""; bool SkipStanbyFlag = false; while(!IsEof()){ //エスケープシーケンススキップ if(IsEscapeSequence()) { CharGet();//一文字飛ばす continue; } //デミリター文字か改行なら if(IsDemiliter()){ CharGet();//一文字飛ばす break; } char c = CharGet();//1文字取得する if(c == '/'){//スラッシュがあれば if(SkipStanbyFlag){//前の文字もスラッシュだったら LineSkip();//改行までループ result = "";//中身をリセット SkipStanbyFlag = false; continue; } SkipStanbyFlag = true;//スキップスタンバイ }else{ SkipStanbyFlag = false; } result += c;//文字を追加する } if( result == "" && !IsEof() ){ //もしも、文字列の中身がないならもう一度試行する result = Read(); } return result; }
//---------------------------------------------------------------------------------- // Read a part of the file in multi line fasta format bool CFastqReader::GetPartFromMultilneFasta(uchar *&_part, uint64 &_size) { uint64 readed = 0; if(!containsNextChromosome) { if(IsEof()) return false; } if(mode == m_plain) readed = fread(part+part_filled, 1, part_size-part_filled, in); else if(mode == m_gzip) readed = gzread(in_gzip, part+part_filled, (int) (part_size-part_filled)); else if(mode == m_bzip2) readed = BZ2_bzRead(&bzerror, in_bzip2, part+part_filled, (int) (part_size-part_filled)); int64 total_filled = part_filled + readed; int64 last_header_pos = 0; int64 pos = 0; for(int64 i = 0 ; i < total_filled ;++i )//find last '>' and remove EOLs { if(part[i] == '>') { int64 tmp = i; SkipNextEOL(part,i,total_filled); copy(part+tmp, part+i, part+pos); last_header_pos = pos; pos += i - tmp; } if(part[i] != '\n' && part[i] != '\r') { part[pos++] = part[i]; } } _part = part; if(last_header_pos == 0)//data in block belong to one seq { part_filled = kmer_len - 1; _size = pos; pmm_fastq->reserve(part); copy(_part+_size-part_filled, _part+_size, part); containsNextChromosome = false; } else//next seq starts at last_header_pos { _size = last_header_pos; part_filled = pos - last_header_pos; pmm_fastq->reserve(part); copy(_part + last_header_pos, _part + pos, part); containsNextChromosome = true; } return true; }
String GenericXMLParser::ParseQuotedString() { StartTrace(GenericXMLParser.ParseValue); String value; SkipWhitespace(); int quote = Get(); int c; while (!IsEof() && (c = Get()) != quote) { value.Append((char)c); } return value; }
BOOL CADORecordset::GetFieldInfo(FieldPtr pField, CADOFieldInfo* fldInfo) { memset(fldInfo, 0, sizeof(CADOFieldInfo)); strcpy(fldInfo->m_strName, (LPCTSTR)pField->GetName()); fldInfo->m_lDefinedSize = pField->GetDefinedSize(); fldInfo->m_nType = pField->GetType(); fldInfo->m_lAttributes = pField->GetAttributes(); if(!IsEof()) fldInfo->m_lSize = pField->GetActualSize(); return TRUE; }
String GenericXMLParser::ParseName() { StartTrace(GenericXMLParser.ParseName); String theName; int c; // Unicode? while (!IsEof() && (c = Peek()) != EOF && c != 0) { if (IsValidNameChar(c) || (isdigit(c) && theName.Length() > 0)) { theName.Append((char)Get()); } else { break; } } return theName; }
String Deserializer::ReadString() { String ret; while (!IsEof()) { char c = ReadByte(); if (!c) break; else ret += c; } return ret; }
LONG BFile::ReadLine(OUT char* const cpBuffer, IN LONG lBufferSize) { LONG lResult = -1; char *pStr = NULL; BZ_PROCESS_ERROR(m_hFile && ferror(m_hFile) == 0); // gets读取换行符并将其丢弃,fgets把换行符存字符串里。 [3/6/2013 T.Q.Y.] pStr = fgets(cpBuffer, lBufferSize, m_hFile); BZ_PROCESS_ERROR(ferror(m_hFile) == 0); if (IsEof()) lResult = 0; else lResult = strnlen(pStr, lBufferSize); Exit0: return lResult; }
// ----------------------------------------------------------------------------- // TMccResourceItemIterator::Next // ----------------------------------------------------------------------------- // TBool TMccResourceItemIterator::Next( CMccResourceItem*& aCandidate, TMccIteratorMatchType aMatchType ) { CMccResourceItem* next = NULL; TBool negation = aMatchType == ExactMatch ? EFalse : ETrue; while( !next && !IsEof() ) { CMccResourceItem* item = iItems[ iCurrentIndex ]; TBool condition = EFalse; if ( iUid != KNullUid ) { condition = ( item->IsSink() && item->Sink()->DataSinkType() == iUid ) || ( item->IsSource() && item->Source()->DataSourceType() == iUid ); if ( condition && iResourceParams ) { condition = item->MatchSession( iResourceParams->iSessionId ); } } else if ( iResourceParams ) { condition = item->Match( *iResourceParams ); } else if ( iEndpointId ) { condition = iEndpointId == item->EndpointId(); } else { condition = ( !iOnlySinks || item->IsSink() ) && ( !iOnlySources || item->IsSource() ) && ( !iOnlyInternals || item->IsInternal() ); } next = ( ( negation && !condition ) || ( !negation && condition ) ) ? item : NULL; iCurrentIndex++; } aCandidate = next; return aCandidate != NULL; }
// ----------------------------------------------------------------------------- // TMccResourceContainerIterator::Next // ----------------------------------------------------------------------------- // TBool TMccResourceContainerIterator::Next( CMccResourceContainer*& aCandidate, TMccIteratorMatchType aMatchType ) { CMccResourceContainer* next = NULL; TBool negation = aMatchType == ExactMatch ? EFalse : ETrue; while( !next && !IsEof() ) { CMccResourceContainer* container = iContainers[ iCurrentIndex ]; TBool condition = EFalse; if ( iResourceParams ) { if ( iResourceParams->iLinkId ) { condition = ( container->LinkId() == iResourceParams->iLinkId ); } else if ( iResourceParams->iStreamId ) { condition = ( container->StreamId() == iResourceParams->iStreamId ); } else if ( iEndpointId ) { condition = ( container->FindResourceItem( iEndpointId ) != NULL ); } else { } } else { condition = ETrue; } next = ( ( negation && !condition ) || ( !negation && condition ) ) ? container : NULL; iCurrentIndex++; } aCandidate = next; return aCandidate != NULL; }
bool XmlParser::End() { if(IsEof()) throw XmlError("Unexpected end of file"); if(IsEnd()) { LLOG("EndTag " << text); if(stack.IsEmpty()) throw XmlError(NFormat("Unexpected end-tag: </%s>", tagtext)); if(stack.Top().tag != tagtext && !relaxed) { LLOG("Tag/end-tag mismatch: <" << stack.Top().tag << "> </" << tagtext << ">"); throw XmlError(NFormat("Tag/end-tag mismatch: <%s> </%s>", stack.Top().tag, tagtext)); } stack.Drop(); npreserve = (!stack.IsEmpty() && stack.Top().preserve_blanks); Next(); return true; } return false; }
bool GenericXMLParser::ParseTag(String &tag, Anything &tagAttributes) { StartTrace(GenericXMLParser.ParseTag); tag = ParseName(); Trace("tag = " << tag); while (!IsEof()) { SkipWhitespace(); int c = Peek(); switch (c) { case '>': // done with tag c = Get(); return true;//lint !e438 case '/': // an empty tag? i.e. <br /> c = Get(); if ('>' == Peek()) { c = Get(); return false;//lint !e438 } // an error occured, ignore '/' silently PutBack(c); default: {//lint !e616 String name; String value; if (ParseAttribute(name, value)) { tagAttributes[name] = value; } else { // non-well formed XML...no value given if (name.Length() > 0) { tagAttributes.Append(name); } else { String msg("Unexpected character <"); c = Get(); msg.AppendAsHex((unsigned char)c).Append("> near ").Append(tag); Error(msg); tagAttributes.Append(String(char(c))); } } } } } Error("unexpected EOF in Tag"); return false; // no body to expect }
uint32 File::ReadString(String & destinationString) { uint32 writeIndex = 0; while(!IsEof()) { uint8 currentChar; Read(¤tChar, 1); if(0 != currentChar) { destinationString += currentChar; writeIndex++; } else { break; } } return writeIndex - 1; }
uint32 File::ReadString(char8 * destinationBuffer, uint32 destinationBufferSize) { uint32 writeIndex = 0; while(!IsEof()) { uint8 currentChar; Read(¤tChar, 1); if (writeIndex < destinationBufferSize) { destinationBuffer[writeIndex] = currentChar; }else { Logger::Warning("File::ReadString buffer size is too small for this string."); } writeIndex++; if(currentChar == 0)break; } return writeIndex - 1; }
FramePtr fetchFrame() { bool wasStepIntoQueue = stepIntoQueue; if(frameQueue.empty() && IsEof() && !reportedEof) { reportedEof = true; messageCallback(MEof, "eof"); } if(stepIntoQueue && !frameQueue.empty()) { stepIntoQueue = false; timeHandler->SetTime(timeFromTs(frameQueue.top()->GetPts()) + .001); audioHandler->discardQueueUntilTs(timeHandler->GetTime()); } double time = timeHandler->GetTime(); FramePtr newFrame = 0; // Throw away all old frames (timestamp older than now) except for the last // and set the pFrame pointer to that. int poppedFrames = 0; while(!frameQueue.empty() && timeFromTs(frameQueue.top()->GetPts()) < time) { newFrame = frameQueue.top(); frameQueue.pop(); poppedFrames++; } if(poppedFrames > 1){ FlogD("skipped " << poppedFrames - 1 << " frames"); } if(newFrame != 0 && (newFrame->GetPts() >= time || wasStepIntoQueue)) return newFrame; return 0; }
bool IFile::ReadString(String & result) { char8 sym = 0; char8 tmp[2048]; int32 counter = 0; while(1) { Read(&sym, 1); if (sym == 0) { tmp[counter] = sym; result = tmp; return true; }; if (IsEof())return false; tmp[counter++] = sym; } tmp[counter] = sym; result = tmp; return true; }
Anything GenericXMLParser::ParseDtdElements() { StartTrace(GenericXMLParser.ParseDtdElements); Anything result; int c = Get();// read the [ while (!IsEof() && ']' != c) { SkipWhitespace(); c = Get(); switch (c) { case '%' : { // a PE Reference String peref("%"); peref.Append(ParseToSemicolon()); peref.Append(';'); result.Append(peref); break; } case '<': // a processing instruction, comment or dtd decl switch (Peek()) { case '?': result.Append(ParseXmlOrProcessingInstruction()); break; case '!': // a comment only allowed result.Append(ParseCommentCdataOrDtd(true)); break; default: Error("invalid < character seqence within DTD"); result.Append(SkipToClosingAngleBracket()); break; } break; case ']': break; // done default: Error("invalid character within DTD ignored"); break; } } return result; }
BOOL CADORecordset::FindNext() { if(m_nSearchDirection == searchForward) { m_pRecordset->Find(_bstr_t(m_strFind), 1, adSearchForward, m_varBookFind); if(!IsEof()) { m_varBookFind = m_pRecordset->Bookmark; return TRUE; } } else { m_pRecordset->Find(_bstr_t(m_strFind), 1, adSearchBackward, m_varBookFind); if(!IsBof()) { m_varBookFind = m_pRecordset->Bookmark; return TRUE; } } return FALSE; }