| OLD | NEW |
| 1 library java.engine; | 1 library java.engine; |
| 2 | 2 |
| 3 import 'java_core.dart'; | 3 import 'java_core.dart'; |
| 4 | 4 |
| 5 class StringUtilities { | 5 class StringUtilities { |
| 6 static const String EMPTY = ''; | 6 static const String EMPTY = ''; |
| 7 static const List<String> EMPTY_ARRAY = const <String> []; | 7 static const List<String> EMPTY_ARRAY = const <String> []; |
| 8 static String intern(String s) => s; | 8 static String intern(String s) => s; |
| 9 static bool isTagName(String s) { | 9 static bool isTagName(String s) { |
| 10 if (s == null || s.length == 0) { | 10 if (s == null || s.length == 0) { |
| 11 return false; | 11 return false; |
| 12 } | 12 } |
| 13 int sz = s.length; | 13 int sz = s.length; |
| 14 for (int i = 0; i < sz; i++) { | 14 for (int i = 0; i < sz; i++) { |
| 15 int c = s.codeUnitAt(i); | 15 int c = s.codeUnitAt(i); |
| 16 if (!Character.isLetter(c)) { | 16 if (!Character.isLetter(c)) { |
| 17 if (i == 0) { | 17 if (i == 0) { |
| 18 return false; | 18 return false; |
| 19 } | 19 } |
| 20 if (!Character.isDigit(c) && c != 0x2D) { | 20 if (!Character.isDigit(c) && c != 0x2D) { |
| 21 return false; | 21 return false; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 return true; | 25 return true; |
| 26 } | 26 } |
| 27 static bool isEmpty(String s) { |
| 28 return s == null || s.isEmpty; |
| 29 } |
| 27 static String substringBefore(String str, String separator) { | 30 static String substringBefore(String str, String separator) { |
| 28 if (str == null || str.isEmpty) { | 31 if (str == null || str.isEmpty) { |
| 29 return str; | 32 return str; |
| 30 } | 33 } |
| 31 int pos = str.indexOf(separator); | 34 int pos = str.indexOf(separator); |
| 32 if (pos < 0) { | 35 if (pos < 0) { |
| 33 return str; | 36 return str; |
| 34 } | 37 } |
| 35 return str.substring(0, pos); | 38 return str.substring(0, pos); |
| 36 } | 39 } |
| 40 static endsWithChar(String str, int c) { |
| 41 int length = str.length; |
| 42 return length > 0 && str.codeUnitAt(length - 1) == c; |
| 43 } |
| 44 static endsWith3(String str, int c1, int c2, int c3) { |
| 45 var length = str.length; |
| 46 return length >= 3 && |
| 47 str.codeUnitAt(length - 3) == c1 && |
| 48 str.codeUnitAt(length - 2) == c2 && |
| 49 str.codeUnitAt(length - 1) == c3; |
| 50 } |
| 51 |
| 52 static startsWithChar(String str, int c) { |
| 53 return str.length != 0 && str.codeUnitAt(0) == c; |
| 54 } |
| 55 static startsWith2(String str, int start, int c1, int c2) { |
| 56 return str.length - start >= 2 && |
| 57 str.codeUnitAt(start) == c1 && |
| 58 str.codeUnitAt(start + 1) == c2; |
| 59 } |
| 60 static startsWith3(String str, int start, int c1, int c2, int c3) { |
| 61 return str.length - start >= 3 && |
| 62 str.codeUnitAt(start) == c1 && |
| 63 str.codeUnitAt(start + 1) == c2 && |
| 64 str.codeUnitAt(start + 2) == c3; |
| 65 } |
| 66 static startsWith4(String str, int start, int c1, int c2, int c3, int c4) { |
| 67 return str.length - start >= 4 && |
| 68 str.codeUnitAt(start) == c1 && |
| 69 str.codeUnitAt(start + 1) == c2 && |
| 70 str.codeUnitAt(start + 2) == c3 && |
| 71 str.codeUnitAt(start + 3) == c4; |
| 72 } |
| 73 static startsWith5(String str, int start, int c1, int c2, int c3, int c4, |
| 74 int c5) { |
| 75 return str.length - start >= 5 && |
| 76 str.codeUnitAt(start) == c1 && |
| 77 str.codeUnitAt(start + 1) == c2 && |
| 78 str.codeUnitAt(start + 2) == c3 && |
| 79 str.codeUnitAt(start + 3) == c4 && |
| 80 str.codeUnitAt(start + 4) == c5; |
| 81 } |
| 82 static startsWith6(String str, int start, int c1, int c2, int c3, int c4, |
| 83 int c5, int c6) { |
| 84 return str.length - start >= 6 && |
| 85 str.codeUnitAt(start) == c1 && |
| 86 str.codeUnitAt(start + 1) == c2 && |
| 87 str.codeUnitAt(start + 2) == c3 && |
| 88 str.codeUnitAt(start + 3) == c4 && |
| 89 str.codeUnitAt(start + 4) == c5 && |
| 90 str.codeUnitAt(start + 5) == c6; |
| 91 } |
| 92 static int indexOf1(String str, int start, int c) { |
| 93 int index = start; |
| 94 int last = str.length; |
| 95 while (index < last) { |
| 96 if (str.codeUnitAt(index) == c) { |
| 97 return index; |
| 98 } |
| 99 index++; |
| 100 } |
| 101 return -1; |
| 102 } |
| 103 static int indexOf2(String str, int start, int c1, int c2) { |
| 104 int index = start; |
| 105 int last = str.length - 1; |
| 106 while (index < last) { |
| 107 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2) { |
| 108 return index; |
| 109 } |
| 110 index++; |
| 111 } |
| 112 return -1; |
| 113 } |
| 114 static int indexOf4(String string, int start, int c1, int c2, int c3, int c4)
{ |
| 115 int index = start; |
| 116 int last = string.length - 3; |
| 117 while (index < last) { |
| 118 if (string.codeUnitAt(index) == c1 && |
| 119 string.codeUnitAt(index + 1) == c2 && |
| 120 string.codeUnitAt(index + 2) == c3 && |
| 121 string.codeUnitAt(index + 3) == c4) { |
| 122 return index; |
| 123 } |
| 124 index++; |
| 125 } |
| 126 return -1; |
| 127 } |
| 128 static int indexOf5(String str, int start, int c1, int c2, int c3, int c4, |
| 129 int c5) { |
| 130 int index = start; |
| 131 int last = str.length - 4; |
| 132 while (index < last) { |
| 133 if (str.codeUnitAt(index) == c1 && |
| 134 str.codeUnitAt(index + 1) == c2 && |
| 135 str.codeUnitAt(index + 2) == c3 && |
| 136 str.codeUnitAt(index + 3) == c4 && |
| 137 str.codeUnitAt(index + 4) == c5) { |
| 138 return index; |
| 139 } |
| 140 index++; |
| 141 } |
| 142 return -1; |
| 143 } |
| 144 static String substringBeforeChar(String str, int c) { |
| 145 if (isEmpty(str)) { |
| 146 return str; |
| 147 } |
| 148 int pos = indexOf1(str, 0, c); |
| 149 if (pos < 0) { |
| 150 return str; |
| 151 } |
| 152 return str.substring(0, pos); |
| 153 } |
| 37 } | 154 } |
| 38 | 155 |
| 39 class FileNameUtilities { | 156 class FileNameUtilities { |
| 40 static String getExtension(String fileName) { | 157 static String getExtension(String fileName) { |
| 41 if (fileName == null) { | 158 if (fileName == null) { |
| 42 return ""; | 159 return ""; |
| 43 } | 160 } |
| 44 int index = fileName.lastIndexOf('.'); | 161 int index = fileName.lastIndexOf('.'); |
| 45 if (index >= 0) { | 162 if (index >= 0) { |
| 46 return fileName.substring(index + 1); | 163 return fileName.substring(index + 1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 static int combineHashCodes(int first, int second) => first * 31 + second; | 178 static int combineHashCodes(int first, int second) => first * 31 + second; |
| 62 } | 179 } |
| 63 | 180 |
| 64 class UUID { | 181 class UUID { |
| 65 static int __nextId = 0; | 182 static int __nextId = 0; |
| 66 final String id; | 183 final String id; |
| 67 UUID(this.id); | 184 UUID(this.id); |
| 68 String toString() => id; | 185 String toString() => id; |
| 69 static UUID randomUUID() => new UUID((__nextId).toString()); | 186 static UUID randomUUID() => new UUID((__nextId).toString()); |
| 70 } | 187 } |
| OLD | NEW |