-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create UTF8Charset to support Korean language
Co-Authored-By: SangYeon Min <[email protected]> Co-Authored-By: JK Park <[email protected]>
- Loading branch information
1 parent
3d78a92
commit 53c605f
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef EUPHONY_UTF8CHARSET_H | ||
#define EUPHONY_UTF8CHARSET_H | ||
|
||
#include "Charset.h" | ||
|
||
namespace Euphony { | ||
|
||
class UTF8Charset : public Charset { | ||
public: | ||
UTF8Charset() = default; | ||
~UTF8Charset() = default; | ||
HexVector encode(std::string src); | ||
std::string decode(const HexVector &src); | ||
}; | ||
} | ||
|
||
#endif //EUPHONY_UTF8CHARSET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "UTF8Charset.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace Euphony; | ||
|
||
HexVector UTF8Charset::encode(std::string src) { | ||
HexVector result = HexVector(src.size()); | ||
|
||
for (int i = 0; i < src.size(); i++) | ||
result.pushBack(src[i]); | ||
|
||
return result; | ||
} | ||
|
||
std::string UTF8Charset::decode(const HexVector& src) { | ||
std::string result; | ||
std::vector<u_int8_t> hexSource = src.getHexSource(); | ||
|
||
for (int i = 0; i < hexSource.size() / 2; i++) | ||
result += (hexSource[2 * i] << 4) | hexSource[2 * i + 1]; | ||
|
||
return result; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <Definitions.h> | ||
#include <UTF8Charset.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <tuple> | ||
|
||
using namespace Euphony; | ||
|
||
typedef std::tuple<std::string, std::string> TestParamType; | ||
|
||
class UTF8CharsetTestFixture : public ::testing::TestWithParam<TestParamType> { | ||
|
||
public: | ||
void openCharset() { | ||
EXPECT_EQ(charset, nullptr); | ||
charset = new UTF8Charset(); | ||
ASSERT_NE(charset, nullptr); | ||
} | ||
|
||
Charset *charset = nullptr; | ||
}; | ||
|
||
TEST_P(UTF8CharsetTestFixture, 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(UTF8CharsetTestFixture, 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, | ||
UTF8CharsetTestFixture, | ||
::testing::Values( | ||
TestParamType("a", "61"), | ||
TestParamType("b", "62"), | ||
TestParamType("가", "eab080"), | ||
TestParamType("각", "eab081"), | ||
TestParamType("나", "eb8298"), | ||
TestParamType("홍길동", "ed998deab8b8eb8f99"), | ||
TestParamType("@XYZ", "4058595a"), | ||
TestParamType(".com", "2e636f6d"), | ||
TestParamType("서울특별시", "ec849cec9ab8ed8ab9ebb384ec8b9c"), | ||
TestParamType("010-1234-5678", "3031302d313233342d35363738"), | ||
TestParamType("36.5℃", "33362e35e28483") | ||
)); |