annotate base/src/java/nonstandard/Locale.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents 3daece18b48e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
1 /**
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
2 * Locale.d
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
3 * Information of a locale.
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
4 * Author: knt.roh
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
5 * License: Public Domain
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
6 */
116
3daece18b48e java.nonstandard.locale should be java.nonstandard.Locale.
Jacob Carlborg <doob@me.com>
parents: 114
diff changeset
7 module java.nonstandard.Locale;
114
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
8
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
9 import java.lang.String;
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
10 import java.lang.util : implMissing;
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
11
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
12 version(Tango){
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
13 private import tango.text.locale.Core;
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
14 } else { // Phobos
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
15 private import std.conv;
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
16 private import std.exception;
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
17
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
18 version (Windows) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
19 private import std.c.string;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
20 private import std.c.windows.windows;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
21 private bool W_VERSION;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
22 static this() {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
23 W_VERSION = GetVersion < 0x80000000;
114
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
24 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
25 private extern (Windows) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
26 enum LCID : DWORD {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
27 /// The default locale for the user or process.
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
28 LOCALE_USER_DEFAULT = 0x0400,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
29 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
30 enum LCTYPE : DWORD {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
31 /// ISO639 language name.
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
32 LOCALE_SISO639LANGNAME = 0x0059,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
33 /// ISO3166 country name.
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
34 LOCALE_SISO3166CTRYNAME = 0x005A
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
35 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
36 /// Retrieves information about a locale specified by identifier.
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
37 /// See_Also: GetLocaleInfo Function (Windows)
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
38 /// (http://msdn.microsoft.com/en-us/library/dd318101%28VS.85%29.aspx)
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
39 INT GetLocaleInfoW(
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
40 LCID Locale,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
41 LCTYPE LCType,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
42 LPWSTR lpLCData,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
43 INT cchData
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
44 );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
45 /// ditto
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
46 INT GetLocaleInfoA(
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
47 LCID Locale,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
48 LCTYPE LCType,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
49 LPCSTR lpLCData,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
50 INT cchData
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
51 );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
52 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
53 /// A purpose of this templete is switch of W or A in Windows.
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
54 private String caltureNameImpl(Char, alias GetLocalInfo)() {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
55 INT len;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
56 Char[] res;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
57 Char[] buf;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
58 len = GetLocalInfo(LCID.LOCALE_USER_DEFAULT,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
59 LCTYPE.LOCALE_SISO639LANGNAME, null, 0);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
60 enforce(len, new Exception("LOCALE_SISO639LANGNAME (len)", __FILE__, __LINE__));
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
61 buf.length = len;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
62 len = GetLocalInfo(LCID.LOCALE_USER_DEFAULT,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
63 LCTYPE.LOCALE_SISO639LANGNAME, buf.ptr, buf.length);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
64 enforce(len, new Exception("LOCALE_SISO639LANGNAME", __FILE__, __LINE__));
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
65 res ~= buf[0 .. len - 1];
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
66 res ~= "-";
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
67 len = GetLocalInfo(LCID.LOCALE_USER_DEFAULT,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
68 LCTYPE.LOCALE_SISO3166CTRYNAME, null, 0);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
69 enforce(len, new Exception("LOCALE_SISO3166CTRYNAME (len)", __FILE__, __LINE__));
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
70 buf.length = len;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
71 len = GetLocalInfo(LCID.LOCALE_USER_DEFAULT,
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
72 LCTYPE.LOCALE_SISO3166CTRYNAME, buf.ptr, buf.length);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
73 enforce(len, new Exception("LOCALE_SISO3166CTRYNAME", __FILE__, __LINE__));
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
74 res ~= buf[0 .. len - 1];
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
75 return to!(String)(res);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
76 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
77 } else version (Posix) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
78 private import std.process : getenv;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
79 private import std.string : indexOf, replace;
114
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
80 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
81 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
82 /// Get a omitted calture name. for example: "en-US"
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
83 String caltureName() {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
84 version(Tango){
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
85 return Culture.current.name;
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
86 } else { // Phobos
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
87 version (Windows) {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
88 if (W_VERSION) {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
89 return caltureNameImpl!(wchar, GetLocaleInfoW)();
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
90 } else {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
91 return caltureNameImpl!(char, GetLocaleInfoA)();
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
92 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
93 } else version (Posix) {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
94 // LC_ALL is override to settings of all category.
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
95 // This is undefined in almost case.
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
96 String res = .getenv("LC_ALL");
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
97 if (!res || !res.length) {
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
98 // LANG is basic Locale setting.
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
99 // A settings of each category override this.
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
100 res = .getenv("LANG");
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
101 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
102 int dot = .indexOf(res, '.');
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
103 if (dot != -1) res = res[0 .. dot];
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
104 return .replace(res, "_", "-");
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
105 } else {
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 116
diff changeset
106 static assert(0);
114
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
107 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
108 }
46539f5c5993 Added implementation of ResourceBundle.
kntroh
parents:
diff changeset
109 }