blob: 151f7e3f9d6972cf6d8d29008cb509ae15a7b7a6 (
plain) (
blame)
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
|
package com.camilstaps.taize;
import org.json.JSONException;
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.camilstaps.common.Date;
import com.camilstaps.common.DatedString;
/**
* Created by camilstaps on 7-4-15.
*/
public class DailyReading extends DatedString {
public DailyReading(Date date, String string) {
super(date, string);
}
public String getTextWithoutReference() {
Matcher bible_ref_m = referenceMatcher();
if (bible_ref_m.find()) {
return string.substring(0, bible_ref_m.start() - 1);
} else {
return string;
}
}
public BibleText getBibleReference() {
final Matcher bible_ref_m = referenceMatcher();
if (!bible_ref_m.find()) {
return null;
}
if (bible_ref_m.group(3) == null) {
return new BibleText(bible_ref_m.group(1), Integer.parseInt(bible_ref_m.group(2)));
} else {
return new BibleText(bible_ref_m.group(1), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(3)), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(4)));
}
}
private Matcher referenceMatcher() {
Pattern bible_ref = Pattern.compile("\\((\\d? ?[a-zA-Z]+) (\\d{1,2})(?::|,)?(\\d+)?-?(\\d+?)?\\)");
return bible_ref.matcher(string);
}
public static DailyMeditation fromString(String s) throws JSONException, ParseException {
return (DailyMeditation) DatedString.fromString(s, DailyMeditation.class);
}
}
|