UTF-16 클래스 만들기 #60
Replies: 10 comments 29 replies
-
넵넵! 참고할게요! 감사합니다~!~! |
Beta Was this translation helpful? Give feedback.
-
goooooooood :) |
Beta Was this translation helpful? Give feedback.
-
https://convertcodes.com/utf16-encode-decode-convert-string/ |
Beta Was this translation helpful? Give feedback.
-
#include <iostream>
#include <codecvt>
int main() {
std::string s = u8"가나다";
std::wstring_convert<std::codecvt<char16_t, char, std::mbstate_t>, char16_t> convert;
std::u16string u16 = convert.from_bytes(s);
for (char16_t c : u16) {
std::cout << std::hex << int(c) << std::endl;
}
/*
ac00
b098
b2e4
*/
} 일단 간단하게 프린트만 하도록 UTF16 인코딩부터 만들어보고 있는데 이런 느낌으로 하면 되는건가요 ?! 근데 일단 저 코드에서는 |
Beta Was this translation helpful? Give feedback.
-
UTF8 decoder 테스트 자료입니다. https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
등의 키워드들이 있습니다. 아직 파악중입니다😿 |
Beta Was this translation helpful? Give feedback.
-
디스커션 자체를 워낙 세세하게 다들 작성해 주셔서 한 눈에 이해가 잘 되고 있는 것 같습니다! 감사합니다!! |
Beta Was this translation helpful? Give feedback.
-
UTF16 테스트케이스입니다. @kuro11pow2 #include <gtest/gtest.h>
#include <Definitions.h>
#include <UTF16Charset.h>
#include <tuple>
using namespace Euphony;
typedef std::tuple<std::string, std::string> TestParamType;
class UTF16CharsetTestFixture : public ::testing::TestWithParam<TestParamType>
{
public:
void openCharset()
{
EXPECT_EQ(charset, nullptr);
charset = new UTF16Charset();
ASSERT_NE(charset, nullptr);
}
Charset *charset = nullptr;
};
TEST_P(UTF16CharsetTestFixture, EncodingTest)
{
openCharset();
std::string source;
std::string expectedResult;
std::tie(source, expectedResult) = GetParam();
HexVector actualResult = charset->encode(source);
EXPECT_EQ(actualResult.toString(), expectedResult);
}
TEST_P(UTF16CharsetTestFixture, DecodingTest)
{
openCharset();
std::string source;
std::string expectedResult;
std::tie(expectedResult, source) = GetParam();
HexVector hv = HexVector(source);
std::string actualResult = charset->decode(hv);
EXPECT_EQ(actualResult, expectedResult);
}
INSTANTIATE_TEST_CASE_P(
ChrasetDecodingTestSuite,
UTF16CharsetTestFixture,
::testing::Values(
TestParamType("가", "ac00"),
TestParamType("나", "b098"),
TestParamType("홍길동", "d64dae38b3d9"),
TestParamType("a", "0061"),
TestParamType("b", "0062"),
TestParamType("@XYZ", "004000580059005a"),
TestParamType(".com", "002e0063006f006d"),
TestParamType("서울특별시", "c11cc6b8d2b9bcc4c2dc"),
TestParamType("010-1234-5678", "003000310030002d0031003200330034002d0035003600370038"),
TestParamType("36.5℃", "00330036002e00352103")
)); |
Beta Was this translation helpful? Give feedback.
-
hex to utf8std::string hex_to_string(const std::string& in) {
std::string output;
if ((in.length() % 2) != 0) {
throw std::runtime_error("String is not valid length ...");
}
size_t cnt = in.length() / 2;
for (size_t i = 0; cnt > i; ++i) {
uint32_t s = 0;
std::stringstream ss;
ss << std::hex << in.substr(i * 2, 2);
ss >> s;
output.push_back(static_cast<unsigned char>(s));
}
return output;
} Referencehttps://stackoverflow.com/questions/3381614/c-convert-string-to-hexadecimal-and-vice-versa |
Beta Was this translation helpful? Give feedback.
-
이런 방법도 있지 않을까요? int x;
istringstream iss("a1a56");
iss >> hex >> x;
ostringstream oss;
oss << x;
string s(oss.str()); |
Beta Was this translation helpful? Give feedback.
-
#81 로 이동. |
Beta Was this translation helpful? Give feedback.
-
Charset 인터페이스를 상속해서
euphony/euphony/src/main/cpp/core/Charset.h
Lines 7 to 16 in 5496692
아래처럼 구현할 예정입니다.
euphony/euphony/src/main/cpp/core/ASCIICharset.h
Lines 6 to 17 in 5496692
이런 헤더가 되겠죠?
UTF16Charset.h
테스트케이스는 다음을 참고해서 만들 수 있습니다.
euphony/euphony/src/main/cpp/tests/asciiCharsetTest.cpp
Lines 51 to 64 in 5496692
UTF-8
"가", "eab080"
UTF-16
"가", "ac00"
HexVector에 저장되는 값이기 때문에 이렇게 16진수로 적어주시면 될 것 같습니다!
Beta Was this translation helpful? Give feedback.
All reactions