本文整理汇总了C++中Ztring::FindAndReplace方法的典型用法代码示例。如果您正苦于以下问题:C++ Ztring::FindAndReplace方法的具体用法?C++ Ztring::FindAndReplace怎么用?C++ Ztring::FindAndReplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ztring
的用法示例。
在下文中一共展示了Ztring::FindAndReplace方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Modified_Local_Get
//---------------------------------------------------------------------------
Ztring File::Modified_Local_Get()
{
#ifdef ZENLIB_USEWX
if (File_Handle==NULL)
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
//if (File_Handle==-1)
if (File_Handle==NULL)
#elif defined WINDOWS
if (File_Handle==NULL)
#endif
#endif //ZENLIB_USEWX
return Ztring();
#ifdef ZENLIB_USEWX
return Ztring(); //Not implemented
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
struct stat Stat;
int Result=stat(File_Name.To_Local().c_str(), &Stat);
if (Result<0)
return Ztring(); //Error
Ztring Time; Time.Date_From_Seconds_1970_Local(Stat.st_mtime);
return Time;
#elif defined WINDOWS
FILETIME TimeFT;
if (GetFileTime(File_Handle, NULL, NULL, &TimeFT))
{
int64u Time64=0x100000000ULL*TimeFT.dwHighDateTime+TimeFT.dwLowDateTime; //100-ns
TIME_ZONE_INFORMATION Info;
DWORD Result=GetTimeZoneInformation(&Info);
if (Result!=TIME_ZONE_ID_INVALID)
{
Time64-=((int64s)Info.Bias)*60*1000*1000*10;
if (Result==TIME_ZONE_ID_DAYLIGHT)
Time64-=((int64s)Info.DaylightBias)*60*1000*1000*10;
else
Time64-=((int64s)Info.StandardBias)*60*1000*1000*10;
}
Ztring Time; Time.Date_From_Milliseconds_1601(Time64/10000);
Time.FindAndReplace(_T("UTC "), _T(""));
return Time;
}
else
return Ztring(); //There was a problem
#endif
#endif //ZENLIB_USEWX
}
示例2: Enums_Create_Item
//---------------------------------------------------------------------------
// Open an item
ZenLib::Ztring Enums_Create_Item(const Ztring &Directory, const Ztring &Name, Ztring &Contents)
{
Contents.clear();
Ztring Result;
//Load header
Ztring Partial;
Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.2.txt", Partial);
if (!Result.empty())
return Result;
Partial.FindAndReplace(L"%Name%", Ztring(Name).MakeLowerCase());
Contents+=Partial;
//Load line template
Ztring Line;
Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.5.txt", Line);
if (!Result.empty())
return Result;
//Read input file
ZtringListListF ZLL;
ZLL.Load(Ztring(L"../Source/Resource/Text/")+Directory+L"/"+Name+L".csv");
for (size_t Pos=0; Pos<ZLL.size(); Pos++)
{
Ztring Line_Temp=Line;
Line_Temp.FindAndReplace(L"%Name%", Name);
Ztring &ToAdd=ZLL(Pos, 0);
ToAdd.FindAndReplace(__T("/"), __T("_"), 0, Ztring_Recursive); //C++ does not accept "/" in names
ToAdd.FindAndReplace(__T("("), __T("_")); //C++ does not accept "(" in names
ToAdd.FindAndReplace(__T(")"), __T("_")); //C++ does not accept ")" in names
ToAdd.FindAndReplace(__T("*"), __T("_")); //C++ does not accept "*" in names
ToAdd.FindAndReplace(__T("-"), __T("_")); //C++ does not accept "-" in names
Line_Temp.FindAndReplace(L"%Line%", ToAdd);
Contents+=Line_Temp;
}
//Load footer template
Result=Enums_Create_Load(L"../Source/Resource/Text/Enums_.8.txt", Partial);
if (!Result.empty())
return Result;
Contents+=Partial;
return L"";
}
示例3: Created_Local_Get
//---------------------------------------------------------------------------
Ztring File::Created_Local_Get()
{
#ifdef ZENLIB_USEWX
if (File_Handle==NULL)
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
//if (File_Handle==-1)
if (File_Handle==NULL)
#elif defined WINDOWS
if (File_Handle==NULL)
#endif
#endif //ZENLIB_USEWX
return _T("");
#ifdef ZENLIB_USEWX
return _T(""); //Not implemented
#else //ZENLIB_USEWX
#ifdef ZENLIB_STANDARD
return _T(""); //Not implemented
#elif defined WINDOWS
FILETIME TimeFT;
if (GetFileTime(File_Handle, &TimeFT, NULL, NULL))
{
int64u Time64=0x100000000ULL*TimeFT.dwHighDateTime+TimeFT.dwLowDateTime;
TIME_ZONE_INFORMATION Info;
DWORD Result=GetTimeZoneInformation(&Info);
if (Result!=TIME_ZONE_ID_INVALID)
{
Time64-=((int64s)Info.Bias)*60*1000*1000*10;
if (Result==TIME_ZONE_ID_DAYLIGHT)
Time64-=((int64s)Info.DaylightBias)*60*1000*1000*10;
else
Time64-=((int64s)Info.StandardBias)*60*1000*1000*10;
}
Ztring Time; Time.Date_From_Milliseconds_1601(Time64/10000);
Time.FindAndReplace(_T("UTC "), _T(""));
return Time;
}
else
return _T(""); //There was a problem
#endif
#endif //ZENLIB_USEWX
}
示例4: Test_Version
int Test_Version(char* FileName_, char* Begin, char* End)
{
wxString FileName=Ztring().From_Local(FileName_).c_str();
//Opening File
F.Open(FileName);
I=F.Read(C, 1000000);
if (!I)
{
ToShow+=__T("Error opening ")+FileName;
return -1;
}
//Getting information
C[I]=0;
Z.From_Local(C);
Z=Z.SubString(Ztring().From_Local(Begin), Ztring().From_Local(End));
//deleting extra bytes
if (Z[Z.size()-1]=='\n')
Z.resize(Z.size()-1);
if (Z[Z.size()-1]=='\r')
Z.resize(Z.size()-1);
//Testing validity
if (Z.size()!=3 && Z.size()!=7) //non long, no short
{
ToShow+=__T("Error reading ")+FileName;
return -2;
}
//Reformtation information
Z.FindAndReplace(__T(","), __T("."), 0, Ztring_Recursive);
if (Z!=Version && Z!=Version_Short)
{
ToShow+=FileName;
ToShow+=__T(" is not good : version is marked ");
ToShow+=Z;
ToShow+=__T("\r\n");
}
return 0;
}
示例5: Read_Buffer_Continue
void File_OtherText::Read_Buffer_Continue()
{
if (Buffer_Size<0x200)
{
Element_WaitForMoreData();
return;
}
Element_Offset=File_Size-(File_Offset+Buffer_Offset);
Ztring Format, FormatMore, Codec;
Ztring File;
ZtringList Lines;
//Feed File and Lines
File.From_UTF8((const char*)Buffer, Buffer_Size>65536?65536:Buffer_Size);
if (File.empty())
File.From_Local((const char*)Buffer, Buffer_Size>65536?65536:Buffer_Size); // Trying from local code page
if (File.size()<0x100)
{
File.From_Unicode((wchar_t*)Buffer, 0, Buffer_Size/sizeof(wchar_t)); //Unicode with BOM
//TODO: Order of bytes (big or Little endian)
if (File.size()<0x100)
{
Reject("Other text");
return;
}
}
if (File.size()>0x1000)
File.resize(0x1000); //Do not work on too big
File.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
File.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
Lines.Separator_Set(0, __T("\n"));
Lines.Write(File);
Lines.resize(0x20);
if (Lines[0]==__T("[Script Info]")
&& (Lines.Find(__T("ScriptType: v4.00"))!=Error || Lines.Find(__T("Script Type: V4.00"))!=Error)
&& Lines.Find(__T("[V4 Styles]"))!=Error
)
{
Format=__T("SSA");
FormatMore=__T("SubStation Alpha");
Codec=__T("SSA");
}
else if (Lines[0]==__T("[Script Info]")
&& (Lines.Find(__T("ScriptType: v4.00+"))!=Error || Lines.Find(__T("Script Type: V4.00+"))!=Error)
&& Lines.Find(__T("[V4+ Styles]"))!=Error
)
{
Format=__T("ASS");
FormatMore=__T("Advanced SubStation Alpha");
Codec=__T("ASS");
}
else if (Lines[0].size()>24
&& Lines[0][ 0]==__T('0') && Lines[0][ 1]==__T('0')
&& Lines[0][ 2]==__T(':') && Lines[0][ 5]==__T(':') && Lines[0][ 8]==__T(':')
&& Lines[0][11]==__T(' ')
&& Lines[0][12]==__T('0') && Lines[0][13]==__T('0')
&& Lines[0][14]==__T(':') && Lines[0][17]==__T(':') && Lines[0][20]==__T(':')
&& Lines[0][23]==__T(' ')
)
{
Format=__T("Adobe encore DVD");
Codec=__T("Adobe");
}
else if (Lines[0].size()==11
&& Lines[0][0]==__T('-') && Lines[0][1]==__T('-') && Lines[0][2]==__T('>') && Lines[0][3]==__T('>') && Lines[0][4]==__T(' ')
&& Lines[0][5]==__T('0')
&& Lines[1].empty()!=true
)
{
Format=__T("AQTitle");
Codec=__T("AQTitle");
}
else if (Lines[0].size()>28
&& Lines[0][ 0]==__T('0') && Lines[0][ 1]==__T('0')
&& Lines[0][ 2]==__T(':') && Lines[0][ 5]==__T(':') && Lines[0][ 8]==__T(':')
&& Lines[0][11]==__T(' ') && Lines[0][12]==__T(',') && Lines[0][13]==__T(' ')
&& Lines[0][14]==__T('0') && Lines[0][15]==__T('0')
&& Lines[0][16]==__T(':') && Lines[0][19]==__T(':') && Lines[0][22]==__T(':')
&& Lines[0][25]==__T(' ') && Lines[0][16]==__T(',') && Lines[0][27]==__T(' ')
)
{
Format=__T("Captions 32");
Codec=__T("Caption 32");
}
else if (Lines[0].size()==23
&& Lines[0]==__T("*Timecode type: PAL/EBU")
&& Lines[1].empty()
&& Lines[2].size()==23
&& Lines[2][ 0]==__T('0') && Lines[2][ 1]==__T('0')
&& Lines[2][ 2]==__T(':') && Lines[2][ 5]==__T(':') && Lines[2][ 8]==__T(':')
&& Lines[2][11]==__T(' ')
&& Lines[2][12]==__T('0') && Lines[2][13]==__T('0')
&& Lines[2][14]==__T(':') && Lines[2][17]==__T(':') && Lines[2][20]==__T(':')
&& Lines[2].size()>0
)
{
Format=__T("Captions Inc");
//.........这里部分代码省略.........
示例6: Transform
//---------------------------------------------------------------------------
Ztring Export_PBCore::Transform(MediaInfo_Internal &MI)
{
//Current date/time is ISO format
time_t Time=time(NULL);
Ztring TimeS; TimeS.Date_From_Seconds_1970((int32u)Time);
TimeS.FindAndReplace(__T("UTC "), __T(""));
TimeS.FindAndReplace(__T(" "), __T("T"));
TimeS+=__T('Z');
Ztring ToReturn;
ToReturn+=__T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
ToReturn+=__T("<PBCoreDescriptionDocument xsi:schemaLocation=\"http://www.pbcore.org/PBCore/PBCoreNamespace.html http://www.pbcore.org/PBCore/PBCoreXSD_Ver_1-2-1.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.pbcore.org/PBCore/PBCoreNamespace.html\">\n");
ToReturn+=__T("\t<!-- Generated at ")+TimeS+__T(" by ")+MediaInfoLib::Config.Info_Version_Get()+__T(" -->\n");
ToReturn+=__T("\t<!-- Warning: MediaInfo outputs only pbcoreInstantiation, other mandatory PBCore data is junk -->\n");
ToReturn+=__T("\t<pbcoreIdentifier>\n");
ToReturn+=__T("\t\t<identifier>***</identifier>\n");
ToReturn+=__T("\t\t<identifierSource>***</identifierSource>\n");
ToReturn+=__T("\t</pbcoreIdentifier>\n");
ToReturn+=__T("\t<pbcoreTitle>\n");
ToReturn+=__T("\t\t<title>***</title>\n");
ToReturn+=__T("\t</pbcoreTitle>\n");
ToReturn+=__T("\t<pbcoreDescription>\n");
ToReturn+=__T("\t\t<description>***</description>\n");
ToReturn+=__T("\t\t<descriptionType>***</descriptionType>\n");
ToReturn+=__T("\t</pbcoreDescription>\n");
ToReturn+=__T("\t<pbcoreInstantiation>\n");
//pbcoreFormatID
ToReturn+=__T("\t\t<pbcoreFormatID>\n");
//formatIdentifier
ToReturn+=__T("\t\t\t<formatIdentifier>")+MI.Get(Stream_General, 0, General_FileName)+__T("</formatIdentifier>\n");
//formatIdentifierSource
ToReturn+=__T("\t\t\t<formatIdentifierSource version=\"PBCoreXSD_Ver_1.2_D1\">File Name</formatIdentifierSource>\n");
ToReturn+=__T("\t\t</pbcoreFormatID>\n");
//formatDigital
if (!MI.Get(Stream_General, 0, General_InternetMediaType).empty())
{
ToReturn+=__T("\t\t<formatDigital>");
ToReturn+=MI.Get(Stream_General, 0, General_InternetMediaType);
ToReturn+=__T("</formatDigital>\n");
}
else
{
//TODO: how to implement formats without Media Type?
ToReturn+=__T("\t\t<formatDigital>");
if (MI.Count_Get(Stream_Video))
ToReturn+=__T("video/x-");
else if (MI.Count_Get(Stream_Image))
ToReturn+=__T("image/x-");
else if (MI.Count_Get(Stream_Audio))
ToReturn+=__T("audio/x-");
else
ToReturn+=__T("application/x-");
ToReturn+=Ztring(MI.Get(Stream_General, 0, __T("Format"))).MakeLowerCase();
ToReturn+=__T("</formatDigital>\n");
}
//formatLocation
ToReturn+=__T("\t\t<formatLocation>")+MI.Get(Stream_General, 0, General_CompleteName)+__T("</formatLocation>\n");
//dateCreated
if (!MI.Get(Stream_General, 0, General_Encoded_Date).empty())
{
Ztring dateCreated=MI.Get(Stream_General, 0, General_Recorded_Date);
dateCreated.FindAndReplace(__T("UTC"), __T("-"));
dateCreated.FindAndReplace(__T(" "), __T("T"));
dateCreated+=__T('Z');
ToReturn+=__T("\t\t<dateCreated>")+dateCreated+__T("</dateCreated>\n");
}
//dateIssued
if (!MI.Get(Stream_General, 0, General_Recorded_Date).empty())
{
Ztring dateIssued=MI.Get(Stream_General, 0, General_Recorded_Date);
dateIssued.FindAndReplace(__T("UTC"), __T("-"));
dateIssued.FindAndReplace(__T(" "), __T("T"));
dateIssued+=__T('Z');
ToReturn+=__T("\t\t<dateIssued>")+dateIssued+__T("</dateIssued>\n");
}
//formatMediaType
if (!PBCore_MediaType(MI).empty())
ToReturn+=__T("\t\t<formatMediaType version=\"PBCoreXSD_Ver_1.2_D1\">")+PBCore_MediaType(MI)+__T("</formatMediaType>\n");
else
ToReturn+=__T("\t\t<formatMediaType version=\"PBCoreXSD_Ver_1.2_D1\">application/octet-stream</formatMediaType>\n");
//formatGenerations
ToReturn+=__T("\t\t<formatGenerations version=\"PBCoreXSD_Ver_1.2_D1\" />\n");
//formatFileSize
if (!MI.Get(Stream_General, 0, General_FileSize).empty())
ToReturn+=__T("\t\t<formatFileSize>")+MI.Get(Stream_General, 0, General_FileSize)+__T("</formatFileSize>\n");
//formatTimeStart
if (!MI.Get(Stream_Video, 0, Video_Delay_Original_String3).empty())
ToReturn+=__T("\t\t<formatTimeStart>")+MI.Get(Stream_Video, 0, Video_Delay_Original_String3)+__T("</formatTimeStart>\n");
else if (!MI.Get(Stream_Video, 0, Video_Delay_String3).empty())
//.........这里部分代码省略.........
示例7: FileHeader_Begin
//---------------------------------------------------------------------------
bool File_SubRip::FileHeader_Begin()
{
if (!IsSub && (Buffer_Size<File_Size && Buffer_Size<65536))
{
Element_WaitForMoreData();
return false;
}
ZtringListList List;
List.Separator_Set(0, __T("\n\n"));
List.Separator_Set(1, __T("\n"));
if (Buffer[0]==0xEF
&& Buffer[1]==0xBB
&& Buffer[2]==0xBF)
HasBOM=true;
bool IsLocal=false;
Ztring Temp;
Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0));
if (Temp.empty())
{
Temp.From_Local((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); // Trying from local code page
IsLocal=true;
}
Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
List.Write(Temp);
if (List(0, 0)==__T("WEBVTT FILE") || List(0, 0)==__T("WEBVTT"))
IsVTT=true;
if (!IsVTT)
{
size_t IsOk=0;
size_t IsNok=0;
for (size_t Pos=0; Pos<List.size(); Pos++)
{
if (List(Pos, 0).To_int64u()==Pos+1)
IsOk++;
else
IsNok++;
if (List(Pos, 1).size()>22 && List(Pos, 1)[2]==__T(':') && List(Pos, 1)[5]==__T(':') && List(Pos, 1).find(__T(" --> "))!=string::npos)
IsOk++;
else
IsNok++;
}
if (!IsOk || IsNok>IsOk/2)
{
Reject();
return true;
}
}
if (!IsSub && File_Size!=(int64u)-1 && Buffer_Size!=File_Size)
{
Element_WaitForMoreData();
return false;
}
if (!Status[IsAccepted])
{
Accept();
Fill(Stream_General, 0, General_Format, IsVTT?"WebVTT":"SubRip");
Stream_Prepare(Stream_Text);
Fill(Stream_Text, 0, "Format", IsVTT?"WebVTT":"SubRip");
Fill(Stream_Text, 0, "Codec", IsVTT?"WebVTT":"SubRip");
}
if (IsLocal)
Temp.From_Local((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0));
else
Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0));
Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
List.Write(Temp);
#if MEDIAINFO_DEMUX
size_t Pos=0;
for (;;)
{
if (Pos>=List.size())
break;
if (List[Pos].size()>=3 || (IsVTT && List[Pos].size()>=2))
{
Ztring PTS_Begin_String=List[Pos][IsVTT?0:1].SubString(Ztring(), __T(" --> "));
Ztring PTS_End_String=List[Pos][IsVTT?0:1].SubString(__T(" --> "), Ztring());
if (IsVTT)
{
size_t Extra_Pos=PTS_End_String.find(__T(' '));
if (Extra_Pos!=string::npos)
PTS_End_String.resize(Extra_Pos); //Discarding positioning
}
item Item;
Item.PTS_Begin=SubRip_str2timecode(PTS_Begin_String.To_UTF8().c_str());
Item.PTS_End=SubRip_str2timecode(PTS_End_String.To_UTF8().c_str());
for (size_t Pos2=IsVTT?1:2; Pos2<List[Pos].size(); Pos2++)
//.........这里部分代码省略.........
示例8: Streams_Finish_ParseReference
//---------------------------------------------------------------------------
void File_Dxw::Streams_Finish_ParseReference()
{
if (MI==NULL)
{
//Configuring file name
Ztring Name=Reference->FileName;
if (Name.find(_T("file:"))==0)
{
Name.erase(0, 5); //Removing "file:", this is the default behaviour and this makes comparison easier
Name=ZenLib::Format::Http::URL_Encoded_Decode(Name);
}
Ztring AbsoluteName;
if (Name.find(_T(':'))!=1 && Name.find(_T("/"))!=0 && Name.find(_T("\\\\"))!=0) //If absolute patch
{
AbsoluteName=ZenLib::FileName::Path_Get(File_Name);
if (!AbsoluteName.empty())
AbsoluteName+=ZenLib::PathSeparator;
}
AbsoluteName+=Name;
#ifdef __WINDOWS__
AbsoluteName.FindAndReplace(_T("/"), _T("\\"), 0, Ztring_Recursive); //Name normalization
#endif //__WINDOWS__
if (AbsoluteName==File_Name)
{
if (StreamKind_Last!=Stream_Max)
{
Fill(StreamKind_Last, StreamPos_Last, "Source_Info", "Circular");
StreamKind_Last=Stream_Max;
StreamPos_Last=(size_t)-1;
}
return;
}
//Configuration
MI=new MediaInfo_Internal();
MI->Option(_T("File_KeepInfo"), _T("1"));
#if MEDIAINFO_NEXTPACKET
if (Config->NextPacket_Get())
MI->Option(_T("File_NextPacket"), _T("1"));
#endif //MEDIAINFO_NEXTPACKET
#if MEDIAINFO_EVENTS
if (Config->Event_CallBackFunction_IsSet())
MI->Option(_T("File_Event_CallBackFunction"), Config->Event_CallBackFunction_Get());
MI->Option(_T("File_SubFile_StreamID_Set"), Ztring::ToZtring((size_t)(Reference-References.begin()+1)));
#endif //MEDIAINFO_EVENTS
#if MEDIAINFO_DEMUX
if (Config->Demux_Unpacketize_Get())
MI->Option(_T("File_Demux_Unpacketize"), _T("1"));
#endif //MEDIAINFO_DEMUX
//Run
if (!MI->Open(AbsoluteName))
{
//Filling
if (StreamKind_Last!=Stream_Max)
{
Fill(StreamKind_Last, StreamPos_Last, General_ID, Ztring::ToZtring((size_t)(Reference-References.begin()+1)));
Fill(StreamKind_Last, StreamPos_Last, "Source", (*Reference).FileName);
Fill(StreamKind_Last, StreamPos_Last, "Source_Info", "Missing");
}
delete MI; MI=NULL;
}
}
if (MI)
{
#if MEDIAINFO_NEXTPACKET
while (MI->Open_NextPacket()[8])
{
#if MEDIAINFO_DEMUX
if (Config->Event_CallBackFunction_IsSet())
{
Config->Demux_EventWasSent=true;
return;
}
#endif //MEDIAINFO_DEMUX
}
#endif //MEDIAINFO_NEXTPACKET
Streams_Finish_ParseReference_Finalize();
delete MI; MI=NULL;
}
}
示例9: Read_Buffer_Continue
//.........这里部分代码省略.........
}
}
#if MEDIAINFO_DEMUX
Demux(Buffer, Buffer_Size, ContentType_MainStream);
#endif //MEDIAINFO_DEMUX
// Output
#if MEDIAINFO_EVENTS
for (; p; p=p->NextSiblingElement())
{
//p
if (!strcmp(p->Value(), "p"))
{
int64u DTS_Begin=(int64u)-1;
const char* Attribute=p->Attribute("begin");
if (Attribute)
DTS_Begin=Ttml_str2timecode(Attribute);
int64u DTS_End=(int64u)-1;
Attribute=p->Attribute("end");
if (Attribute)
DTS_End=Ttml_str2timecode(Attribute);
string ContentUtf8;
XMLPrinter printer;
p->Accept(&printer);
ContentUtf8+=printer.CStr();
while (!ContentUtf8.empty() && (ContentUtf8[ContentUtf8.size()-1]=='\r' || ContentUtf8[ContentUtf8.size()-1]=='\n'))
ContentUtf8.resize(ContentUtf8.size()-1);
Ztring Content; Content.From_UTF8(ContentUtf8.c_str());
Frame_Count_NotParsedIncluded=Frame_Count;
EVENT_BEGIN (Global, SimpleText, 0)
//Hack: remove "p", "span", "br"
Content.FindAndReplace(__T("\r"), Ztring(), 0, ZenLib::Ztring_Recursive);
Content.FindAndReplace(__T("\n"), Ztring(), 0, ZenLib::Ztring_Recursive);
for (;;)
{
size_t Span_Begin=Content.find(__T("<p"));
if (Span_Begin==string::npos)
break;
size_t Span_End=Content.find(__T(">"), Span_Begin+5);
if (Span_End==string::npos)
break;
size_t ShlashSpan_Begin=Content.find(__T("</p>"), Span_End+1);
if (ShlashSpan_Begin==string::npos)
break;
Content.erase(ShlashSpan_Begin, 7);
Content.erase(Span_Begin, Span_End-Span_Begin+1);
}
for (;;)
{
size_t Span_Begin=Content.find(__T("<span"));
if (Span_Begin==string::npos)
break;
size_t Span_End=Content.find(__T(">"), Span_Begin+5);
if (Span_End==string::npos)
break;
size_t ShlashSpan_Begin=Content.find(__T("</span>"), Span_End+1);
if (ShlashSpan_Begin==string::npos)
break;
示例10: FileHeader_Begin
//---------------------------------------------------------------------------
bool File_SubRip::FileHeader_Begin()
{
if (!IsSub && (Buffer_Size<File_Size && Buffer_Size<65536))
{
Element_WaitForMoreData();
return false;
}
ZtringListList List;
List.Separator_Set(0, __T("\n\n"));
List.Separator_Set(1, __T("\n"));
if (Buffer_Size>=3
&& Buffer[0]==0xEF
&& Buffer[1]==0xBB
&& Buffer[2]==0xBF)
HasBOM=true;
bool IsLocal=false;
Ztring Temp;
Temp.From_UTF8((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0));
if (Temp.empty())
{
#ifdef WINDOWS
Temp.From_Local((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0)); // Trying from local code page
#else //WINDOWS
Temp.From_ISO_8859_1((const char*)Buffer+(HasBOM?3:0), (Buffer_Size>65536?65536:Buffer_Size)-(HasBOM?3:0));
#endif //WINDOWS
IsLocal=true;
}
Temp.FindAndReplace(__T("\r\n"), __T("\n"), 0, Ztring_Recursive);
Temp.FindAndReplace(__T("\r"), __T("\n"), 0, Ztring_Recursive);
List.Write(Temp);
if (List(0, 0)==__T("WEBVTT FILE") || List(0, 0)==__T("WEBVTT"))
IsVTT=true;
if (!IsVTT)
{
size_t IsOk=0;
size_t IsNok=0;
for (size_t Pos=0; Pos<List.size(); Pos++)
{
if (List(Pos, 0).To_int64u()==Pos+1)
IsOk++;
else
IsNok++;
if (List(Pos, 1).size()>22 && List(Pos, 1)[2]==__T(':') && List(Pos, 1)[5]==__T(':') && List(Pos, 1).find(__T(" --> "))!=string::npos)
IsOk++;
else
IsNok++;
}
if (!IsOk || IsNok>IsOk/2)
{
Reject();
return true;
}
}
if (!IsSub && File_Size!=(int64u)-1 && Buffer_Size!=File_Size)
{
Element_WaitForMoreData();
return false;
}
if (!Status[IsAccepted])
{
Accept();
Fill(Stream_General, 0, General_Format, IsVTT?"WebVTT":"SubRip");
Stream_Prepare(Stream_Text);
Fill(Stream_Text, 0, "Format", IsVTT?"WebVTT":"SubRip");
Fill(Stream_Text, 0, "Codec", IsVTT?"WebVTT":"SubRip");
}
if (IsLocal)
#ifdef WINDOWS
Temp.From_Local((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0));
#else //WINDOWS
Temp.From_ISO_8859_1((const char*)Buffer+(HasBOM?3:0), Buffer_Size-(HasBOM?3:0));
#endif //WINDOWS
else