Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/main/java/org/codejive/properties/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,22 +617,35 @@ private List<Integer> findPropertyCommentLines(Cursor pos) {
return Collections.unmodifiableList(result);
}

private Cursor indexOf(String key) {
/**
* @param key the key of the property whose token is searched.
* @return a Cursor pointing to the {@link PropertiesParser.Type#KEY} token of the property.
* <br/> Or a Cursor pointing to {@code -1} if no such property exists.
*/
public Cursor indexOf(String key) {
return index(
tokens.indexOf(
new PropertiesParser.Token(
PropertiesParser.Type.KEY, escapeKey(key), key)));
}

private static String escapeValue(String value) {
/**
* @param value the value to escape
* @return the value, escaped such that it can be stored in a .properties file
*/
public static String escapeValue(String value) {
return value.replace("\\", "\\\\")
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
.replace("\f", "\\f");
}

private static String escapeKey(String key) {
/**
* @param key the key to escape
* @return the key, escaped such that it can be stored in a .properties file
*/
public static String escapeKey(String key) {
return escapeValue(key).replace(" ", "\\ ");
}

Expand Down Expand Up @@ -997,11 +1010,17 @@ Cursor index(int index) {
return Cursor.index(tokens, index);
}

Cursor first() {
/**
* @return a Cursor pointing to the first token, or to {@code -1} if no tokens have been loaded.
*/
public Cursor first() {
return Cursor.first(tokens);
}

Cursor last() {
/**
* @return a Cursor pointing to the last token, or to {@code -1} if no tokens have been loaded.
*/
public Cursor last() {
return Cursor.last(tokens);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/codejive/properties/PropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* input which makes it possible to exactly recreate the original, including all whitespace and
* comments.
*/
class PropertiesParser {
public class PropertiesParser {

/** The type of token. */
public enum Type {
Expand Down Expand Up @@ -59,7 +59,7 @@ public static class Token {
* @param type The token's type
* @param raw The token's value
*/
Token(Type type, String raw) {
public Token(Type type, String raw) {
this(type, raw, null);
}

Expand All @@ -71,7 +71,7 @@ public static class Token {
* @param raw The token's raw value (including escape sequences)
* @param text The token's processed value (no escape sequences)
*/
Token(Type type, String raw, String text) {
public Token(Type type, String raw, String text) {
this.type = type;
this.raw = raw;
if (raw.equals(text)) {
Expand Down Expand Up @@ -310,7 +310,7 @@ private String string() {
* @param escape Input string
* @return Decoded string
*/
static String unescape(String escape) {
public static String unescape(String escape) {
StringBuilder txt = new StringBuilder();
for (int i = 0; i < escape.length(); i++) {
char ch = escape.charAt(i);
Expand Down Expand Up @@ -358,7 +358,7 @@ && isWhitespaceChar(ch = escape.charAt(i + 1))) {
return txt.toString();
}

private static boolean isSeparatorChar(int ch) {
public static boolean isSeparatorChar(int ch) {
return ch == '=' || ch == ':';
}

Expand All @@ -370,7 +370,7 @@ private static boolean isWhitespaceEolChar(int ch) {
return isWhitespaceChar(ch) || isEol(ch);
}

private static boolean isCommentChar(int ch) {
public static boolean isCommentChar(int ch) {
return ch == '#' || ch == '!';
}

Expand Down
Loading