Unified · Split
| @@ -108,36 +108,36 @@ static int compare_sub_priority(const void *a, const void *b) · 107 unmodified lines | |||
| 108 | return strcoll(s1->fname, s2->fname); | 108 | return strcoll(s1->fname, s2->fname); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static struct bstr guess_lang_from_filename(struct bstr name, int *fn_start) | 111 | static struct bstr guess_lang_from_filename(struct bstr name, int *lang_start) |
| 112 | { | 112 | { |
| 113 | if (name.len < 2) | 113 | if (name.len < 2) |
| 114 | return (struct bstr){NULL, 0}; | 114 | return (struct bstr){NULL, 0}; |
| 115 | 115 | ||
| 116 | int n = 0; | 116 | int lang_length = 0; |
| 117 | int i = name.len - 1; | 117 | int i = name.len - 1; |
| 118 | 118 | ||
| 119 | char thing = '.'; | 119 | char delimiter = '.'; |
| 120 | if (name.start[i] == ')') { | 120 | if (name.start[i] == ')') { |
| 121 | thing = '('; | 121 | delimiter = '('; |
| 122 | i--; | 122 | i--; |
| 123 | } | 123 | } |
| 124 | if (name.start[i] == ']') { | 124 | if (name.start[i] == ']') { |
| 125 | thing = '['; | 125 | delimiter = '['; |
| 126 | i--; | 126 | i--; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | while (i >= 0 && mp_isalpha(name.start[i])) { | 129 | while (i >= 0 && mp_isalpha(name.start[i])) { |
| 130 | n++; | 130 | lang_length++; |
| 131 | if (n > 3) | 131 | if (lang_length > 3) |
| 132 | return (struct bstr){NULL, 0}; | 132 | return (struct bstr){NULL, 0}; |
| 133 | i--; | 133 | i--; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | if (n < 2 || i == 0 || name.start[i] != thing) | 136 | if (lang_length < 2 || i == 0 || name.start[i] != delimiter) |
| 137 | return (struct bstr){NULL, 0}; | 137 | return (struct bstr){NULL, 0}; |
| 138 | 138 | ||
| 139 | *fn_start = i; | 139 | *lang_start = i; |
| 140 | return (struct bstr){name.start + i + 1, n}; | 140 | return (struct bstr){name.start + i + 1, lang_length}; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | char *mp_guess_lang_from_filename(void* ctx, const char *filename) | 143 | char *mp_guess_lang_from_filename(void* ctx, const char *filename) |