istream operator>>(istream& is, MyCustomStringImp& s)
C++ (Qt)qint64 lineCount(const char* FileName) { char fsm [256][8]; int fh = open(FileName, O_RDONLY|O_BINARY); if(fh < 0) { return -1; } else { char fsm0 [8] = {6,0,0,0,0,0,6,0}; char fsm1 [8] = {3,1,5,1,5,1,3,1}; char fsm2 [8] = {4,2,2,2,2,2,4,2}; for(int i=0; i<256; i++) {memcpy(&(fsm[i][0]), &(fsm0[0]), sizeof(fsm0));} memcpy(&(fsm[(unsigned char)'\n'][0]), &(fsm1[0]), sizeof(fsm1)); memcpy(&(fsm[(unsigned char)'\r'][0]), &(fsm2[0]), sizeof(fsm2)); } unsigned char buff[1024*256]; int state = 7; qint64 lcount = 0; unsigned int len; unsigned char* str; unsigned char* strE; for(;;) { len = read(fh, buff, sizeof(buff)); if(!len) {break;} if(len < 0) { close(fh); return -1; } str = buff; strE = str+len; for(; str<strE; ++str) { switch((state = fsm[*str][state])) { case 0: case 1: case 2: lcount++; } } } if(lcount) { switch(state) { case 1: case 2: case 3: case 4: case 5: lcount++; } } close(fh); return lcount;}
C++ (Qt)qint64 lineCount1(const char* FileName) { char fsm0 [8] = {6,0,0,0,0,0,6,0}; char fsm1 [8] = {3,1,5,1,5,1,3,1}; char fsm2 [8] = {4,2,2,2,2,2,4,2}; char fsm [256][8]; for(int i=0; i<256; i++) {memcpy(&(fsm[i][0]), &(fsm0[0]), sizeof(fsm0));} memcpy(&(fsm[(unsigned char)'\n'][0]), &(fsm1[0]), sizeof(fsm1)); memcpy(&(fsm[(unsigned char)'\r'][0]), &(fsm2[0]), sizeof(fsm2)); QFile File(FileName); if (!File.open(QFile::ReadOnly)) {return -1;} char buff[1024*128]; qint64 lcount = 0; int len; int state = 7; char* str; char* strE; for(;;) { len = File.read(buff, sizeof(buff)); if (File.error()) return -1; if(!len) {break;} str = buff; strE = str+len; for(; str<strE; ++str) { switch((state = fsm[(unsigned char)*str][state])) { case 0: case 1: case 2: lcount++; } } } if(lcount) { switch(state) { case 1: case 2: case 3: case 4: case 5: lcount++; } } return lcount;}
C++ (Qt)qint64 lineCount2(const char* FileName) { QFile File(FileName); if (!File.open(QFile::ReadOnly)) return -1; char buff[1024*128]; qint64 lcount = 0; int len; char prev = 0; char cur = 0; for(;;) { len = File.read(buff, sizeof(buff)); if (File.error()) return -1; if(!len) {break;} for (int i=0; i<len; ++i) { cur = buff[i]; if (cur == 10) {++lcount;} else if (prev == 13) {++lcount;} prev = cur; } } if (cur == 13) {++lcount;} return lcount + 1;}
void createLongFile( const QString& strFileName ){ QFile srcFile( strFileName ); if( srcFile.open( QIODevice::ReadWrite ) ) { QByteArray baContent = srcFile.readAll(); for( long i = 65536*64; i >= 0; --i ) { srcFile.write( baContent ); } }}