Skip to content

Commit

Permalink
Merge remote branch 'johnogle/misc-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
matburt committed Jan 10, 2011
2 parents 37cc2d7 + f3bf6e9 commit fdc28de
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/com/matburt/mobileorg/OrgFileParser.java
Expand Up @@ -25,7 +25,7 @@
class OrgFileParser {

class TitleComponents {
String title;
String title = "";
String todo = "";
String priority = "";
ArrayList<String> tags = new ArrayList<String>();
Expand All @@ -38,6 +38,7 @@ class TitleComponents {
FileInputStream fstream;
Node rootNode = new Node("", Node.HEADING);
MobileOrgDatabase appdb;
ArrayList<HashMap<String, Integer>> todos = null;
public static final String LT = "MobileOrg";
public String orgDir = "/sdcard/mobileorg/";

Expand All @@ -49,7 +50,6 @@ class TitleComponents {
this.storageMode = storageMode;
this.orgPaths = orgpaths;
this.orgDir = orgBasePath;

}

private Pattern prepareTitlePattern() {
Expand All @@ -63,22 +63,35 @@ private Pattern prepareTitlePattern() {
}
return this.titlePattern;
}

private boolean isValidTodo(String todo) {
for(HashMap<String, Integer> aTodo : this.todos) {
if(aTodo.containsKey(todo)) return true;
}
return false;
}

private TitleComponents parseTitle (String orgTitle) {
TitleComponents component = new TitleComponents();
String title = orgTitle.trim();
Pattern pattern = prepareTitlePattern();
Matcher m = pattern.matcher(title);
if (m.find()) {
if (m.group(1) != null)
component.todo = m.group(1).trim();
if (m.group(1) != null) {
String todo = m.group(1).trim();
if(todo.length() > 0 && isValidTodo(todo)) {
component.todo = todo;
} else {
component.title = todo + " ";
}
}
if (m.group(2) != null) {
component.priority = m.group(2);
component.priority = component.priority.replace("#", "");
component.priority = component.priority.replace("[", "");
component.priority = component.priority.replace("]", "");
}
component.title = m.group(3);
component.title += m.group(3);
String tags = m.group(4);
if (tags != null) {
for (String tag : tags.split(":")) {
Expand Down Expand Up @@ -139,6 +152,8 @@ public void parse(Node fileNode, BufferedReader breader)
{
try
{
this.todos = appdb.getTodos();

String thisLine;
Stack<Node> nodeStack = new Stack();
Pattern propertiesLine = Pattern.compile("^\\s*:[A-Z]+:");
Expand Down

0 comments on commit fdc28de

Please sign in to comment.