diff src/goodjava/bbcode/BBCode.java @ 1712:36c28be6d432

improve html and bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Jul 2022 22:14:21 -0600
parents 05d14db623b6
children 31a82b0d0a87
line wrap: on
line diff
--- a/src/goodjava/bbcode/BBCode.java	Wed Jul 13 21:50:41 2022 -0600
+++ b/src/goodjava/bbcode/BBCode.java	Thu Jul 14 22:14:21 2022 -0600
@@ -11,6 +11,15 @@
 
 public final class BBCode {
 
+	private static final Pattern tagPtn = Pattern.compile(
+		"\\[(/?[a-zA-Z]+(=[^ \\n\\t\\[\\]]*)?)\\]"
+	);
+
+	public static String encode(String s) {
+		return tagPtn.matcher(s).replaceAll("[brackets]$1[/brackets]");
+	}
+
+
 	public final class Element {
 		public final String name;
 		public final String param;
@@ -216,7 +225,7 @@
 		parser.matchIgnoreCase("s");
 		if( !parser.matchIgnoreCase("://") )
 			return parser.failure(null);
-		while( parser.noneOf(" []'") );
+		while( parser.noneOf(" \n\t[]") );
 		String url = parser.textFrom(start);
 		while( parser.match(' ') );
 		return parser.success(url);
@@ -233,7 +242,7 @@
 			end = "[/code]";
 		} else if( parser.match('=') ) {
 			int start = parser.currentIndex();
-			while( parser.noneOf("[]") );
+			while( parser.noneOf("[]\n") );
 			param = parser.textFrom(start);
 			if( !parser.match(']') )
 				return parser.failure(null);
@@ -347,8 +356,8 @@
 			name = null;
 		} else if( parser.match('=') ) {
 			int start = parser.currentIndex();
-			while( parser.noneOf("[]") );
-			name = parser.textFrom(start).trim();
+			while( parser.noneOf("[]\n") );
+			name = parser.textFrom(start);
 			if( !parser.match(']') )
 				return parser.failure(null);
 		} else