문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 다음 판 | 이전 판 | ||
|
wiki:programming:pattern [2021/01/13 19:21] dhan 만듦 |
wiki:programming:pattern [2023/01/13 18:44] (현재) |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| - | ====== Ant style pattern ======^ 표기 | + | ====== Ant style pattern ====== |
| - | | | + | |
| + | |||
| + | |||
| + | ===== 설명 ===== | ||
| + | ^ 표기 | ||
| + | | ? | 1개의 문자와 매칭 (matches single character) | ||
| + | | * | 0개 이상의 문자와 매칭 (matches zero or more characters) | ||
| + | | * * | 0개 이상의 디렉토리와 파일 매칭 (matches all files / directories) | ||
| + | |||
| + | ===== 사용 예 ===== | ||
| + | <code java> | ||
| + | import static org.hamcrest.CoreMatchers.*; | ||
| + | import static org.junit.Assert.*; | ||
| + | |||
| + | import org.junit.Test; | ||
| + | import org.springframework.util.AntPathMatcher; | ||
| + | |||
| + | public class AntStylePatternMatcherUtilTest { | ||
| + | |||
| + | @Test | ||
| + | public void antStylePatternTest() { | ||
| + | // double asterisks | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | // single asterisks | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | assertThat(false, | ||
| + | assertThat(false, | ||
| + | |||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | assertThat(false, | ||
| + | assertThat(false, | ||
| + | |||
| + | // double and single combine | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | |||
| + | // question-mark | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | assertThat(true, | ||
| + | |||
| + | } | ||
| + | |||
| + | private boolean checkAntPattern(String pattern, String inputStr) { | ||
| + | return matches(pattern, | ||
| + | } | ||
| + | |||
| + | public static boolean matches(String pattern, String inputStr) { | ||
| + | AntPathMatcher antPathMatcher = new AntPathMatcher(); | ||
| + | return antPathMatcher.match(pattern, | ||
| + | } | ||
| + | } | ||
| + | </ | ||