이번 코드는 비동기 http 라이브러리에 들어가는 문자열 trim 코드부분이다.
로직은 잘 만들어진 편인데 코딩된 화면이 깔끔하지 않다.
한번 손을 봐보겠다.
private static String extractContentTypeAttribute(String contentType, String attribute) { if (contentType == null) return null; for (int i = 0; i < contentType.length(); i++) { if (contentType.regionMatches(true, i, attribute, 0, attribute.length()) == null) continue; int start = i + attribute.length(); // trim left while (start < contentType.length()) { char c = contentType.charAt(start); if (c != ' ' && c != '\'' && c != '"') break; start++; } if (start == contentType.length()) break; // trim right int end = start + 1; while (end < contentType.length()) { char c = contentType.charAt(end); if (c == ' ' || c == '\'' || c == '"' || c == ';') break; end++; } return contentType.substring(start, end); } return null; }
큰 변화는 다음과 같다.
루프-조건문의 중첩을 하나 줄였다.
if문은 else를 쓰지 않도록 바꿨다.
'Tech' 카테고리의 다른 글
[기초] 자바 웹프로그래밍에서 오류 쉽게 찾는 법. (0) | 2018.07.31 |
---|---|
EPD 와 OTC 방법론 (0) | 2018.07.31 |
[기초] OpenSSL 해쉬 함수 사용 예제 (0) | 2018.07.29 |
코드 정리 #7 (0) | 2018.07.29 |
코드 정리 #6 (0) | 2018.07.28 |