| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 class _Platform { | 7 class _Platform { |
| 8 external static int _numberOfProcessors(); | 8 external static int _numberOfProcessors(); |
| 9 external static String _pathSeparator(); | 9 external static String _pathSeparator(); |
| 10 external static String _operatingSystem(); | 10 external static String _operatingSystem(); |
| 11 external static _localHostname(); | 11 external static _localHostname(); |
| 12 external static _executable(); | 12 external static _executable(); |
| 13 external static _environment(); | 13 external static _environment(); |
| 14 external static List<String> _executableArguments(); | 14 external static List<String> _executableArguments(); |
| 15 external static String _packageRoot(); | 15 external static String _packageRoot(); |
| 16 external static String _version(); | 16 external static String _version(); |
| 17 | 17 |
| 18 static String executable = _executable(); |
| 19 static String packageRoot = _packageRoot(); |
| 20 |
| 18 // Cache the OS environemnt. This can be an OSError instance if | 21 // Cache the OS environemnt. This can be an OSError instance if |
| 19 // retrieving the environment failed. | 22 // retrieving the environment failed. |
| 20 static var _environmentCache; | 23 static var _environmentCache; |
| 21 | 24 |
| 22 static int get numberOfProcessors => _numberOfProcessors(); | 25 static int get numberOfProcessors => _numberOfProcessors(); |
| 23 static String get pathSeparator => _pathSeparator(); | 26 static String get pathSeparator => _pathSeparator(); |
| 24 static String get operatingSystem => _operatingSystem(); | 27 static String get operatingSystem => _operatingSystem(); |
| 25 static Uri script = _script(); | 28 static Uri script = _script(); |
| 26 static Uri _script() { | 29 static Uri _script() { |
| 27 // The embedder (Dart executable) creates the Platform._nativeScript field. | 30 // The embedder (Dart executable) creates the Platform._nativeScript field. |
| 28 var s = Platform._nativeScript; | 31 var s = Platform._nativeScript; |
| 29 if (s.startsWith('http:') || | 32 if (s.startsWith('http:') || |
| 30 s.startsWith('https:') || | 33 s.startsWith('https:') || |
| 31 s.startsWith('file:')) { | 34 s.startsWith('file:')) { |
| 32 return Uri.parse(s); | 35 return Uri.parse(s); |
| 33 } else { | 36 } else { |
| 34 return Uri.base.resolveUri(new Uri.file(s)); | 37 return Uri.base.resolveUri(new Uri.file(s)); |
| 35 } | 38 } |
| 36 } | 39 } |
| 37 | 40 |
| 38 static String get localHostname { | 41 static String get localHostname { |
| 39 var result = _localHostname(); | 42 var result = _localHostname(); |
| 40 if (result is OSError) { | 43 if (result is OSError) { |
| 41 throw result; | 44 throw result; |
| 42 } else { | 45 } else { |
| 43 return result; | 46 return result; |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 static String executable = _executable(); | |
| 48 static String packageRoot = _packageRoot(); | |
| 49 static List<String> get executableArguments => _executableArguments(); | 50 static List<String> get executableArguments => _executableArguments(); |
| 50 | 51 |
| 51 static Map<String, String> get environment { | 52 static Map<String, String> get environment { |
| 52 if (_environmentCache == null) { | 53 if (_environmentCache == null) { |
| 53 var env = _environment(); | 54 var env = _environment(); |
| 54 if (env is !OSError) { | 55 if (env is !OSError) { |
| 55 var isWindows = operatingSystem == 'windows'; | 56 var isWindows = operatingSystem == 'windows'; |
| 56 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); | 57 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
| 57 for (var str in env) { | 58 for (var str in env) { |
| 58 // When running on Windows through cmd.exe there are strange | 59 // When running on Windows through cmd.exe there are strange |
| (...skipping 23 matching lines...) Expand all Loading... |
| 82 return _environmentCache; | 83 return _environmentCache; |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 static String get version => _version(); | 87 static String get version => _version(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Environment variables are case-insensitive on Windows. In order | 90 // Environment variables are case-insensitive on Windows. In order |
| 90 // to reflect that we use a case-insensitive string map on Windows. | 91 // to reflect that we use a case-insensitive string map on Windows. |
| 91 class _CaseInsensitiveStringMap<V> implements Map<String, V> { | 92 class _CaseInsensitiveStringMap<V> implements Map<String, V> { |
| 93 Map<String, V> _map; |
| 94 |
| 92 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); | 95 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); |
| 93 | 96 |
| 94 _CaseInsensitiveStringMap.from(Map<String, V> other) | 97 _CaseInsensitiveStringMap.from(Map<String, V> other) |
| 95 : _map = new Map<String, V>() { | 98 : _map = new Map<String, V>() { |
| 96 other.forEach((String key, V value) { | 99 other.forEach((String key, V value) { |
| 97 _map[key.toUpperCase()] = value; | 100 _map[key.toUpperCase()] = value; |
| 98 }); | 101 }); |
| 99 } | 102 } |
| 100 | 103 |
| 101 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); | 104 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); |
| 102 bool containsValue(Object value) => _map.containsValue(value); | 105 bool containsValue(Object value) => _map.containsValue(value); |
| 103 V operator [](String key) => _map[key.toUpperCase()]; | 106 V operator [](String key) => _map[key.toUpperCase()]; |
| 104 void operator []=(String key, V value) { | 107 void operator []=(String key, V value) { |
| 105 _map[key.toUpperCase()] = value; | 108 _map[key.toUpperCase()] = value; |
| 106 } | 109 } |
| 107 V putIfAbsent(String key, V ifAbsent()) { | 110 V putIfAbsent(String key, V ifAbsent()) { |
| 108 _map.putIfAbsent(key.toUpperCase(), ifAbsent); | 111 _map.putIfAbsent(key.toUpperCase(), ifAbsent); |
| 109 } | 112 } |
| 110 addAll(Map other) { | 113 addAll(Map other) { |
| 111 other.forEach((key, value) => this[key.toUpperCase()] = value); | 114 other.forEach((key, value) => this[key.toUpperCase()] = value); |
| 112 } | 115 } |
| 113 V remove(String key) => _map.remove(key.toUpperCase()); | 116 V remove(String key) => _map.remove(key.toUpperCase()); |
| 114 void clear() => _map.clear(); | 117 void clear() => _map.clear(); |
| 115 void forEach(void f(String key, V value)) => _map.forEach(f); | 118 void forEach(void f(String key, V value)) => _map.forEach(f); |
| 116 Iterable<String> get keys => _map.keys; | 119 Iterable<String> get keys => _map.keys; |
| 117 Iterable<V> get values => _map.values; | 120 Iterable<V> get values => _map.values; |
| 118 int get length => _map.length; | 121 int get length => _map.length; |
| 119 bool get isEmpty => _map.isEmpty; | 122 bool get isEmpty => _map.isEmpty; |
| 120 bool get isNotEmpty => _map.isNotEmpty; | 123 bool get isNotEmpty => _map.isNotEmpty; |
| 121 | |
| 122 Map<String, V> _map; | |
| 123 } | 124 } |
| OLD | NEW |