-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtils.java
More file actions
122 lines (81 loc) · 2.14 KB
/
StringUtils.java
File metadata and controls
122 lines (81 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import DirectCharArray;
public class StringUtils {
public static String[] split(String txt, char c) {
String txt2 = txt;
List<String> list = new ArrayList<>();
int pos = 0;
while((pos = txt2.indexOf(',')) > 0) {
list.add(txt2.substring(0, pos));
txt2 = txt2.substring(pos + 1);
}
if(txt2 != null && txt2.length() > 0) {
list.add(txt2);
}
int resultSize = list.size();
String[] result = new String[resultSize];
return list.toArray(result);
}
public static String[] unsafeCopy(String str, char c) {
str = str + c;
DirectCharArray direct = DirectCharArray.getInstance();
direct.allocate(str.length());
direct.intern(str);
List<String> col = new ArrayList<>();
char[] word = new char[1000];
int cnt = 0;
for(int i = 0; i < str.length(); i++) {
char cur = direct.get(i);
if(cur == c) {
col.add( new String(Arrays.copyOfRange(word, 0, cnt)));
cnt = 0;
continue;
}
word[cnt] = cur;
cnt++;
}
return col.toArray(new String[col.size()]);
}
public static String[] unsafecountBefore(String str, char c) {
str = str + c;
DirectCharArray direct = DirectCharArray.getInstance();
direct.allocate(str.length());
List idxs = new ArrayList();
long cnt = 0L;
for(char cur : str.toCharArray()) {
direct.set(cnt, cur);
if(cur == c) {
idxs.add(cnt);
}
cnt++;
}
String[] column = new String[idxs.size()];
long start = 0L;
long stop = 0L;
for(int i = 0; i < idxs.size(); i++) {
stop = (Long) idxs.get(i) + 1;
column[i] = new String(direct.get(start, stop));
start = stop;
}
return column;
}
public static String[] loop(String str, char c) {
str = str + c;
int lenght = 0;
int start = 0;
List<String> col = new ArrayList<>();
for(int i = 0; i < str.length(); i++) {
char cur = str.charAt(i);
if(cur == c) {
col.add(str.substring(start, start + lenght));
start = i + 1;
lenght = 0;
continue;
}
lenght++;
}
return col.toArray(new String[col.size()]);
}
}