Mercurial Hosting > luan
view src/goodjava/html/Css.java @ 1742:d778f1f2598a
make server side events proxy work
author | Vadim Filimonov <fffilimonov@yandex.ru> |
---|---|
date | Tue, 08 Nov 2022 09:32:46 +0200 |
parents | 31a82b0d0a87 |
children |
line wrap: on
line source
package goodjava.html; import java.util.Map; import java.util.LinkedHashMap; import goodjava.parser.Parser; public final class Css { public static Map<String,String> style(String text) { return new Css(text).parseStyle(); } private final Parser parser; private Css(String text) { this.parser = new Parser(text); } private Map<String,String> parseStyle() { Map<String,String> map = new LinkedHashMap<String,String>(); while( matchSpace() ); while( !parser.endOfInput() ) { int start = parser.currentIndex(); if( !matchPropertyChar() ) return null; while( matchPropertyChar() ); String prop = parser.textFrom(start).toLowerCase(); while( matchSpace() ); if( !parser.match(':') ) return null; start = parser.currentIndex(); while( !parser.endOfInput() && parser.noneOf(";") ); String val = parser.textFrom(start).trim(); map.put(prop,val); parser.match(';'); while( matchSpace() ); } return map; } private boolean matchPropertyChar() { return parser.inCharRange('a','z') || parser.inCharRange('A','Z') || parser.inCharRange('0','9') || parser.anyOf("_-") ; } private boolean matchSpace() { return parser.anyOf(" \t\r\n"); } }