Breaks a LIKE pattern into a chain of sub-patterns.
(pattern: &str)
| 318 | |
| 319 | /// Breaks a LIKE pattern into a chain of sub-patterns. |
| 320 | fn build_subpatterns(pattern: &str) -> Result<Vec<Subpattern>, EvalError> { |
| 321 | let mut subpatterns = Vec::with_capacity(MAX_SUBPATTERNS); |
| 322 | let mut current = Subpattern::default(); |
| 323 | let mut in_wildcard = true; |
| 324 | let mut in_escape = false; |
| 325 | for c in pattern.chars() { |
| 326 | match c { |
| 327 | c if !in_escape && c == DEFAULT_ESCAPE => { |
| 328 | in_escape = true; |
| 329 | in_wildcard = false; |
| 330 | } |
| 331 | '_' if !in_escape => { |
| 332 | if !in_wildcard { |
| 333 | current.suffix.shrink_to_fit(); |
| 334 | subpatterns.push(mem::take(&mut current)); |
| 335 | in_wildcard = true; |
| 336 | } |
| 337 | current.consume += 1; |
| 338 | } |
| 339 | '%' if !in_escape => { |
| 340 | if !in_wildcard { |
| 341 | current.suffix.shrink_to_fit(); |
| 342 | subpatterns.push(mem::take(&mut current)); |
| 343 | in_wildcard = true; |
| 344 | } |
| 345 | current.many = true; |
| 346 | } |
| 347 | c => { |
| 348 | current.suffix.push(c); |
| 349 | in_escape = false; |
| 350 | in_wildcard = false; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | if in_escape { |
| 355 | return Err(EvalError::UnterminatedLikeEscapeSequence); |
| 356 | } |
| 357 | current.suffix.shrink_to_fit(); |
| 358 | subpatterns.push(current); |
| 359 | subpatterns.shrink_to_fit(); |
| 360 | Ok(subpatterns) |
| 361 | } |
| 362 | |
| 363 | /// Builds a regular expression that matches some parsed Subpatterns. |
| 364 | fn build_regex(subpatterns: &[Subpattern], case_insensitive: bool) -> Result<Regex, EvalError> { |
no test coverage detected