-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRArchieve.java
More file actions
45 lines (44 loc) · 1.63 KB
/
RArchieve.java
File metadata and controls
45 lines (44 loc) · 1.63 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
public class RArchieve {
//return null - if "string" is empry or "string" consist wrong data
public String getDecompressData(String string)
{
StringBuilder builder = new StringBuilder();
int len = string.length();
if(len == 0)
return null;
int currentCodePoint,appendCodePoint = 0,countOfSymblos = 0,currentDegree = 1;
for(int offset = 0;offset < len;)
{
currentCodePoint = string.codePointAt(offset);
//
if(Character.isDigit(currentCodePoint)) {
countOfSymblos = countOfSymblos + currentDegree * (currentCodePoint - '0');
currentDegree*=10;
}
else {
//case error format data
if(countOfSymblos == 0 && offset != 0)
return null;
//add countOfSymbols by word
for(int i = 0;i < countOfSymblos;++i)
builder.appendCodePoint(appendCodePoint);
//resetting variables
currentDegree = 1;
countOfSymblos = 0;
appendCodePoint = currentCodePoint;
}
//to offset on string
offset+=Character.charCount(currentCodePoint);
}
//At the end - AGAIN
//case error format data
if(countOfSymblos == 0)
return null;
else
//add countOfSymbols by word
for(int i = 0;i < countOfSymblos;++i)
builder.appendCodePoint(appendCodePoint);
//
return builder.toString();
}
}