1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.util;
15
16 import ch.qos.logback.core.CoreConstants;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22
23
24 public class LoggerNameUtil {
25
26 public static int getFirstSeparatorIndexOf(String name) {
27 return getSeparatorIndexOf(name, 0);
28 }
29
30
31
32
33
34
35
36
37
38 public static int getSeparatorIndexOf(String name, int fromIndex) {
39 int dotIndex = name.indexOf(CoreConstants.DOT, fromIndex);
40 int dollarIndex = name.indexOf(CoreConstants.DOLLAR, fromIndex);
41
42 if (dotIndex == -1 && dollarIndex == -1)
43 return -1;
44 if (dotIndex == -1)
45 return dollarIndex;
46 if (dollarIndex == -1)
47 return dotIndex;
48
49 return dotIndex < dollarIndex ? dotIndex : dollarIndex;
50 }
51
52 public static List<String> computeNameParts(String loggerName) {
53 List<String> partList = new ArrayList<String>();
54
55 int fromIndex = 0;
56 while (true) {
57 int index = getSeparatorIndexOf(loggerName, fromIndex);
58 if (index == -1) {
59 partList.add(loggerName.substring(fromIndex));
60 break;
61 }
62 partList.add(loggerName.substring(fromIndex, index));
63 fromIndex = index + 1;
64 }
65 return partList;
66 }
67 }