| 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 19 matching lines...) Expand all Loading... |
| 30 } else { | 30 } else { |
| 31 return result; | 31 return result; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 static Map<String, String> get environment { | 35 static Map<String, String> get environment { |
| 36 var env = _environment(); | 36 var env = _environment(); |
| 37 if (env is OSError) { | 37 if (env is OSError) { |
| 38 throw env; | 38 throw env; |
| 39 } else { | 39 } else { |
| 40 var result = new Map(); | 40 var isWindows = operatingSystem == 'windows'; |
| 41 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
| 41 for (var str in env) { | 42 for (var str in env) { |
| 42 // When running on Windows through cmd.exe there are strange | 43 // When running on Windows through cmd.exe there are strange |
| 43 // environment variables that are used to record the current | 44 // environment variables that are used to record the current |
| 44 // working directory for each drive and the exit code for the | 45 // working directory for each drive and the exit code for the |
| 45 // last command. As an example: '=A:=A:\subdir' records the | 46 // last command. As an example: '=A:=A:\subdir' records the |
| 46 // current working directory on the 'A' drive. In order to | 47 // current working directory on the 'A' drive. In order to |
| 47 // handle these correctly we search for a second occurrence of | 48 // handle these correctly we search for a second occurrence of |
| 48 // of '=' in the string if the first occurrence is at index 0. | 49 // of '=' in the string if the first occurrence is at index 0. |
| 49 var equalsIndex = str.indexOf('='); | 50 var equalsIndex = str.indexOf('='); |
| 50 if (equalsIndex == 0) { | 51 if (equalsIndex == 0) { |
| 51 equalsIndex = str.indexOf('=', 1); | 52 equalsIndex = str.indexOf('=', 1); |
| 52 } | 53 } |
| 53 assert(equalsIndex != -1); | 54 assert(equalsIndex != -1); |
| 54 result[str.substring(0, equalsIndex)] = str.substring(equalsIndex + 1); | 55 result[str.substring(0, equalsIndex)] = str.substring(equalsIndex + 1); |
| 55 } | 56 } |
| 56 return result; | 57 return result; |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 } | 60 } |
| 61 |
| 62 // Environment variables are case-insensitive on Windows. In order |
| 63 // to reflect that we use a case-insensitive string map on Windows. |
| 64 class _CaseInsensitiveStringMap<V> implements Map<String, V> { |
| 65 _CaseInsensitiveStringMap() : _map = new Map<String, V>(); |
| 66 |
| 67 _CaseInsensitiveStringMap.from(Map<String, V> other) |
| 68 : _map = new Map<String, V>() { |
| 69 other.forEach((String key, V value) { |
| 70 _map[key.toUpperCase()] = value; |
| 71 }); |
| 72 } |
| 73 |
| 74 bool containsKey(String key) => _map.containsKey(key.toUpperCase()); |
| 75 bool containsValue(V value) => _map.containsValue(value); |
| 76 V operator [](String key) => _map[key.toUpperCase()]; |
| 77 void operator []=(String key, V value) { |
| 78 _map[key.toUpperCase()] = value; |
| 79 } |
| 80 V putIfAbsent(String key, V ifAbsent()) { |
| 81 _map.putIfAbsent(key.toUpperCase(), ifAbsent); |
| 82 } |
| 83 V remove(String key) => _map.remove(key.toUpperCase()); |
| 84 void clear() => _map.clear(); |
| 85 void forEach(void f(String key, V value)) => _map.forEach(f); |
| 86 Collection<String> get keys => _map.keys; |
| 87 Collection<V> get values => _map.values; |
| 88 int get length => _map.length; |
| 89 bool get isEmpty => _map.isEmpty; |
| 90 |
| 91 Map<String, V> _map; |
| 92 } |
| OLD | NEW |