Mercurial > projects > ldc
comparison tango/tango/text/locale/Win32.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /******************************************************************************* | |
2 | |
3 copyright: Copyright (c) 2005 John Chapman. All rights reserved | |
4 | |
5 license: BSD style: $(LICENSE) | |
6 | |
7 version: Initial release: 2005 | |
8 | |
9 author: John Chapman | |
10 | |
11 ******************************************************************************/ | |
12 | |
13 module tango.text.locale.Win32; | |
14 | |
15 alias tango.text.locale.Win32 nativeMethods; | |
16 | |
17 extern (Windows) | |
18 private { | |
19 void GetSystemTimeAsFileTime(out ulong lpSystemTimeAsFileTime); | |
20 uint GetUserDefaultLCID(); | |
21 uint GetThreadLocale(); | |
22 bool SetThreadLocale(uint Locale); | |
23 int MultiByteToWideChar(uint CodePage, uint dwFlags, char* lpMultiByteStr, int cbMultiByte, wchar* lpWideCharStr, int cchWideChar); | |
24 int CompareStringW(uint Locale, uint dwCmpFlags, wchar* lpString1, int cchCount1, wchar* lpString2, int cchCount2); | |
25 | |
26 } | |
27 | |
28 int getUserCulture() { | |
29 return GetUserDefaultLCID(); | |
30 } | |
31 | |
32 void setUserCulture(int lcid) { | |
33 SetThreadLocale(lcid); | |
34 } | |
35 | |
36 ulong getUtcTime() { | |
37 ulong ticks; | |
38 GetSystemTimeAsFileTime(ticks); | |
39 return ticks; | |
40 } | |
41 | |
42 int compareString(int lcid, char[] stringA, uint offsetA, uint lengthA, char[] stringB, uint offsetB, uint lengthB, bool ignoreCase) { | |
43 | |
44 wchar[] toUnicode(char[] string, uint offset, uint length, out int translated) { | |
45 char* chars = string.ptr + offset; | |
46 int required = MultiByteToWideChar(0, 0, chars, length, null, 0); | |
47 wchar[] result = new wchar[required]; | |
48 translated = MultiByteToWideChar(0, 0, chars, length, result.ptr, required); | |
49 return result; | |
50 } | |
51 | |
52 int sortId = (lcid >> 16) & 0xF; | |
53 sortId = (sortId == 0) ? lcid : (lcid | (sortId << 16)); | |
54 | |
55 int len1, len2; | |
56 wchar[] string1 = toUnicode(stringA, offsetA, lengthA, len1); | |
57 wchar[] string2 = toUnicode(stringB, offsetB, lengthB, len2); | |
58 | |
59 return CompareStringW(sortId, ignoreCase ? 0x1 : 0x0, string1.ptr, len1, string2.ptr, len2) - 2; | |
60 } |