Fixed a bug with multi word lists in title parsing

pull/14/head
Sam Bosley 13 years ago
parent 33915a1206
commit 69997500ea

@ -446,7 +446,7 @@ public class TaskService {
* @return * @return
*/ */
public static boolean parseQuickAddMarkup(Task task, ArrayList<String> tags) { public static boolean parseQuickAddMarkup(Task task, ArrayList<String> tags) {
return new TitleParser(task, tags).parse(); return TitleParser.parse(task, tags);
} }
/** /**

@ -22,15 +22,8 @@ import com.todoroo.astrid.tags.TagService;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class TitleParser { public class TitleParser {
Task task;
ArrayList<String> tags;
public TitleParser(Task task, ArrayList<String> tags){ public static boolean parse(Task task, ArrayList<String> tags) {
this.task = task;
this.tags = tags;
}
public boolean parse() {
boolean markup = false; boolean markup = false;
markup = repeatHelper(task) || markup; markup = repeatHelper(task) || markup;
markup = dayHelper(task) || markup; markup = dayHelper(task) || markup;
@ -39,15 +32,15 @@ public class TitleParser {
return markup; return markup;
} }
public static String[] trimParenthesisAndSplit(String pattern){ public static String trimParenthesis(String pattern){
if (pattern.charAt(0) == '#' || pattern.charAt(0) == '@') { if (pattern.charAt(0) == '#' || pattern.charAt(0) == '@') {
pattern = pattern.substring(1); pattern = pattern.substring(1);
} }
if ('(' == pattern.charAt(0)) { if ('(' == pattern.charAt(0)) {
String lists = pattern.substring(1, pattern.length()-1); String list = pattern.substring(1, pattern.length()-1);
return lists.split("\\s+"); return list;
} }
return new String[] { pattern }; return pattern;
} }
public static boolean listHelper(Task task, ArrayList<String> tags) { public static boolean listHelper(Task task, ArrayList<String> tags) {
String inputText = task.getValue(Task.TITLE); String inputText = task.getValue(Task.TITLE);
@ -62,28 +55,20 @@ public class TitleParser {
Matcher m = tagPattern.matcher(inputText); Matcher m = tagPattern.matcher(inputText);
if(m.find()) { if(m.find()) {
result = true; result = true;
String[] splitTags = TitleParser.trimParenthesisAndSplit(m.group(2)); String tag = TitleParser.trimParenthesis(m.group(2));
if (splitTags != null) { String tagWithCase = tagService.getTagWithCase(tag);
for (String tag : splitTags) { if (!addedTags.contains(tagWithCase))
String tagWithCase = tagService.getTagWithCase(tag); tags.add(tagWithCase);
if (!addedTags.contains(tagWithCase)) addedTags.add(tagWithCase);
tags.add(tagWithCase);
addedTags.add(tagWithCase);
}
}
} else { } else {
m = contextPattern.matcher(inputText); m = contextPattern.matcher(inputText);
if(m.find()) { if(m.find()) {
result = true; result = true;
String[] splitTags = TitleParser.trimParenthesisAndSplit(m.group(2)); String tag = TitleParser.trimParenthesis(m.group(2));
if (splitTags != null) { String tagWithCase = tagService.getTagWithCase(tag);
for (String tag : splitTags) { if (!addedTags.contains(tagWithCase))
String tagWithCase = tagService.getTagWithCase(tag); tags.add(tagWithCase);
if (!addedTags.contains(tagWithCase)) addedTags.add(tagWithCase);
tags.add(tagWithCase);
addedTags.add(tagWithCase);
}
}
} else{ } else{
break; break;
} }
@ -379,7 +364,8 @@ public class TitleParser {
repeatTimesIntervalOne.put( "(?i)\\bmonthly\\b" ,Frequency.MONTHLY); repeatTimesIntervalOne.put( "(?i)\\bmonthly\\b" ,Frequency.MONTHLY);
repeatTimesIntervalOne.put( "(?i)\\byearly\\b" , Frequency.YEARLY); repeatTimesIntervalOne.put( "(?i)\\byearly\\b" , Frequency.YEARLY);
for (String repeatTime:repeatTimes.keySet()){ Set<String> keys = repeatTimes.keySet();
for (String repeatTime : keys){
Pattern pattern = Pattern.compile(repeatTime); Pattern pattern = Pattern.compile(repeatTime);
Matcher m = pattern.matcher(inputText); Matcher m = pattern.matcher(inputText);
if (m.find()){ if (m.find()){

@ -3,7 +3,7 @@
* *
* See the file "LICENSE" for the full license governing this code. * See the file "LICENSE" for the full license governing this code.
*/ */
package com.todoroo.andlib.utility; package com.todoroo.astrid.service;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,6 +13,7 @@ import java.util.Date;
import com.google.ical.values.Frequency; import com.google.ical.values.Frequency;
import com.google.ical.values.RRule; import com.google.ical.values.RRule;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
@ -542,15 +543,13 @@ public class TitleParserTest extends DatabaseTestCase {
"#(cool)" "#(cool)"
}; };
Task task = new Task(); Task task = new Task();
for (String acceptedString:acceptedStrings){ for (String acceptedString : acceptedStrings) {
task = new Task(); task = new Task();
task.setValue(Task.TITLE, "Jog " + acceptedString); //test at end of task. should set importance. task.setValue(Task.TITLE, "Jog " + acceptedString); //test at end of task. should set importance.
ArrayList<String> tags = new ArrayList<String>(); ArrayList<String> tags = new ArrayList<String>();
TitleParser.listHelper(task, tags); TitleParser.listHelper(task, tags);
String[] splitTags = TitleParser.trimParenthesisAndSplit(acceptedString); String tag = TitleParser.trimParenthesis(acceptedString);
for (String tag : splitTags) { assertTrue("test pound at failed for string: " + acceptedString + " for tags: " + tags.toString(), tags.contains(tag));
assertTrue("test pound at failed for string: " + acceptedString + " for tags: " + tags.toString(),tags.contains(tag));
}
} }
} }
@ -563,15 +562,13 @@ public class TitleParserTest extends DatabaseTestCase {
"@(cool)" "@(cool)"
}; };
Task task = new Task(); Task task = new Task();
for (String acceptedString:acceptedStrings){ for (String acceptedString : acceptedStrings) {
task = new Task(); task = new Task();
task.setValue(Task.TITLE, "Jog " + acceptedString); //test at end of task. should set importance. task.setValue(Task.TITLE, "Jog " + acceptedString); //test at end of task. should set importance.
ArrayList<String> tags = new ArrayList<String>(); ArrayList<String> tags = new ArrayList<String>();
TitleParser.listHelper(task, tags); TitleParser.listHelper(task, tags);
String[] splitTags = TitleParser.trimParenthesisAndSplit(acceptedString); String tag = TitleParser.trimParenthesis(acceptedString);
for (String tag : splitTags) { assertTrue("testTagsAt failed for string: " + acceptedString+ " for tags: " + tags.toString(), tags.contains(tag));
assertTrue("testTagsAt failed for string: " + acceptedString+ " for tags: " + tags.toString(), tags.contains(tag));
}
} }
} }
Loading…
Cancel
Save