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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // handle these correctly we search for a second occurrence of | 64 // handle these correctly we search for a second occurrence of |
65 // of '=' in the string if the first occurrence is at index 0. | 65 // of '=' in the string if the first occurrence is at index 0. |
66 var equalsIndex = str.indexOf('='); | 66 var equalsIndex = str.indexOf('='); |
67 if (equalsIndex == 0) { | 67 if (equalsIndex == 0) { |
68 equalsIndex = str.indexOf('=', 1); | 68 equalsIndex = str.indexOf('=', 1); |
69 } | 69 } |
70 assert(equalsIndex != -1); | 70 assert(equalsIndex != -1); |
71 result[str.substring(0, equalsIndex)] = | 71 result[str.substring(0, equalsIndex)] = |
72 str.substring(equalsIndex + 1); | 72 str.substring(equalsIndex + 1); |
73 } | 73 } |
74 _environmentCache = new UnmodifiableMapView(result); | 74 _environmentCache = new UnmodifiableMapView<String, String>(result); |
75 } else { | 75 } else { |
76 _environmentCache = env; | 76 _environmentCache = env; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 if (_environmentCache is OSError) { | 80 if (_environmentCache is OSError) { |
81 throw _environmentCache; | 81 throw _environmentCache; |
82 } else { | 82 } else { |
83 return _environmentCache; | 83 return _environmentCache; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 static String get version => _version(); | 87 static String get version => _version(); |
88 } | 88 } |
89 | 89 |
90 // Environment variables are case-insensitive on Windows. In order | 90 // Environment variables are case-insensitive on Windows. In order |
91 // 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. |
92 class _CaseInsensitiveStringMap<V> implements Map<String, V> { | 92 class _CaseInsensitiveStringMap<V> implements Map<String, V> { |
93 Map<String, V> _map; | 93 final Map<String, V> _map = new Map<String, V>(); |
94 | |
95 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); | |
96 | |
97 _CaseInsensitiveStringMap.from(Map<String, V> other) | |
98 : _map = new Map<String, V>() { | |
99 other.forEach((String key, V value) { | |
100 _map[key.toUpperCase()] = value; | |
101 }); | |
102 } | |
103 | 94 |
104 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); | 95 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); |
105 bool containsValue(Object value) => _map.containsValue(value); | 96 bool containsValue(Object value) => _map.containsValue(value); |
106 V operator [](String key) => _map[key.toUpperCase()]; | 97 V operator [](String key) => _map[key.toUpperCase()]; |
107 void operator []=(String key, V value) { | 98 void operator []=(String key, V value) { |
108 _map[key.toUpperCase()] = value; | 99 _map[key.toUpperCase()] = value; |
109 } | 100 } |
110 V putIfAbsent(String key, V ifAbsent()) { | 101 V putIfAbsent(String key, V ifAbsent()) { |
111 _map.putIfAbsent(key.toUpperCase(), ifAbsent); | 102 _map.putIfAbsent(key.toUpperCase(), ifAbsent); |
112 } | 103 } |
113 addAll(Map other) { | 104 addAll(Map other) { |
114 other.forEach((key, value) => this[key.toUpperCase()] = value); | 105 other.forEach((key, value) => this[key.toUpperCase()] = value); |
115 } | 106 } |
116 V remove(String key) => _map.remove(key.toUpperCase()); | 107 V remove(String key) => _map.remove(key.toUpperCase()); |
117 void clear() => _map.clear(); | 108 void clear() => _map.clear(); |
118 void forEach(void f(String key, V value)) => _map.forEach(f); | 109 void forEach(void f(String key, V value)) => _map.forEach(f); |
119 Iterable<String> get keys => _map.keys; | 110 Iterable<String> get keys => _map.keys; |
120 Iterable<V> get values => _map.values; | 111 Iterable<V> get values => _map.values; |
121 int get length => _map.length; | 112 int get length => _map.length; |
122 bool get isEmpty => _map.isEmpty; | 113 bool get isEmpty => _map.isEmpty; |
123 bool get isNotEmpty => _map.isNotEmpty; | 114 bool get isNotEmpty => _map.isNotEmpty; |
| 115 String toString() => _map.toString(); |
124 } | 116 } |
OLD | NEW |