Mercurial Hosting > luan
comparison src/goodjava/html/Css.java @ 1714:31a82b0d0a87
bbcode and html work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jul 2022 23:49:47 -0600 |
parents | src/luan/modules/parsers/Css.java@b89212fd04b5 |
children |
comparison
equal
deleted
inserted
replaced
1713:4d70e9543ef2 | 1714:31a82b0d0a87 |
---|---|
1 package goodjava.html; | |
2 | |
3 import java.util.Map; | |
4 import java.util.LinkedHashMap; | |
5 import goodjava.parser.Parser; | |
6 | |
7 | |
8 public final class Css { | |
9 | |
10 public static Map<String,String> style(String text) { | |
11 return new Css(text).parseStyle(); | |
12 } | |
13 | |
14 private final Parser parser; | |
15 | |
16 private Css(String text) { | |
17 this.parser = new Parser(text); | |
18 } | |
19 | |
20 private Map<String,String> parseStyle() { | |
21 Map<String,String> map = new LinkedHashMap<String,String>(); | |
22 while( matchSpace() ); | |
23 while( !parser.endOfInput() ) { | |
24 int start = parser.currentIndex(); | |
25 if( !matchPropertyChar() ) | |
26 return null; | |
27 while( matchPropertyChar() ); | |
28 String prop = parser.textFrom(start).toLowerCase(); | |
29 | |
30 while( matchSpace() ); | |
31 if( !parser.match(':') ) | |
32 return null; | |
33 | |
34 start = parser.currentIndex(); | |
35 while( !parser.endOfInput() && parser.noneOf(";") ); | |
36 String val = parser.textFrom(start).trim(); | |
37 | |
38 map.put(prop,val); | |
39 parser.match(';'); | |
40 while( matchSpace() ); | |
41 } | |
42 return map; | |
43 } | |
44 | |
45 private boolean matchPropertyChar() { | |
46 return parser.inCharRange('a','z') | |
47 || parser.inCharRange('A','Z') | |
48 || parser.inCharRange('0','9') | |
49 || parser.anyOf("_-") | |
50 ; | |
51 } | |
52 | |
53 private boolean matchSpace() { | |
54 return parser.anyOf(" \t\r\n"); | |
55 } | |
56 | |
57 } |