comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/win32/OS.d @ 39:0ecb2b338560

further work on phobosification
author Frank Benoit <benoit@tionex.de>
date Wed, 25 Mar 2009 13:20:43 +0100
parents 2e09b0e6857a
children ed96ea2a2764
comparison
equal deleted inserted replaced
38:2e09b0e6857a 39:0ecb2b338560
3620 static int strlen( PCHAR ptr ){ 3620 static int strlen( PCHAR ptr ){
3621 version(Tango){ 3621 version(Tango){
3622 return tango.stdc.string.strlen( cast(char*)ptr ); 3622 return tango.stdc.string.strlen( cast(char*)ptr );
3623 } else { // Phobos 3623 } else { // Phobos
3624 implMissing( __FILE__, __LINE__ ); 3624 implMissing( __FILE__, __LINE__ );
3625 return 0;
3625 } 3626 }
3626 } 3627 }
3627 3628
3628 static void POINTSTOPOINT( inout POINT pt, int pts) { 3629 static void POINTSTOPOINT( inout POINT pt, int pts) {
3629 pt.x = cast(SHORT) LOWORD(pts); 3630 pt.x = cast(SHORT) LOWORD(pts);
3641 foreach (char c; sc){ 3642 foreach (char c; sc){
3642 if (c >= 0x80) 3643 if (c >= 0x80)
3643 { 3644 {
3644 CHAR[] result; 3645 CHAR[] result;
3645 int i; 3646 int i;
3646 wchar[] ws = toWCharArray(sc); 3647 auto ws = toWCharArray(sc);
3647 result.length = OS.WideCharToMultiByte(codepage, 0, ws.ptr, ws.length, null, 0, null, null); 3648 result.length = OS.WideCharToMultiByte(codepage, 0, ws.ptr, ws.length, null, 0, null, null);
3648 i = OS.WideCharToMultiByte(codepage, 0, ws.ptr, ws.length, result.ptr, result.length, null, null); 3649 i = OS.WideCharToMultiByte(codepage, 0, ws.ptr, ws.length, result.ptr, result.length, null, null);
3649 assert(i == result.length); 3650 assert(i == result.length);
3650 return result; 3651 return result;
3651 } 3652 }
3658 } 3659 }
3659 3660
3660 // convert UTF-8 to MBCSz 3661 // convert UTF-8 to MBCSz
3661 public char* StrToMBCSz(CString sc) { 3662 public char* StrToMBCSz(CString sc) {
3662 char* ret = null; 3663 char* ret = null;
3663 try{ 3664 version(Tango){
3664 if( CodePage.isAscii( sc )){ 3665 try{
3665 return .toStringz( sc ); 3666 if( CodePage.isAscii( sc )){
3667 return .toStringz( sc );
3668 }
3669 char[] dst;
3670 dst.length = sc.length;
3671 return toStringz( tango.sys.win32.CodePage.CodePage.into( sc, dst ));
3672 }catch(Exception e){
3673 // do nothing
3674 ret = "";
3666 } 3675 }
3667 char[] dst; 3676
3668 dst.length = sc.length; 3677 } else { // Phobos
3669 version(Tango){ 3678 implMissing( __FILE__, __LINE__ );
3670 return toStringz( tango.sys.win32.CodePage.CodePage.into( sc, dst ));
3671 } else { // Phobos
3672 implMissing( __FILE__, __LINE__ );
3673 }
3674 }catch(Exception e){
3675 // do nothing
3676 ret = "";
3677 } 3679 }
3678
3679 return ret; 3680 return ret;
3680 } 3681 }
3681 3682
3682 public String16 StrToWCHARs(uint codepage , CString sc, bool terminated = false ) { 3683 public String16 StrToWCHARs(uint codepage , CString sc, bool terminated = false ) {
3683 return StrToWCHARs( sc, terminated ); 3684 return StrToWCHARs( sc, terminated );
3684 } 3685 }
3685 public String16 StrToWCHARs(CString sc, bool terminated = false ) { 3686 public String16 StrToWCHARs(CString sc, bool terminated = false ) {
3686 wchar[] ret; 3687 String16 ret;
3687 try{ 3688 try{
3688 ret = toWCharArray(sc); 3689 ret = toWCharArray(sc);
3689 }catch(Exception e){ 3690 }catch(Exception e){
3690 // do nothing 3691 // do nothing
3691 ret = ""; 3692 ret = "";
3694 ret ~= "\0"; 3695 ret ~= "\0";
3695 } 3696 }
3696 return ret; 3697 return ret;
3697 } 3698 }
3698 3699
3699 public wchar* StrToWCHARz( uint codepage, CString sc, uint* length = null ) { 3700 public LPCWSTR StrToWCHARz( uint codepage, CString sc, uint* length = null ) {
3700 return StrToWCHARz( sc, length ); 3701 return StrToWCHARz( sc, length );
3701 } 3702 }
3702 3703
3703 public wchar* StrToWCHARz(CString sc, uint* length = null ) { 3704 public LPCWSTR StrToWCHARz(CString sc, uint* length = null ) {
3704 return StrToWCHARs(sc, true ).ptr; 3705 return StrToWCHARs(sc, true ).ptr;
3705 } 3706 }
3706 3707
3707 public CString MBCSsToStr(CHAR[] string, uint codepage = 0){ 3708 public CString MBCSsToStr(CHAR[] string, uint codepage = 0){
3708 return MBCSzToStr( string.ptr, string.length, codepage); 3709 return MBCSzToStr( string.ptr, string.length, codepage);
3717 } 3718 }
3718 // convert MBCS to UTF-8 3719 // convert MBCS to UTF-8
3719 if(_length == 0) 3720 if(_length == 0)
3720 return null; 3721 return null;
3721 3722
3722 wchar[] wcs = _mbcszToWs(pString, _length, codepage); 3723 String16 wcs = _mbcszToWs(pString, _length, codepage);
3723 char[] result; 3724 String result;
3724 try{ 3725 try{
3725 result = String_valueOf(wcs); 3726 result = String_valueOf(wcs);
3726 }catch(Exception e){ 3727 }catch(Exception e){
3727 } 3728 }
3728 return result; 3729 return result;
3744 ++_length; 3745 ++_length;
3745 } 3746 }
3746 if(_length == 0) 3747 if(_length == 0)
3747 return null; 3748 return null;
3748 // convert wchar* to UTF-8 3749 // convert wchar* to UTF-8
3749 wchar[] wcs = pString[0.._length]; 3750 auto wcs = pString[0.._length];
3750 3751
3751 char[] result; 3752 String result;
3752 try{ 3753 try{
3753 result = String_valueOf(wcs); 3754 result = String_valueOf(wcs);
3754 }catch(Exception e){ 3755 }catch(Exception e){
3755 // do nothing 3756 // do nothing
3756 } 3757 }
3780 return result; 3781 return result;
3781 } 3782 }
3782 } // end of OLE_COM 3783 } // end of OLE_COM
3783 3784
3784 3785
3785 public static wchar[] _mbcszToWs(PCHAR pMBCS, int len, uint codepage = 0) 3786 public static String16 _mbcszToWs(PCHAR pMBCS, int len, uint codepage = 0)
3786 { 3787 {
3787 wchar[] wbuf; 3788 wchar[] wbuf;
3788 // Convert MBCS to unicode 3789 // Convert MBCS to unicode
3789 wbuf.length = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, null, 0); 3790 wbuf.length = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, null, 0);
3790 int n = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, wbuf.ptr, wbuf.length); 3791 int n = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, wbuf.ptr, wbuf.length);
3791 assert(n == wbuf.length); 3792 assert(n == wbuf.length);
3792 return wbuf; 3793 return cast(String16)wbuf;
3793 } 3794 }
3794 3795
3795 // static methods 3796 // static methods
3796 public int _tcslen(TCHAR* pString){ 3797 public int _tcslen(TCHAR* pString){
3797 int _length = 0; 3798 int _length = 0;
3808 char[] b = std.string.toupper(a); 3809 char[] b = std.string.toupper(a);
3809 char[] c = std.string.tolower(a); 3810 char[] c = std.string.tolower(a);
3810 The length of a is 11, but the length of b,c is 18 now. 3811 The length of a is 11, but the length of b,c is 18 now.
3811 * 3812 *
3812 */ 3813 */
3813 public char[] tolower(char[] string) { 3814 public String tolower(char[] string) {
3814 TCHAR* ps = StrToTCHARz(string); 3815 LPCTSTR ps = StrToTCHARz(string);
3815 TCHAR* ps2 = OS.CharLower(ps); 3816 LPCTSTR ps2 = OS.CharLower(cast(LPTSTR)ps);
3816 return TCHARzToStr(ps2); 3817 return TCHARzToStr(ps2);
3817 } 3818 }
3818 public char[] toupper(char[] string) { 3819 public String toupper(char[] string) {
3819 TCHAR* ps = StrToTCHARz(string); 3820 LPCTSTR ps = StrToTCHARz(string);
3820 TCHAR* ps2 = OS.CharUpper(ps); 3821 LPCTSTR ps2 = OS.CharUpper(cast(LPTSTR)ps);
3821 return TCHARzToStr(ps2); 3822 return TCHARzToStr(ps2);
3822 } 3823 }
3823 3824
3824 version(ANSI){ 3825 version(ANSI){
3825 alias StrToMBCS StrToTCHARs; 3826 alias StrToMBCS StrToTCHARs;