|
1 | 1 | use regex::Regex;
|
| 2 | +use std::cmp::Ordering; |
2 | 3 |
|
3 | 4 | /// Handles track formatting.
|
4 | 5 | pub struct TrackFormatter {
|
@@ -163,21 +164,19 @@ impl TrackFormatter {
|
163 | 164 | }
|
164 | 165 |
|
165 | 166 | /// Check parenthesis counts match and insert missing.
|
166 |
| - fn balance_parenthesis(&self, mut title: String) -> String { |
| 167 | + fn balance_parenthesis(&self, title: String) -> String { |
167 | 168 | let open_count = title.matches('(').count();
|
168 | 169 | let close_count = title.matches(')').count();
|
169 |
| - if open_count > close_count { |
170 |
| - title = Self::add_missing_closing_parentheses(&title); |
171 |
| - } else if open_count < close_count { |
172 |
| - title = Self::add_missing_opening_parentheses(&title); |
| 170 | + match open_count.cmp(&close_count) { |
| 171 | + Ordering::Greater => Self::add_missing_closing_parentheses(&title), |
| 172 | + Ordering::Less => Self::add_missing_opening_parentheses(&title), |
| 173 | + _ => title, |
173 | 174 | }
|
174 |
| - title |
175 | 175 | }
|
176 | 176 |
|
177 | 177 | fn add_missing_closing_parentheses(text: &str) -> String {
|
178 | 178 | let mut open_count: usize = 0;
|
179 | 179 | let mut result = String::new();
|
180 |
| - println!("Missing closing"); |
181 | 180 |
|
182 | 181 | for char in text.chars() {
|
183 | 182 | match char {
|
@@ -207,7 +206,6 @@ impl TrackFormatter {
|
207 | 206 | fn add_missing_opening_parentheses(text: &str) -> String {
|
208 | 207 | let mut open_count: usize = 0;
|
209 | 208 | let mut result = String::new();
|
210 |
| - println!("Missing opening"); |
211 | 209 |
|
212 | 210 | for char in text.chars().rev() {
|
213 | 211 | match char {
|
|
0 commit comments