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(); |
(...skipping 23 matching lines...) Expand all Loading... |
34 external static String _packageConfig(); | 34 external static String _packageConfig(); |
35 external static String _version(); | 35 external static String _version(); |
36 | 36 |
37 static String executable = _executable(); | 37 static String executable = _executable(); |
38 static String resolvedExecutable = _resolvedExecutable(); | 38 static String resolvedExecutable = _resolvedExecutable(); |
39 static String packageRoot = _packageRoot(); | 39 static String packageRoot = _packageRoot(); |
40 static String packageConfig = _packageConfig(); | 40 static String packageConfig = _packageConfig(); |
41 | 41 |
42 // Cache the OS environment. This can be an OSError instance if | 42 // Cache the OS environment. This can be an OSError instance if |
43 // retrieving the environment failed. | 43 // retrieving the environment failed. |
44 static var/*OSError|Map<String,String>*/ _environmentCache; | 44 static var /*OSError|Map<String,String>*/ _environmentCache; |
45 | 45 |
46 static int get numberOfProcessors => _numberOfProcessors(); | 46 static int get numberOfProcessors => _numberOfProcessors(); |
47 static String get pathSeparator => _pathSeparator(); | 47 static String get pathSeparator => _pathSeparator(); |
48 static String get operatingSystem => _operatingSystem(); | 48 static String get operatingSystem => _operatingSystem(); |
49 static bool get ansiSupported => _ansiSupported(); | 49 static bool get ansiSupported => _ansiSupported(); |
50 static Uri script; | 50 static Uri script; |
51 | 51 |
52 static String get localHostname { | 52 static String get localHostname { |
53 var result = _localHostname(); | 53 var result = _localHostname(); |
54 if (result is OSError) { | 54 if (result is OSError) { |
55 throw result; | 55 throw result; |
56 } else { | 56 } else { |
57 return result; | 57 return result; |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 static List<String> get executableArguments => _executableArguments(); | 61 static List<String> get executableArguments => _executableArguments(); |
62 | 62 |
63 static Map<String, String> get environment { | 63 static Map<String, String> get environment { |
64 if (_environmentCache == null) { | 64 if (_environmentCache == null) { |
65 var env = _environment(); | 65 var env = _environment(); |
66 if (env is !OSError) { | 66 if (env is! OSError) { |
67 var isWindows = operatingSystem == 'windows'; | 67 var isWindows = operatingSystem == 'windows'; |
68 var result = isWindows | 68 var result = isWindows |
69 ? new _CaseInsensitiveStringMap<String>() | 69 ? new _CaseInsensitiveStringMap<String>() |
70 : new Map<String, String>(); | 70 : new Map<String, String>(); |
71 for (var str in env) { | 71 for (var str in env) { |
72 if (str == null) { | 72 if (str == null) { |
73 continue; | 73 continue; |
74 } | 74 } |
75 // The Strings returned by [_environment()] are expected to be | 75 // The Strings returned by [_environment()] are expected to be |
76 // valid environment entries, but exceptions have been seen | 76 // valid environment entries, but exceptions have been seen |
(...skipping 27 matching lines...) Expand all Loading... |
104 class _CaseInsensitiveStringMap<V> implements Map<String, V> { | 104 class _CaseInsensitiveStringMap<V> implements Map<String, V> { |
105 final Map<String, V> _map = new Map<String, V>(); | 105 final Map<String, V> _map = new Map<String, V>(); |
106 | 106 |
107 bool containsKey(Object key) => | 107 bool containsKey(Object key) => |
108 key is String && _map.containsKey(key.toUpperCase()); | 108 key is String && _map.containsKey(key.toUpperCase()); |
109 bool containsValue(Object value) => _map.containsValue(value); | 109 bool containsValue(Object value) => _map.containsValue(value); |
110 V operator [](Object key) => key is String ? _map[key.toUpperCase()] : null; | 110 V operator [](Object key) => key is String ? _map[key.toUpperCase()] : null; |
111 void operator []=(String key, V value) { | 111 void operator []=(String key, V value) { |
112 _map[key.toUpperCase()] = value; | 112 _map[key.toUpperCase()] = value; |
113 } | 113 } |
| 114 |
114 V putIfAbsent(String key, V ifAbsent()) { | 115 V putIfAbsent(String key, V ifAbsent()) { |
115 return _map.putIfAbsent(key.toUpperCase(), ifAbsent); | 116 return _map.putIfAbsent(key.toUpperCase(), ifAbsent); |
116 } | 117 } |
| 118 |
117 void addAll(Map<String, V> other) { | 119 void addAll(Map<String, V> other) { |
118 other.forEach((key, value) => this[key.toUpperCase()] = value); | 120 other.forEach((key, value) => this[key.toUpperCase()] = value); |
119 } | 121 } |
| 122 |
120 V remove(Object key) => key is String ? _map.remove(key.toUpperCase()) : null; | 123 V remove(Object key) => key is String ? _map.remove(key.toUpperCase()) : null; |
121 void clear() { _map.clear(); } | 124 void clear() { |
122 void forEach(void f(String key, V value)) { _map.forEach(f); } | 125 _map.clear(); |
| 126 } |
| 127 |
| 128 void forEach(void f(String key, V value)) { |
| 129 _map.forEach(f); |
| 130 } |
| 131 |
123 Iterable<String> get keys => _map.keys; | 132 Iterable<String> get keys => _map.keys; |
124 Iterable<V> get values => _map.values; | 133 Iterable<V> get values => _map.values; |
125 int get length => _map.length; | 134 int get length => _map.length; |
126 bool get isEmpty => _map.isEmpty; | 135 bool get isEmpty => _map.isEmpty; |
127 bool get isNotEmpty => _map.isNotEmpty; | 136 bool get isNotEmpty => _map.isNotEmpty; |
128 String toString() => _map.toString(); | 137 String toString() => _map.toString(); |
129 } | 138 } |
OLD | NEW |