| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library mojom.utils; | 5 library mojom.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:crypto/crypto.dart' as crypto; | 11 import 'package:crypto/crypto.dart' as crypto; |
| 12 import 'package:logging/logging.dart' as logging; | 12 import 'package:logging/logging.dart' as logging; |
| 13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
| 14 | 14 |
| 15 bool isMojomDart(String path) => path.endsWith('.mojom.dart'); | 15 bool isMojomDart(String path) => path.endsWith('.mojom.dart'); |
| 16 bool isMojom(String path) => path.endsWith('.mojom'); | 16 bool isMojom(String path) => path.endsWith('.mojom'); |
| 17 bool isDotMojoms(String path) => path.endsWith(".mojoms"); | 17 bool isDotMojoms(String path) => path.endsWith(".mojoms"); |
| 18 bool isPubspecYaml(String path) => path.endsWith("pubspec.yaml"); |
| 18 | 19 |
| 19 String makeAbsolute(String p) => | 20 String makeAbsolute(String p) => |
| 20 path.isAbsolute(p) ? path.normalize(p) : path.normalize(path.absolute(p)); | 21 path.isAbsolute(p) ? path.normalize(p) : path.normalize(path.absolute(p)); |
| 21 | 22 |
| 22 String makeRelative(String p) => path.isAbsolute(p) | 23 String makeRelative(String p) => path.isAbsolute(p) |
| 23 ? path.normalize(path.relative(p, from: Directory.current.path)) | 24 ? path.normalize(path.relative(p, from: Directory.current.path)) |
| 24 : path.normalize(p); | 25 : path.normalize(p); |
| 25 | 26 |
| 26 logging.Logger log; | 27 logging.Logger log; |
| 27 | 28 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return 0; | 128 return 0; |
| 128 } | 129 } |
| 129 | 130 |
| 130 /// Is any element of [haystack] a prefix of [needle]? | 131 /// Is any element of [haystack] a prefix of [needle]? |
| 131 bool containsPrefix(String needle, List<String> haystack) { | 132 bool containsPrefix(String needle, List<String> haystack) { |
| 132 if (haystack == null) return false; | 133 if (haystack == null) return false; |
| 133 var match = | 134 var match = |
| 134 haystack.firstWhere((p) => needle.startsWith(p), orElse: () => null); | 135 haystack.firstWhere((p) => needle.startsWith(p), orElse: () => null); |
| 135 return match != null; | 136 return match != null; |
| 136 } | 137 } |
| OLD | NEW |