| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class HtmlUtils { | |
| 6 | |
| 7 // Strips the 'px' (pixels) suffix from a string CSS value and parses the | |
| 8 // result as an integer. | |
| 9 static int fromPx(String px) => Math.parseInt(px.substring(0, px.length - 2)); | |
| 10 | |
| 11 // Workaround until String.replaceAll is functional | |
| 12 static String quoteHtml(String s) { | |
| 13 StringBuffer sb = new StringBuffer(); | |
| 14 int last = 0; | |
| 15 for (int i = 0; i < s.length; i++) { | |
| 16 switch (s[i]) { | |
| 17 case "<": | |
| 18 sb.add(s.substring(last, i)); | |
| 19 sb.add("<"); | |
| 20 last = i + 1; | |
| 21 break; | |
| 22 case ">": | |
| 23 sb.add(s.substring(last, i)); | |
| 24 sb.add(">"); | |
| 25 last = i + 1; | |
| 26 break; | |
| 27 case "&": | |
| 28 sb.add(s.substring(last, i)); | |
| 29 sb.add("&"); | |
| 30 last = i + 1; | |
| 31 break; | |
| 32 case "\"": | |
| 33 sb.add(s.substring(last, i)); | |
| 34 sb.add("""); | |
| 35 last = i + 1; | |
| 36 break; | |
| 37 } | |
| 38 } | |
| 39 sb.add(s.substring(last, s.length)); | |
| 40 return sb.toString(); | |
| 41 } | |
| 42 | |
| 43 static void setIntegerProperty(Element element, String property, int value, St
ring units) { | |
| 44 element.style.setProperty(property, "${value}${units}", ""); | |
| 45 } | |
| 46 | |
| 47 // Appends 'px' (pixels) to an integer for use in CSS values. | |
| 48 static String toPx(int length) => "${length}px"; | |
| 49 } | |
| OLD | NEW |