foobar2000 SDK  2015-08-03
Functions
chapterizer.cpp File Reference

Go to the source code of this file.

Functions

double cuesheet_parse_index_time_e (const char *p_string, t_size p_length)
 
unsigned cuesheet_parse_index_time_ticks_e (const char *p_string, t_size p_length)
 

Function Documentation

double cuesheet_parse_index_time_e ( const char *  p_string,
t_size  p_length 
)

Definition at line 43 of file chapterizer.cpp.

44 {
45  return (double) cuesheet_parse_index_time_ticks_e(p_string,p_length) / 75.0;
46 }
unsigned cuesheet_parse_index_time_ticks_e(const char *p_string, t_size p_length)
Definition: chapterizer.cpp:48
unsigned cuesheet_parse_index_time_ticks_e ( const char *  p_string,
t_size  p_length 
)

Definition at line 48 of file chapterizer.cpp.

49 {
50  p_length = pfc::strlen_max(p_string,p_length);
51  t_size ptr = 0;
52  t_size splitmarks[2];
53  t_size splitptr = 0;
54  for(ptr=0;ptr<p_length;ptr++)
55  {
56  if (p_string[ptr] == ':')
57  {
58  if (splitptr >= 2) throw std::runtime_error("invalid INDEX time syntax");
59  splitmarks[splitptr++] = ptr;
60  }
61  else if (!pfc::char_is_numeric(p_string[ptr])) throw std::runtime_error("invalid INDEX time syntax");
62  }
63 
64  t_size minutes_base = 0, minutes_length = 0, seconds_base = 0, seconds_length = 0, frames_base = 0, frames_length = 0;
65 
66  switch(splitptr)
67  {
68  case 0:
69  frames_base = 0;
70  frames_length = p_length;
71  break;
72  case 1:
73  seconds_base = 0;
74  seconds_length = splitmarks[0];
75  frames_base = splitmarks[0] + 1;
76  frames_length = p_length - frames_base;
77  break;
78  case 2:
79  minutes_base = 0;
80  minutes_length = splitmarks[0];
81  seconds_base = splitmarks[0] + 1;
82  seconds_length = splitmarks[1] - seconds_base;
83  frames_base = splitmarks[1] + 1;
84  frames_length = p_length - frames_base;
85  break;
86  }
87 
88  unsigned ret = 0;
89 
90  if (frames_length > 0) ret += pfc::atoui_ex(p_string + frames_base,frames_length);
91  if (seconds_length > 0) ret += 75 * pfc::atoui_ex(p_string + seconds_base,seconds_length);
92  if (minutes_length > 0) ret += 60 * 75 * pfc::atoui_ex(p_string + minutes_base,minutes_length);
93 
94  return ret;
95 }
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
size_t t_size
Definition: int_types.h:48
unsigned atoui_ex(const char *p_string, t_size p_string_len)
bool char_is_numeric(char_t p_char)
Definition: string_base.h:99