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 static int get numberOfProcessors => _numberOfProcessors(); | 21 static int get numberOfProcessors => _numberOfProcessors(); |
19 static String get pathSeparator => _pathSeparator(); | 22 static String get pathSeparator => _pathSeparator(); |
20 static String get operatingSystem => _operatingSystem(); | 23 static String get operatingSystem => _operatingSystem(); |
21 static Uri script = _script(); | 24 static Uri script = _script(); |
22 static Uri _script() { | 25 static Uri _script() { |
23 // The embedder (Dart executable) creates the Platform._nativeScript field. | 26 // The embedder (Dart executable) creates the Platform._nativeScript field. |
24 var s = Platform._nativeScript; | 27 var s = Platform._nativeScript; |
25 if (s.startsWith('http:') || | 28 if (s.startsWith('http:') || |
26 s.startsWith('https:') || | 29 s.startsWith('https:') || |
27 s.startsWith('file:')) { | 30 s.startsWith('file:')) { |
28 return Uri.parse(s); | 31 return Uri.parse(s); |
29 } else { | 32 } else { |
30 return Uri.base.resolveUri(new Uri.file(s)); | 33 return Uri.base.resolveUri(new Uri.file(s)); |
31 } | 34 } |
32 } | 35 } |
33 | 36 |
34 static String get localHostname { | 37 static String get localHostname { |
35 var result = _localHostname(); | 38 var result = _localHostname(); |
36 if (result is OSError) { | 39 if (result is OSError) { |
37 throw result; | 40 throw result; |
38 } else { | 41 } else { |
39 return result; | 42 return result; |
40 } | 43 } |
41 } | 44 } |
42 | 45 |
43 static String executable = _executable(); | |
44 static String packageRoot = _packageRoot(); | |
45 static List<String> get executableArguments => _executableArguments(); | 46 static List<String> get executableArguments => _executableArguments(); |
46 | 47 |
47 static Map<String, String> get environment { | 48 static Map<String, String> get environment { |
48 var env = _environment(); | 49 var env = _environment(); |
49 if (env is OSError) { | 50 if (env is OSError) { |
50 throw env; | 51 throw env; |
51 } else { | 52 } else { |
52 var isWindows = operatingSystem == 'windows'; | 53 var isWindows = operatingSystem == 'windows'; |
53 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); | 54 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
54 for (var str in env) { | 55 for (var str in env) { |
(...skipping 14 matching lines...) Expand all Loading... |
69 return result; | 70 return result; |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
73 static String get version => _version(); | 74 static String get version => _version(); |
74 } | 75 } |
75 | 76 |
76 // Environment variables are case-insensitive on Windows. In order | 77 // Environment variables are case-insensitive on Windows. In order |
77 // to reflect that we use a case-insensitive string map on Windows. | 78 // to reflect that we use a case-insensitive string map on Windows. |
78 class _CaseInsensitiveStringMap<V> implements Map<String, V> { | 79 class _CaseInsensitiveStringMap<V> implements Map<String, V> { |
| 80 Map<String, V> _map; |
| 81 |
79 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); | 82 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); |
80 | 83 |
81 _CaseInsensitiveStringMap.from(Map<String, V> other) | 84 _CaseInsensitiveStringMap.from(Map<String, V> other) |
82 : _map = new Map<String, V>() { | 85 : _map = new Map<String, V>() { |
83 other.forEach((String key, V value) { | 86 other.forEach((String key, V value) { |
84 _map[key.toUpperCase()] = value; | 87 _map[key.toUpperCase()] = value; |
85 }); | 88 }); |
86 } | 89 } |
87 | 90 |
88 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); | 91 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); |
89 bool containsValue(Object value) => _map.containsValue(value); | 92 bool containsValue(Object value) => _map.containsValue(value); |
90 V operator [](String key) => _map[key.toUpperCase()]; | 93 V operator [](String key) => _map[key.toUpperCase()]; |
91 void operator []=(String key, V value) { | 94 void operator []=(String key, V value) { |
92 _map[key.toUpperCase()] = value; | 95 _map[key.toUpperCase()] = value; |
93 } | 96 } |
94 V putIfAbsent(String key, V ifAbsent()) { | 97 V putIfAbsent(String key, V ifAbsent()) { |
95 _map.putIfAbsent(key.toUpperCase(), ifAbsent); | 98 _map.putIfAbsent(key.toUpperCase(), ifAbsent); |
96 } | 99 } |
97 addAll(Map other) { | 100 addAll(Map other) { |
98 other.forEach((key, value) => this[key.toUpperCase()] = value); | 101 other.forEach((key, value) => this[key.toUpperCase()] = value); |
99 } | 102 } |
100 V remove(String key) => _map.remove(key.toUpperCase()); | 103 V remove(String key) => _map.remove(key.toUpperCase()); |
101 void clear() => _map.clear(); | 104 void clear() => _map.clear(); |
102 void forEach(void f(String key, V value)) => _map.forEach(f); | 105 void forEach(void f(String key, V value)) => _map.forEach(f); |
103 Iterable<String> get keys => _map.keys; | 106 Iterable<String> get keys => _map.keys; |
104 Iterable<V> get values => _map.values; | 107 Iterable<V> get values => _map.values; |
105 int get length => _map.length; | 108 int get length => _map.length; |
106 bool get isEmpty => _map.isEmpty; | 109 bool get isEmpty => _map.isEmpty; |
107 bool get isNotEmpty => _map.isNotEmpty; | 110 bool get isNotEmpty => _map.isNotEmpty; |
108 | |
109 Map<String, V> _map; | |
110 } | 111 } |
OLD | NEW |