1
1
#include "time.h"
2
2
3
3
enum {
4
- TIME_PARSER_FLEXIBLE_LENGTH_BLOCK ,
5
- TIME_PARSER_FIXED_LENGTH_BLOCK ,
6
- TIME_PARSER_MINISECOND ,
4
+ lyric_time_status_flexible_length_block ,
5
+ lyric_time_status_fixed_length_block ,
6
+ lyric_time_status_minisecond ,
7
7
};
8
8
9
9
bool lyric_time_create_from_string (Time * const restrict time , const char * const restrict string , const size_t length ) {
10
10
if (unlikely (time == NULL )) {
11
11
return false;
12
12
}
13
13
time -> second = time -> minisecond = 0 ;
14
- size_t status = TIME_PARSER_FLEXIBLE_LENGTH_BLOCK ;
14
+ size_t status = lyric_time_status_flexible_length_block ;
15
15
size_t counter = 0 ;
16
16
for (size_t i = 0 ; i < length ; ++ i ) {
17
17
switch (status ) {
18
- case TIME_PARSER_FLEXIBLE_LENGTH_BLOCK : {
18
+ case lyric_time_status_flexible_length_block : {
19
19
if (isdigit (string [i ])) {
20
20
time -> second = time -> second * 10 + (string [i ] - '0' );
21
21
} else if (string [i ] == ':' ) {
22
22
time -> second *= 60 ;
23
- status = TIME_PARSER_FIXED_LENGTH_BLOCK ;
23
+ status = lyric_time_status_fixed_length_block ;
24
24
} else {
25
25
return false;
26
26
}
27
27
} break ;
28
- case TIME_PARSER_FIXED_LENGTH_BLOCK : {
28
+ case lyric_time_status_fixed_length_block : {
29
29
if (isdigit (string [i ])) {
30
30
if (counter == 2 ) {
31
31
return false;
@@ -36,20 +36,20 @@ bool lyric_time_create_from_string(Time *const restrict time, const char *const
36
36
return false;
37
37
}
38
38
time -> second *= 60 ;
39
- status = TIME_PARSER_FIXED_LENGTH_BLOCK ;
39
+ status = lyric_time_status_fixed_length_block ;
40
40
counter = 0 ;
41
41
} else if (string [i ] == '.' ) {
42
42
if (counter != 2 ) {
43
43
return false;
44
44
}
45
- status = TIME_PARSER_MINISECOND ;
45
+ status = lyric_time_status_minisecond ;
46
46
counter = 0 ;
47
47
} else {
48
48
return false;
49
49
}
50
50
++ counter ;
51
51
} break ;
52
- case TIME_PARSER_MINISECOND : {
52
+ case lyric_time_status_minisecond : {
53
53
if (isdigit (string [i ])) {
54
54
if (counter == 4 ) {
55
55
return false;
@@ -62,7 +62,7 @@ bool lyric_time_create_from_string(Time *const restrict time, const char *const
62
62
} break ;
63
63
}
64
64
}
65
- if (status == TIME_PARSER_MINISECOND ) {
65
+ if (status == lyric_time_status_minisecond ) {
66
66
while (counter < 3 ) {
67
67
time -> minisecond *= 10 ;
68
68
++ counter ;
0 commit comments