mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Revert "[dart:io] Adds Platform.localeName"
This reverts commit ae6d854ec6
.
The build failed on the mac build bots. Need to investigate.
Review-Url: https://codereview.chromium.org/2791453002 .
This commit is contained in:
parent
ae6d854ec6
commit
e75df3cce3
|
@ -4,9 +4,6 @@
|
||||||
|
|
||||||
### Core library changes
|
### Core library changes
|
||||||
|
|
||||||
* `dart:io`
|
|
||||||
* Added `Platform.localeName`.
|
|
||||||
|
|
||||||
### Dart VM
|
### Dart VM
|
||||||
|
|
||||||
### Strong Mode
|
### Strong Mode
|
||||||
|
|
|
@ -252,8 +252,8 @@ class _Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
@patch
|
@patch
|
||||||
static String _localeName() {
|
static _ansiSupported() {
|
||||||
throw new UnsupportedError("Platform._localeName");
|
throw new UnsupportedError("Platform._ansiSupported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,6 @@ namespace bin {
|
||||||
V(Platform_Environment, 0) \
|
V(Platform_Environment, 0) \
|
||||||
V(Platform_ExecutableArguments, 0) \
|
V(Platform_ExecutableArguments, 0) \
|
||||||
V(Platform_GetVersion, 0) \
|
V(Platform_GetVersion, 0) \
|
||||||
V(Platform_LocaleName, 0) \
|
|
||||||
V(Process_Start, 11) \
|
V(Process_Start, 11) \
|
||||||
V(Process_Wait, 5) \
|
V(Process_Wait, 5) \
|
||||||
V(Process_KillPid, 2) \
|
V(Process_KillPid, 2) \
|
||||||
|
|
|
@ -109,16 +109,6 @@ void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) {
|
||||||
Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString()));
|
Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FUNCTION_NAME(Platform_LocaleName)(Dart_NativeArguments args) {
|
|
||||||
const char* locale = Platform::LocaleName();
|
|
||||||
if (locale == NULL) {
|
|
||||||
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
|
|
||||||
} else {
|
|
||||||
Dart_SetReturnValue(args, Dart_NewStringFromCString(locale));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace bin
|
} // namespace bin
|
||||||
} // namespace dart
|
} // namespace dart
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,6 @@ class Platform {
|
||||||
// Extracts the local hostname.
|
// Extracts the local hostname.
|
||||||
static bool LocalHostname(char* buffer, intptr_t buffer_length);
|
static bool LocalHostname(char* buffer, intptr_t buffer_length);
|
||||||
|
|
||||||
static const char* LocaleName();
|
|
||||||
|
|
||||||
// Extracts the environment variables for the current process. The array of
|
// Extracts the environment variables for the current process. The array of
|
||||||
// strings is Dart_ScopeAllocated. The number of elements in the array is
|
// strings is Dart_ScopeAllocated. The number of elements in the array is
|
||||||
// returned in the count argument.
|
// returned in the count argument.
|
||||||
|
|
|
@ -57,11 +57,6 @@ const char* Platform::LibraryExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* Platform::LocaleName() {
|
|
||||||
return getenv("LANG");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
||||||
return gethostname(buffer, buffer_length) == 0;
|
return gethostname(buffer, buffer_length) == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,11 +47,6 @@ const char* Platform::LibraryExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* Platform::LocaleName() {
|
|
||||||
return getenv("LANG");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
||||||
return gethostname(buffer, buffer_length) == 0;
|
return gethostname(buffer, buffer_length) == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,11 +82,6 @@ const char* Platform::LibraryExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* Platform::LocaleName() {
|
|
||||||
return getenv("LANG");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
||||||
return gethostname(buffer, buffer_length) == 0;
|
return gethostname(buffer, buffer_length) == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
#include "bin/platform.h"
|
#include "bin/platform.h"
|
||||||
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
|
||||||
|
|
||||||
#if !HOST_OS_IOS
|
#if !HOST_OS_IOS
|
||||||
#include <crt_externs.h> // NOLINT
|
#include <crt_externs.h> // NOLINT
|
||||||
#endif // !HOST_OS_IOS
|
#endif // !HOST_OS_IOS
|
||||||
|
@ -100,60 +98,6 @@ const char* Platform::LibraryExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* GetLocaleName() {
|
|
||||||
CFLocaleRef locale = CFLocaleCopyCurrent();
|
|
||||||
CFLocaleIdentifier locale_id = CFLocaleGetIdentifier(locale);
|
|
||||||
CFStringRef locale_string = reinterpret_cast<CFStringRef>(locale_id);
|
|
||||||
CFIndex len = CFStringGetLength(locale_string);
|
|
||||||
CFIndex max_len =
|
|
||||||
CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1;
|
|
||||||
char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len));
|
|
||||||
ASSERT(result != NULL);
|
|
||||||
bool success =
|
|
||||||
CFStringGetCString(locale_string, result, max_len, kCFStringEncodingUTF8);
|
|
||||||
CFRelease(locale);
|
|
||||||
if (!success) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const char* GetPreferredLanguageName() {
|
|
||||||
CFArrayRef languages = CFLocaleCopyPreferredLanguages();
|
|
||||||
CFIndex languages_length = CFArrayGetCount(languages);
|
|
||||||
if (languages_length < 1) {
|
|
||||||
CFRelease(languages);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
CFTypeRef item =
|
|
||||||
reinterpret_cast<CFTypeRef>(CFArrayGetValueAtIndex(languages, 0));
|
|
||||||
CFTypeID item_type = CFGetTypeID(item);
|
|
||||||
ASSERT(item_type == CFStringGetTypeID());
|
|
||||||
CFStringRef language = reinterpret_cast<CFStringRef>(item);
|
|
||||||
CFIndex len = CFStringGetLength(language);
|
|
||||||
CFIndex max_len =
|
|
||||||
CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8) + 1;
|
|
||||||
char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(max_len));
|
|
||||||
ASSERT(result != NULL);
|
|
||||||
bool success =
|
|
||||||
CFStringGetCString(language, result, max_len, kCFStringEncodingUTF8);
|
|
||||||
CFRelease(languages);
|
|
||||||
if (!success) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* Platform::LocaleName() {
|
|
||||||
// First see if there is a preferred language. If not, return the
|
|
||||||
// current locale name.
|
|
||||||
const char* preferred_langauge = GetPreferredLanguageName();
|
|
||||||
return (preferred_langauge != NULL) ? preferred_langauge : GetLocaleName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
||||||
return gethostname(buffer, buffer_length) == 0;
|
return gethostname(buffer, buffer_length) == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,6 @@ class _Platform {
|
||||||
@patch
|
@patch
|
||||||
static String _version() native "Platform_GetVersion";
|
static String _version() native "Platform_GetVersion";
|
||||||
|
|
||||||
@patch
|
|
||||||
static String _localeName() native "Platform_LocaleName";
|
|
||||||
|
|
||||||
@patch
|
@patch
|
||||||
static String _packageRoot() => VMLibraryHooks.packageRootString;
|
static String _packageRoot() => VMLibraryHooks.packageRootString;
|
||||||
@patch
|
@patch
|
||||||
|
|
|
@ -64,12 +64,6 @@ void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) {
|
||||||
"Platform is not supported on this platform"));
|
"Platform is not supported on this platform"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FUNCTION_NAME(Platform_LocaleName)(Dart_NativeArguments args) {
|
|
||||||
Dart_ThrowException(DartUtils::NewInternalError(
|
|
||||||
"Platform is not supported on this platform"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace bin
|
} // namespace bin
|
||||||
} // namespace dart
|
} // namespace dart
|
||||||
|
|
||||||
|
|
|
@ -198,16 +198,6 @@ const char* Platform::LibraryExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* Platform::LocaleName() {
|
|
||||||
wchar_t locale_name[LOCALE_NAME_MAX_LENGTH];
|
|
||||||
int result = GetUserDefaultLocaleName(locale_name, LOCALE_NAME_MAX_LENGTH);
|
|
||||||
if (result == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return StringUtilsWin::WideToUtf8(locale_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
||||||
#if defined(DART_IO_DISABLED) || defined(PLATFORM_DISABLE_SOCKET)
|
#if defined(DART_IO_DISABLED) || defined(PLATFORM_DISABLE_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -250,11 +250,6 @@ class _Platform {
|
||||||
static String _version() {
|
static String _version() {
|
||||||
throw new UnsupportedError("Platform._version");
|
throw new UnsupportedError("Platform._version");
|
||||||
}
|
}
|
||||||
|
|
||||||
@patch
|
|
||||||
static String _localeName() {
|
|
||||||
throw new UnsupportedError("Platform._localeName");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@patch
|
@patch
|
||||||
|
|
|
@ -71,7 +71,6 @@ class Platform {
|
||||||
static final _operatingSystem = _Platform.operatingSystem;
|
static final _operatingSystem = _Platform.operatingSystem;
|
||||||
static final _localHostname = _Platform.localHostname;
|
static final _localHostname = _Platform.localHostname;
|
||||||
static final _version = _Platform.version;
|
static final _version = _Platform.version;
|
||||||
static final _localeName = _Platform.localeName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of processors of the machine.
|
* Get the number of processors of the machine.
|
||||||
|
@ -84,11 +83,6 @@ class Platform {
|
||||||
*/
|
*/
|
||||||
static String get pathSeparator => _pathSeparator;
|
static String get pathSeparator => _pathSeparator;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the current locale.
|
|
||||||
*/
|
|
||||||
static String get localeName => _localeName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string (`linux`, `macos`, `windows`, `android`, or `ios`)
|
* Get a string (`linux`, `macos`, `windows`, `android`, or `ios`)
|
||||||
* representing the operating system.
|
* representing the operating system.
|
||||||
|
|
|
@ -32,25 +32,12 @@ class _Platform {
|
||||||
external static String _packageRoot();
|
external static String _packageRoot();
|
||||||
external static String _packageConfig();
|
external static String _packageConfig();
|
||||||
external static String _version();
|
external static String _version();
|
||||||
external static String _localeName();
|
|
||||||
|
|
||||||
static String executable = _executable();
|
static String executable = _executable();
|
||||||
static String resolvedExecutable = _resolvedExecutable();
|
static String resolvedExecutable = _resolvedExecutable();
|
||||||
static String packageRoot = _packageRoot();
|
static String packageRoot = _packageRoot();
|
||||||
static String packageConfig = _packageConfig();
|
static String packageConfig = _packageConfig();
|
||||||
|
|
||||||
static String _cachedLocaleName;
|
|
||||||
static String get localeName {
|
|
||||||
if (_cachedLocaleName == null) {
|
|
||||||
var result = _localeName();
|
|
||||||
if (result is OSError) {
|
|
||||||
throw result;
|
|
||||||
}
|
|
||||||
_cachedLocaleName = result;
|
|
||||||
}
|
|
||||||
return _cachedLocaleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache the OS environment. This can be an OSError instance if
|
// Cache the OS environment. This can be an OSError instance if
|
||||||
// retrieving the environment failed.
|
// retrieving the environment failed.
|
||||||
static var /*OSError|Map<String,String>*/ _environmentCache;
|
static var /*OSError|Map<String,String>*/ _environmentCache;
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import "package:expect/expect.dart";
|
|
||||||
|
|
||||||
main() {
|
|
||||||
try {
|
|
||||||
Platform.localeName;
|
|
||||||
} catch (e, s) {
|
|
||||||
Expect.fail("Platform.localeName threw: $e\n$s\n");
|
|
||||||
}
|
|
||||||
Expect.isNotNull(Platform.localeName);
|
|
||||||
Expect.isTrue(Platform.localeName is String);
|
|
||||||
print(Platform.localeName);
|
|
||||||
}
|
|
Loading…
Reference in a new issue