-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(native): add Locale module (#938)
* Add locale bindings on macOS * Add Locale implementation on Linux * Add locale implementation on Windows * Add locale to Environment * Add a CAMLlocal to return * Add missing newline to format script * Free Windows pointer * Add test * Fix tests * Fix freeing based on platform
- Loading branch information
Showing
15 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
external getUser: unit => string = "revery_getUserLocale"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
|
||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
#include <string.h> | ||
|
||
#include "caml_values.h" | ||
|
||
#ifdef WIN32 | ||
#include "ReveryWin32.h" | ||
#elif __APPLE__ | ||
#include "ReveryCocoa.h" | ||
#else | ||
#include "ReveryGtk.h" | ||
#include <locale.h> | ||
#endif | ||
|
||
CAMLprim value revery_getUserLocale() { | ||
CAMLparam0(); | ||
CAMLlocal1(camlRet); | ||
char *ret; | ||
int shouldFree; | ||
#ifdef __APPLE__ | ||
ret = revery_getUserLocale_cocoa(); | ||
shouldFree = 0; | ||
#elif WIN32 | ||
ret = revery_getUserLocale_win32(); | ||
shouldFree = 1; | ||
#else | ||
setlocale(LC_CTYPE, ""); | ||
ret = setlocale(LC_CTYPE, NULL); | ||
shouldFree = 0; | ||
#endif | ||
camlRet = caml_copy_string(ret); | ||
if (shouldFree) { | ||
free(ret); | ||
} | ||
CAMLreturn(camlRet); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifdef __APPLE__ | ||
#include <stdio.h> | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
char *revery_getUserLocale_cocoa() { | ||
NSLocale *nsLocale = [NSLocale currentLocale]; | ||
return (char *)[[nsLocale localeIdentifier] UTF8String]; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifdef _WIN32 | ||
|
||
#include "win32_target.h" | ||
|
||
#include <windows.h> | ||
#include <stdlib.h> | ||
|
||
char *revery_getUserLocale_win32() { | ||
WCHAR locale[LOCALE_NAME_MAX_LENGTH]; | ||
char *localeStr = malloc(LOCALE_NAME_MAX_LENGTH * sizeof(char)); | ||
|
||
GetUserDefaultLocaleName(locale, LOCALE_NAME_MAX_LENGTH); | ||
|
||
wcstombs(localeStr, locale, sizeof(localeStr)); | ||
return localeStr; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define WINVER 0x0601 | ||
#define _WIN32_WINNT 0x0601 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters