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

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