MyAlbum   Pet
DirectX   openGL   Java   C/C++   STL   C#   Python   Window   ActiveX   SE & Refactoring   Game   Unicode   googleDesktop   Network   Database   Web   php   asp   asp.net   Library   QT   wxWidget   Something to read  
ToDo
zelon's WebAlbum
Google Tools
Google Naver map
ToRearrange
OpenOffice.org
Eclipse
Check W3 validator
unicode
e i R f
Anonymous

윈도우에서의 일반적인 프로그래밍 방법 #


ANSI, Unicode 둘 다를 지원하기 위해서는 다음과 같은 방법을 쓴다.

  • 문자열 타입은 T 타입을 쓴다. char 이 아니라 TCHAR
  • 문자열 함수는 T 타입을 쓴다. _tcsncpy
  • 문자열은 항상 TEXT() 로 묶는다.
  • 길이와 크기를 구분한다.

  • bom - byte order marker #

    UTF-8EF BB BF
    UTF-16 Big EndianFE FF
    UTF-16 Little EndianFF FE
    UTF-32 Big Endian00 00 FE FF
    UTF-32 Little endianFF FE 00 00

    UTF-8 은 딱히 byte order 가 없어도 되므로 리눅스 같은 경우 bom 을 넣지 않는다.

    UTF-8 코드에서의 bom code 를 제거하는 파이썬 코드 #

    import os
    
    def removeUTF8Bom(filename):
    	f = open(filename)
    
    	lines = f.readlines()
    	f.close()
    
    	f = open(filename, "w")
    
    	bFoundBom = False
    	index = 0
    	for line in lines:
    
    		if index == 0 and line[:3] == '\xef\xbb\xbf':
    			line = line[3:]
    			print(filename + " : removed bom code")
    			bFoundBom = True
    		
    		f.write(line)
    
    		index = index + 1
    	f.close()
    
    	if bFoundBom == False:
    		print("!!!! " + filename + " : cannot find bom code")
    
    if __name__ == "__main__":
    	removeUTF8Bom("target.c")
    
    

    C++ 콘솔 프로그래밍 #


    다음의 코드는 아쉽게도, Visual Studio .NET 2005 환경에서 테스트되었으며, 리눅스 utf-8 환경에서는 돌아가지 않는 것을 확인했다.(locale 문제인듯)
    int main()
    {
    	wcout.imbue(locale("kor"));
    	wstring k = L"k한글imjinwook";
    
    	wcout << k << endl;
    
    	return 0;
    }
    

    C++ 유니코드 프로그래밍 #

    프로그래밍 함수나 등에 T 가 붙은 것은 define 에 따라서 알아서 ANSI, UNICODE 로 변환하는 것들이다. 즉, 이런 종류를 쓰면 ASCII, Unicode 에 쉽게 대응할 수 있다. 하지만 현재 윈도우 프로그래밍의 경우 98을 지원할 것이 아니라면 그냥 Unicode 로만 프로그래밍하는 것이 좋을 듯 하다.

    TCHAR => wchar, char _tcslen => wcslen, strlen _T => L, ... TEXT => _T 랑 같음

    C++ 표준으로 리눅스에서 다음과 같이 프로그래밍할 수 있다.
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        wchar_t a[] = L"hello";
    
        wcout << L"hello" << endl;
        return 0;
    }
    

    link #