diff --git a/src/main/java/com/orgzly/org/OrgProperties.java b/src/main/java/com/orgzly/org/OrgProperties.java index fbdfe58..ec0dbdf 100644 --- a/src/main/java/com/orgzly/org/OrgProperties.java +++ b/src/main/java/com/orgzly/org/OrgProperties.java @@ -2,10 +2,9 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.regex.Matcher; /** * a @@ -152,4 +151,23 @@ public boolean isEmpty() { public boolean containsKey(String name) { return values.containsKey(name); } + + public static OrgProperties fromString(String preface) { + OrgProperties properties = new OrgProperties(); + boolean inProperties = false; + for (String line : preface.split("\n")) { + String lineTrimmed = line.trim(); + if (!inProperties && ":PROPERTIES:".equals(lineTrimmed)) { + inProperties = true; + } else if (inProperties && ":END:".equals(lineTrimmed)) { + inProperties = false; + } else if (inProperties) { + Matcher propertyMatcher = OrgPatterns.PROPERTY.matcher(lineTrimmed); + if (propertyMatcher.find()) { + properties.put(propertyMatcher.group(1), propertyMatcher.group(2).trim()); + } + } + } + return properties; + } }