| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library fasta.util.relativize; | 5 library fasta.util.relativize; |
| 6 | 6 |
| 7 // TODO(ahe): Move more advanced version from dart2js here. | 7 // TODO(ahe): Move more advanced version from dart2js here. |
| 8 | 8 |
| 9 String relativizeUri(Uri uri, {Uri base}) { | 9 String relativizeUri(Uri uri, {Uri base}) { |
| 10 if (uri == null) return null; | 10 if (uri == null) return null; |
| 11 base ??= Uri.base; | 11 base ??= Uri.base; |
| 12 String result = "$uri"; | 12 String result = "$uri"; |
| 13 return result.startsWith("$base") ? result.substring("$base".length) : result; | 13 final prefix = "$base"; |
| 14 return result.startsWith(prefix) ? result.substring(prefix.length) : result; |
| 14 } | 15 } |
| OLD | NEW |