///////////////////////////////////////////////////// Created by Jisang Yoo. ///////////////////////////////////////////////////// class TSubtitle { private: String text[MaxLine]; int start[MaxLine]; int end[MaxLine]; int FLineCount; String __fastcall GetText(int Index); int __fastcall GetStart(int Index); int __fastcall GetEnd(int Index); protected: public: void LoadFromSamiFile(String filename, String BR = "\n"); void LoadFromSubripFile(String filename); void LoadFromSubviewer2File(String filename); void LoadFromMicrodvdFile(String filename, float FPS=25); void SaveToSamiFile(String filename) const; TSubtitle(); void Compress(); bool IsCorrect(int* pIndex); static int MicrodvdOrSubviewer2(String filename); __property int LineCount = { read=FLineCount }; //total # of texts in subtitle. __property String Text[int Index] = { read=GetText }; // text of subtitle __property int Start[int Index] = { read=GetStart }; // start time for each texts of subtitle __property int End[int Index] = { read=GetEnd }; // end time for each texts of subtitle }; TSubtitle::TSubtitle() :FLineCount(0) { } String __fastcall TSubtitle::GetText(int Index) { if (0<=Index && Index 00:13:17,621 X1:000 X2:719 Y1:002 Y2:479 l'm your source of self-destruction 2 00:13:47,177 --> 00:13:49,508 X1:000 X2:719 Y1:002 Y2:479 End of passion play */ int i ,sp,hour,minute,second,milisec, prev_len; char buf[201]; FILE* fp = fopen(filename.c_str(),"r"); if(fp==NULL) return; i = 0; start[0] = 0; text[0] = ""; String CurLine("") ,PastLine("") ,Temp; while (fgets(buf,200,fp) && i") , sp && CurLine.Length() > 6 && CurLine[3] == ':' && CurLine[6] == ':' ) { //parsing '??:??:??,??? --> ??:??:??,??? ***' and processing the previous text[i]. text[i] = text[i].SubString( 1 , text[i].Length() - prev_len - 2 ); //deleting the last part(for ex, '\n23\n' , '\n5\n') of text[i]. i++; hour = CurLine.SubString(1,2).ToInt(); minute = CurLine.SubString(4,2).ToInt(); second = CurLine.SubString(7,2).ToInt(); start[i] = ((60*hour + minute)*60 + second)*1000 + CurLine.SubString(10,3).ToInt(); CurLine.Delete(1,sp+2); CurLine = CurLine.Trim(); hour = CurLine.SubString(1,2).ToInt(); minute = CurLine.SubString(4,2).ToInt(); second = CurLine.SubString(7,2).ToInt(); end[i] = ((60*hour + minute)*60 + second)*1000 + CurLine.SubString(10,3).ToInt(); text[i] = ""; } else { //parsing text[i]. text[i] += CurLine + "\n"; } } FLineCount = i + 1; fclose(fp); } void TSubtitle::LoadFromSamiFile(String filename, String BR /*= "\n"*/) { /* SAMI (*.smi , *.smil) ex) "A Few Good Man"

Captain, I'd like to request that
it be me who's the attorney ...

  */ int i ; char buf[201]; String CurLine, Upper,Temp; int sp,sp2; FILE* fp = fopen(filename.c_str(),"r"); if(fp==NULL) return; //skip until '' appears while (fgets(buf,200,fp)) if (String(buf).UpperCase().AnsiPos("") ) break; i = 0; start[0] = 0; TReplaceFlags rf; rf<' and reading the 'start[i]'. if(CurLine.UpperCase().Pos(""); start[i] = CurLine.SubString(sp+1,sp2-sp-1).ToInt(); text[i] = ""; CurLine.Delete(1,sp2); } CurLine = StringReplace(CurLine," "," ",rf); CurLine = StringReplace(CurLine," "," ",rf); CurLine = StringReplace(CurLine,"
",BR,rf); int x = 0; // for error check. while(sp = CurLine.Pos("<") ,sp) // deleting '< ????? >' { if (x++>3) break; //¿¹¿Üó¸® ¹«ÇÑ·çǪ ¹æÁö sp2=CurLine.Pos(">"); Temp = CurLine.SubString(1,sp-1); CurLine= Temp + CurLine.Delete(1,sp2); } text[i] += CurLine; } FLineCount = i+1; //calculating 'end[i]'s from 'start[i]'s for (i=0 ;i<(FLineCount-1) ;i++) end[i] = start[i+1]; end[FLineCount-1] += start[FLineCount-1] + 10000; fclose(fp); } void TSubtitle::SaveToSamiFile(String filename) const { FILE* fp = fopen(filename.c_str(),"w"); if(fp == NULL) return; //TODO: this and end. String hd = "\n\n\nAlbert Einstein\n\n\n\n\n"; fputs(hd.c_str(),fp); String Temp, Temp2; int x,sp; for(int i=0 ; i

"; fputs( Temp.c_str() , fp); Temp = text[i].Trim(); x = 0; // for error check. while(sp = Temp.Pos("\n") , sp) // { if (x++>5) break; //¿¹¿Üó¸® ¹«ÇÑ·çǪ ¹æÁö Temp2 = Temp.SubString(1,sp-1); Temp = Temp2 + "
" + Temp.Delete(1,sp); } Temp += "\n"; fputs( Temp.c_str() , fp); } fputs("\n\n",fp); fclose(fp); }