MCPcopy Create free account
hub / github.com/MediaArea/MediaInfoLib / SubRip_str2timecode

Function SubRip_str2timecode

Source/MediaInfo/Text/File_SubRip.cpp:39–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37//***************************************************************************
38
39int64u SubRip_str2timecode(const char* Value)
40{
41 size_t Length=strlen(Value);
42
43 //Xs
44 if (Length
45 && Value[Length-1]=='s')
46 return (int64u)float64_int64s(atof(Value) * 1000000000);
47
48 //Test if HH: is present
49 if (Length<5)
50 return 0;
51 int64u ToReturn;
52 if (Length!=5 && Value[5]==':')
53 {
54 if (Value[0]<'0' || Value[0]>'9'
55 || Value[1]<'0' || Value[1]>'9'
56 || Value[2]!=':')
57 return 0;
58 ToReturn=(int64u)(Value[0]-'0')*10*60*60*1000000000
59 +(int64u)(Value[1]-'0') *60*60*1000000000;
60 Value+=3;
61 Length-=3;
62 }
63 else
64 ToReturn=0;
65 if (Length<5
66 || Value[0]<'0' || Value[0]>'9'
67 || Value[1]<'0' || Value[1]>'9'
68 || Value[2]!=':'
69 || Value[3]<'0' || Value[3]>'9'
70 || Value[4]<'0' || Value[4]>'9')
71 return 0;
72 ToReturn+=(int64u)(Value[0]-'0') *10*60*1000000000
73 +(int64u)(Value[1]-'0') *60*1000000000
74 +(int64u)(Value[3]-'0') *10*1000000000
75 +(int64u)(Value[4]-'0') *1000000000;
76 if (Length>5 && (Value[5]=='.' || Value[5]==','))
77 {
78 if (Length>6+9)
79 Length=6+9; //Nanoseconds max
80 const char* Value_End=Value+Length;
81 Value+=6;
82 int64u Multiplier=100000000;
83 while (Value<Value_End && *Value>='0' && *Value<='9')
84 {
85 ToReturn+=(int64u)(*Value-'0')*Multiplier;
86 Multiplier/=10;
87 Value++;
88 }
89 }
90
91 return ToReturn;
92}
93
94//---------------------------------------------------------------------------
95struct timeline

Callers 1

FileHeader_BeginMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected