| 49 | } |
| 50 | |
| 51 | Lyrics* lrcParseLoadWithBuffer(char* buffer) |
| 52 | { |
| 53 | regmatch_t pm[5]; |
| 54 | regex_t preg; |
| 55 | |
| 56 | char* pattern = "\\[([0-9]{2}):([0-5][0-9])\\.([0-9]{2})\\](.*)"; |
| 57 | |
| 58 | if (regcomp(&preg, pattern, REG_EXTENDED |REG_NEWLINE) != 0) |
| 59 | return NULL; |
| 60 | |
| 61 | uint32_t lines = 0;//lyrics line count |
| 62 | |
| 63 | Lyricsline* lrcline = malloc(sizeof(Lyricsline) * MAX_LYRICSLINE); |
| 64 | |
| 65 | while(1){ |
| 66 | if(regexec(&preg,buffer, 5, pm, REG_NOTEOL) != REG_NOMATCH){ |
| 67 | |
| 68 | char* m = getStringFromRegmatch(buffer,pm[1].rm_so,pm[1].rm_eo); |
| 69 | char* s = getStringFromRegmatch(buffer,pm[2].rm_so,pm[2].rm_eo); |
| 70 | char* ms = getStringFromRegmatch(buffer,pm[3].rm_so,pm[3].rm_eo); |
| 71 | char* word = getStringFromRegmatch(buffer,pm[4].rm_so,pm[4].rm_eo); |
| 72 | |
| 73 | |
| 74 | lrcline[lines].m = atol(m); |
| 75 | lrcline[lines].s = atoi(s); |
| 76 | lrcline[lines].ms = atoi(ms); |
| 77 | lrcline[lines].word = word; |
| 78 | lrcline[lines].totalms = (atol(m) * 60 + atoi(s)) * 1000 + atoi(ms) * 10; |
| 79 | |
| 80 | free(m); |
| 81 | free(s); |
| 82 | free(ms); |
| 83 | |
| 84 | lines++; |
| 85 | buffer+=pm[0].rm_eo; |
| 86 | }else{break;} |
| 87 | } |
| 88 | |
| 89 | regfree(&preg); |
| 90 | |
| 91 | Lyrics* lyrics = malloc(sizeof(Lyrics)); |
| 92 | lyrics->lrclines = lrcline; |
| 93 | lyrics->lyricscount = lines; |
| 94 | |
| 95 | return lyrics; |
| 96 | } |
| 97 | |
| 98 | void lrcParseClose(Lyrics* lyrics) |
| 99 | { |
no test coverage detected