ソースを参照

Fixing bug in handling of literal '{' and '}' in format string.

Sam Jaffe 8 年 前
コミット
a709a18732
1 ファイル変更6 行追加3 行削除
  1. 6 3
      src/org/leumasjaffe/format/StringFormatter.java

+ 6 - 3
src/org/leumasjaffe/format/StringFormatter.java

@@ -39,19 +39,22 @@ public class StringFormatter {
 		FmtStateMachine formatMain() {
 			int lpos = 0;
 			for (int pos = fmt.indexOf('{'); pos != -1; lpos = pos+1, pos = fmt.indexOf('{', lpos)) {
-				str.append(fmt.substring(lpos, pos));
+				str.append(fmt.substring(lpos, pos).replaceAll("}}", "}"));
 				int epos = fmt.indexOf('}', pos);
 
 				if (fmt.charAt(pos+1) == '{') { 
-					str.append(fmt.substring(++pos, ++epos));
+					// Literal '{'
+					str.append('{');
+					epos = pos + 1;
 				} else if (epos == pos+1) {
+					// Unmarked '{}' -> get the next argument
 					str.append(args[currentIdx++]);
 				} else {
 					formatToken(pos, epos);
 				}
 				pos = epos;
 			}
-			str.append(fmt.substring(lpos));
+			str.append(fmt.substring(lpos).replaceAll("}}", "}"));
 			return this;
 		}