Skip to content

Commit

Permalink
Workaround for MSVC compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
mete0r committed Mar 6, 2019
1 parent 74528b6 commit 1e85ca2
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 57 deletions.
1 change: 0 additions & 1 deletion hypua2jamo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
int hypua_p2jd_ucs4_encode(const unsigned int *src, int srclen, unsigned int *dst);
int hypua_p2jd_ucs2_calcsize(const unsigned short *src, int srclen);
int hypua_p2jd_ucs2_encode(const unsigned short *src, int srclen, unsigned short *dst);
void hypua_p2jd_ucs2_test();
int hypua_jc2p_ucs4_calcsize(const unsigned int *src, int srclen);
int hypua_jc2p_ucs4_decode(const unsigned int *src, int srclen, unsigned int *dst);
Expand Down
47 changes: 42 additions & 5 deletions src/hypua2jamo-c/p2jc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,61 @@ typedef unsigned int uint32_t;


#include "p2jc-table.h"
#include "p2jx.hpp"


template <typename codepoint_t>
inline int p2jc_calcsize(const codepoint_t *src, int srclen) {
const unsigned short *jamo_seq;
int ret = 0;
const codepoint_t *src_end = src + srclen;
for (; src < src_end; ++src) {
jamo_seq = lookup(*src);
if (jamo_seq != NULL) {
ret += jamo_seq[0];
} else {
ret += 1;
}
}
return ret;
}


template <typename codepoint_t>
inline int p2jc_encode(const codepoint_t *src, int srclen, codepoint_t *dst) {
const unsigned short *jamo_seq;
int jamo_len;
const codepoint_t *src_end = src + srclen;
const codepoint_t *dst_start = dst;
for (; src < src_end; ++src) {
jamo_seq = lookup(*src);
if (jamo_seq == NULL) {
*(dst++) = *src;
} else {
jamo_len = *(jamo_seq++);
while (jamo_len-- > 0) {
*(dst++) = *(jamo_seq++);
}
}
}
return dst - dst_start;
}


extern "C" int hypua_p2jc_ucs2_calcsize(const uint16_t *src, int srclen) {
return calcsize(src, srclen);
return p2jc_calcsize(src, srclen);
}


extern "C" int hypua_p2jc_ucs2_encode(const uint16_t *src, int srclen, uint16_t *dst) {
return encode(src, srclen, dst);
return p2jc_encode(src, srclen, dst);
}


extern "C" int hypua_p2jc_ucs4_calcsize(const uint32_t *src, int srclen) {
return calcsize(src, srclen);
return p2jc_calcsize(src, srclen);
}


extern "C" int hypua_p2jc_ucs4_encode(const uint32_t *src, int srclen, uint32_t *dst) {
return encode(src, srclen, dst);
return p2jc_encode(src, srclen, dst);
}
64 changes: 53 additions & 11 deletions src/hypua2jamo-c/p2jd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,77 @@ typedef unsigned int uint32_t;


#include "p2jd-table.h"
#include "p2jx.hpp"


template <typename codepoint_t>
inline int p2jd_calcsize(const codepoint_t *src, int srclen) {
const unsigned short *jamo_seq;
int ret = 0;
const codepoint_t *src_end = src + srclen;
for (; src < src_end; ++src) {
jamo_seq = lookup(*src);
if (jamo_seq != NULL) {
ret += jamo_seq[0];
} else {
ret += 1;
}
}
return ret;
}


template <typename codepoint_t>
inline int p2jd_encode(const codepoint_t *src, int srclen, codepoint_t *dst) {
const unsigned short *jamo_seq;
int jamo_len;
const codepoint_t *src_end = src + srclen;
const codepoint_t *dst_start = dst;
for (; src < src_end; ++src) {
jamo_seq = lookup(*src);
if (jamo_seq == NULL) {
*(dst++) = *src;
} else {
jamo_len = *(jamo_seq++);
while (jamo_len-- > 0) {
*(dst++) = *(jamo_seq++);
}
}
}
return dst - dst_start;
}


extern "C" int hypua_p2jd_ucs2_calcsize(const uint16_t *src, int srclen) {
return calcsize(src, srclen);
return p2jd_calcsize(src, srclen);
}


extern "C" int hypua_p2jd_ucs2_encode(const uint16_t *src, int srclen, uint16_t *dst) {
return encode(src, srclen, dst);
return p2jd_encode(src, srclen, dst);
}


extern "C" int hypua_p2jd_ucs4_calcsize(const uint32_t *src, int srclen) {
return calcsize(src, srclen);
return p2jd_calcsize(src, srclen);
}


extern "C" int hypua_p2jd_ucs4_encode(const uint32_t *src, int srclen, uint32_t *dst) {
return encode(src, srclen, dst);
return p2jd_encode(src, srclen, dst);
}


extern "C" void hypua_p2jd_ucs2_test() {
extern "C" void hypua_p2jd_ucs2_debug() {
uint16_t src = 0xF7CA;
int size = hypua_p2jd_ucs2_calcsize(&src, 1);
void *buf = malloc(size);
int n_encoded = hypua_p2jd_ucs2_encode(&src, 1, (uint16_t*)buf);
printf("hypua_p2jd_ucs2_test: size=%d encoded=%d\n", size, n_encoded);
printf("p2jd_F7CA: len=%d\n", p2jd_F7CA[0]);

printf("p2jd_F7CA: 0x%p len=%d\n", p2jd_F7CA, p2jd_F7CA[0]);
const uint16_t *p2jd = lookup(src);
printf("p2jdfound: 0x%p len=%d\n", p2jd, p2jd[0]);

int buf_size = p2jd_calcsize(&src, 1);
printf("p2jd_calcsize: size=%d\n", buf_size);
uint16_t *buf = (uint16_t *) malloc(buf_size * sizeof(uint16_t));
int n_encoded = p2jd_encode(&src, 1, (uint16_t*)buf);
free(buf);
printf("p2jd_encode: encoded=%d\n", n_encoded);
}
36 changes: 0 additions & 36 deletions src/hypua2jamo-c/p2jx.hpp

This file was deleted.

4 changes: 0 additions & 4 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ def test_f7ca(self):
jamo = encoder.encode(u'\uf7ca', final=True)
self.assertEqual(u'\u1109\u1109', jamo)

def test_hypua_p2jd_ucs2(self):
from hypua2jamo._cffi import lib
lib.hypua_p2jd_ucs2_test()


class ComposedJamoEncoderImplementationOnCythonTest(
TestCase,
Expand Down

0 comments on commit 1e85ca2

Please sign in to comment.