응용 프로그램에서 문자를 UTF-8 인코딩 % C3 % BA (으)로 수신하고 유니 코드 상응하는 % FA로 저장하는 C++ 응용 프로그램에서 U를 어떻게 변환합니까? 난 그냥 ...이 인코딩 과정UTF-8에서 유니 코드로 변환 C++
1
A
답변
5
난 그냥이 어제 할 몇 가지 코드를 썼다을 수행하는 코드를 작성 가겠어요 방법을 알고 싶어요
나는이에 "완벽한"방법입니다 말하는 게 아니에요 이렇게해라. 그러나 나는 그것을 실행 한 모든 테스트 케이스들 (나는 그 목적을 위해 두 방향 모두를 썼다)에서 작동하는 것으로 보인다.
"% NN"을 정수 값으로 변환하겠습니다.
#include <iostream>
#include <deque>
std::deque<int> unicode_to_utf8(int charcode)
{
std::deque<int> d;
if (charcode < 128)
{
d.push_back(charcode);
}
else
{
int first_bits = 6;
const int other_bits = 6;
int first_val = 0xC0;
int t = 0;
while (charcode >= (1 << first_bits))
{
{
t = 128 | (charcode & ((1 << other_bits)-1));
charcode >>= other_bits;
first_val |= 1 << (first_bits);
first_bits--;
}
d.push_front(t);
}
t = first_val | charcode;
d.push_front(t);
}
return d;
}
int utf8_to_unicode(std::deque<int> &coded)
{
int charcode = 0;
int t = coded.front();
coded.pop_front();
if (t < 128)
{
return t;
}
int high_bit_mask = (1 << 6) -1;
int high_bit_shift = 0;
int total_bits = 0;
const int other_bits = 6;
while((t & 0xC0) == 0xC0)
{
t <<= 1;
t &= 0xff;
total_bits += 6;
high_bit_mask >>= 1;
high_bit_shift++;
charcode <<= other_bits;
charcode |= coded.front() & ((1 << other_bits)-1);
coded.pop_front();
}
charcode |= ((t >> high_bit_shift) & high_bit_mask) << total_bits;
return charcode;
}
int main()
{
int charcode;
for(;;)
{
std::cout << "Enter unicode value:" << std::endl;
std::cin >> charcode;
auto x = unicode_to_utf8(charcode);
for(auto c : x)
{
std::cout << "\\x" << std::hex << c << " ";
}
std::cout << std::endl;
int c = utf8_to_unicode(x);
std::cout << "reversed:" << std::dec << c << std::hex << " in hex:" << c << std::endl;
}
}
관련 문제
- 1. NSString iOS에서 UTF8에서 유니 코드로 변환
- 2. 유니 코드로 이모티콘 변환
- 3. int를 유니 코드로 변환
- 4. Utf8을 유니 코드로 변환
- 5. 숫자를 유니 코드로 변환
- 6. ANSI에서 유니 코드로 변환
- 7. 한국어 텍스트를 유니 코드로 변환
- 8. 그리스 문자를 유니 코드로 변환
- 9. Python에서 안전한 유니 코드로 변환
- 10. UTF-8에서 유니 코드로 변환
- 11. datetime.ctime() 값을 유니 코드로 변환
- 12. 로그 항목을 유니 코드로 변환
- 13. str을 파이썬에서 유니 코드로 변환
- 14. UTF8에서 ASCII 로의 변환
- 15. 유니 코드의 유니 코드 문자열 표현을 유니 코드로 변환
- 16. 멀티 바이트 인코딩에서 유니 코드로 변환
- 17. 정수를 하위 호환 방식으로 유니 코드로 변환
- 18. MFC C++에서 유니 코드로 문자 배열을 변환
- 19. Subversion 커밋 메시지를 유니 코드로 변환
- 20. 인코딩 검사 및 유니 코드로 변환
- 21. QString 또는 QUrl을 유니 코드로 변환
- 22. 16 진수 문자열에서 유니 코드로 변환
- 23. Maven 빌드의 일부로 문자열을 유니 코드로 변환
- 24. UnicodeDecodeError : 형식 문자열을 유니 코드로 변환
- 25. django : gettext 및 유니 코드로 강제 변환
- 26. 대시 기호로 된 punycode를 유니 코드로 변환
- 27. MySQL에서 복합 바이트를 유니 코드로 변환
- 28. Python : RTF 파일을 유니 코드로 변환 하시겠습니까?
- 29. Excel에서 C# 코드로 변환
- 30. xaml을 C# 코드로 변환
http://utfcpp.sourceforge.net/? –
http://msdn.microsoft.com/en-us/library/dd374130(v=vs.85).aspx? –
제목과 관련하여 기록을 위해 : UTF-8 _is_ 유니 코드. 코드 포인트를 지정하는 표준 방법은'U + 00FA' (최소 4 자리 16 진수, 최대 6 자리)입니다. –