Separate sj4charset

This commit is contained in:
Nishi 2026-06-25 09:25:46 +09:00
commit a76707537f
9 changed files with 381 additions and 340 deletions

View file

@ -12,7 +12,14 @@ option(SJ4_BUILD_TOOLS "Always build tools" OFF)
file(GLOB_RECURSE SJ4COMMON_SRCS lib/sj4common/**.c) file(GLOB_RECURSE SJ4COMMON_SRCS lib/sj4common/**.c)
add_library(sj4common STATIC ${SJ4COMMON_SRCS}) add_library(sj4common STATIC ${SJ4COMMON_SRCS})
target_include_directories(sj4common PUBLIC include/sj4common) target_include_directories(sj4common PUBLIC include/sj4common)
target_include_directories(sj4common PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB_RECURSE SJ4CHARSET_SRCS lib/sj4charset/**.c)
add_library(sj4charset STATIC ${SJ4CHARSET_SRCS})
target_include_directories(sj4charset PUBLIC include/sj4common include/sj4charset)
target_link_libraries(sj4charset PUBLIC sj4common)
if(NOT SJ4_NO_UNICODE)
target_compile_definitions(sj4charset PRIVATE UCS)
endif()
file(GLOB_RECURSE SJ4CORE_SRCS lib/sj4core/**.c) file(GLOB_RECURSE SJ4CORE_SRCS lib/sj4core/**.c)
add_library(sj4core STATIC ${SJ4CORE_SRCS}) add_library(sj4core STATIC ${SJ4CORE_SRCS})
@ -31,15 +38,13 @@ endif()
file(GLOB_RECURSE SJ4RKCV_SRCS lib/sj4rkcv/**.c) file(GLOB_RECURSE SJ4RKCV_SRCS lib/sj4rkcv/**.c)
add_library(sj4rkcv STATIC ${SJ4RKCV_SRCS}) add_library(sj4rkcv STATIC ${SJ4RKCV_SRCS})
target_include_directories(sj4rkcv PUBLIC include/sj4common include/sj4rkcv) target_include_directories(sj4rkcv PUBLIC include/sj4common include/sj4rkcv)
target_include_directories(sj4rkcv PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(sj4rkcv PUBLIC sj4common) target_link_libraries(sj4rkcv PUBLIC sj4common)
if(NOT SJ4_GLOBAL) if(NOT SJ4_GLOBAL)
file(GLOB_RECURSE SJ4LIB_SRCS lib/sj4lib/**.c) file(GLOB_RECURSE SJ4LIB_SRCS lib/sj4lib/**.c)
add_library(sj4lib STATIC ${SJ4LIB_SRCS}) add_library(sj4lib STATIC ${SJ4LIB_SRCS})
target_include_directories(sj4lib PUBLIC include/sj4common include/sj4core include/sj4lib) target_include_directories(sj4lib PUBLIC include/sj4common include/sj4core include/sj4lib)
target_include_directories(sj4lib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(sj4lib PUBLIC sj4charset sj4core)
target_link_libraries(sj4lib PUBLIC sj4common sj4core)
if(NOT SJ4_NO_UNICODE) if(NOT SJ4_NO_UNICODE)
target_compile_definitions(sj4lib PRIVATE UCS) target_compile_definitions(sj4lib PRIVATE UCS)
endif() endif()
@ -50,7 +55,7 @@ if(SJ4_BUILD_TOOLS OR (NOT CMAKE_BINARY_DIR MATCHES CMAKE_CURRENT_SOURCE_DIR AND
add_executable(sj4mkdic ${SJ4MKDIC_SRCS}) add_executable(sj4mkdic ${SJ4MKDIC_SRCS})
target_include_directories(sj4mkdic PRIVATE include/sj4common include/sj4core) target_include_directories(sj4mkdic PRIVATE include/sj4common include/sj4core)
target_compile_definitions(sj4mkdic PRIVATE ENGLISH) target_compile_definitions(sj4mkdic PRIVATE ENGLISH)
target_link_libraries(sj4mkdic PRIVATE sj4common) target_link_libraries(sj4mkdic PRIVATE sj4common sj4charset)
if(NOT SJ4_NO_UNICODE) if(NOT SJ4_NO_UNICODE)
target_compile_definitions(sj4mkdic PRIVATE UTF8) target_compile_definitions(sj4mkdic PRIVATE UTF8)
endif() endif()

View file

@ -0,0 +1,15 @@
#ifndef __SJ_CHARSET_H__
#define __SJ_CHARSET_H__
#include <sj_types.h>
#include <wchar.h>
int sj4_from_sjis(u_char* out, const u_char* in, int len);
int sj4_from_utf8(u_char* out, const u_char* in, int len);
int sj4_from_utf16(u_char* out, const u_char* in, int len);
int sj4_to_sjis(u_char* out, const u_char* in, int len);
int sj4_to_utf8(u_char* out, const u_char* in, int len);
int sj4_to_utf16(u_char* out, const u_char* in, int len);
#endif

View file

@ -0,0 +1,27 @@
#ifndef __SJ_EUC2UCS_H__
#define __SJ_EUC2UCS_H__
/*
* file:euc_jp_to_utf16_table.h
*/
/*
# EUC-JP Unicode
# Character Code Mappings
# <EUC-JP>
# <制御コード>0x000x1f, 0x7f</制御コード>
# <ASCII文字>0x200x7e</ASCII文字>
# <半角カタカナ>0x8ea10x8edf</半角カタカナ>
# <漢字>0xa1a10xf4a6, 0x8fa2af0x8fede3<漢字>
# </EUC-JP>
*/
struct _E2U_BITMAP_INDEX {
unsigned char byType; /* 1:isEmpty 2:BitmapIndex 3:Data */
unsigned long dwBitmapIndex; /* BitmapIndexへのポインタ(0の場合はBitmapIndexが存在しない) */
unsigned long dwEucJpCode; /* EUC_JP コード(未知の場合には0) */
unsigned long dwUtf16Code; /* UTF16コード(未知の場合には0) */
};
typedef struct _E2U_BITMAP_INDEX T_E2U_BITMAP_INDEX;
extern const T_E2U_BITMAP_INDEX euc_jp_to_utf16_table[];
#endif

View file

@ -0,0 +1,27 @@
#ifndef __SJ_UCS2EUC_H__
#define __SJ_UCS2EUC_H__
/*
* file:utf16_to_euc_jp_table.h
*/
/*
# Unicode EUC-JP
# Character Code Mappings
# <EUC-JP>
# <制御コード>0x000x1f, 0x7f</制御コード>
# <ASCII文字>0x200x7e</ASCII文字>
# <半角カタカナ>0x8ea10x8edf</半角カタカナ>
# <漢字>0xa1a10xf4a6, 0x8fa2af0x8fede3<漢字>
# </EUC-JP>
*/
struct _U2E_BITMAP_INDEX {
unsigned char byType; /* 1:isEmpty 2:BitmapIndex 3:Data */
unsigned long dwBitmapIndex; /* BitmapIndexへのポインタ(0の場合はBitmapIndexが存在しない) */
unsigned long dwEucJpCode; /* EUC_JP コード(未知の場合には0) */
unsigned long dwUtf16Code; /* UTF16コード(未知の場合には0) */
};
typedef struct _U2E_BITMAP_INDEX T_U2E_BITMAP_INDEX;
extern const T_U2E_BITMAP_INDEX utf16_to_euc_jp_table[];
#endif

287
lib/sj4charset/conv.c Normal file
View file

@ -0,0 +1,287 @@
#include "sj_charset.h"
#include "sj_euc2ucs.h"
#include "sj_ucs2euc.h"
#include "sj_string.h"
#ifdef UCS
static u_int ucs_to_euc(u_int in) {
if(in <= 0xffff) {
const T_U2E_BITMAP_INDEX* b = &utf16_to_euc_jp_table[(in >> 8) & 0xff];
if(b->byType == 2) {
b = &utf16_to_euc_jp_table[b->dwBitmapIndex + (in & 0xff)];
if(b->byType == 3) {
return b->dwEucJpCode;
}
}
return in;
}
return 0;
}
static u_int euc_to_ucs(u_int in) {
const T_E2U_BITMAP_INDEX* b = NULL;
if(in <= 0xff) {
b = &euc_jp_to_utf16_table[in];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
} else if(in <= 0xffff) {
b = &euc_jp_to_utf16_table[(in >> 8) & 0xff];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 0) & 0xff)];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
} else {
b = &euc_jp_to_utf16_table[(in >> 16) & 0xff];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 8) & 0xff)];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 0) & 0xff)];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
}
return 0;
}
static int eucjp_write(u_char* out, u_int n) {
if(n <= 0xff) {
*out++ = n;
return 1;
} else if(n <= 0xffff) {
*out++ = (n >> 8) & 0xff;
*out++ = (n >> 0) & 0xff;
return 2;
} else {
*out++ = (n >> 16) & 0xff;
*out++ = (n >> 8) & 0xff;
*out++ = (n >> 0) & 0xff;
return 3;
}
}
#endif
int sj4_from_sjis(u_char* out, const u_char* in, int len) {
unsigned char d[] = {0, 0};
int uf = 0;
return sj4_str_sjistoeuc(out, 0xffffff, (u_char*)in, len, d, &uf);
}
#ifdef UCS
static int utf8_later(unsigned char c) {
return 0x80 <= c && c < 0xc0;
}
#define CAST_I32(x) ((int)(x))
int sj4_from_utf8(u_char* out, const u_char* in, int len) {
const u_char* o_in = in;
u_char* o_out = out;
while((in - o_in) < len) {
u_char c = *in;
u_int n = 0;
if(c < 0x80) {
n = c;
in += 1;
} else if(0xc2 <= c && c < 0xe0) {
if(!utf8_later(in[1])) return 0;
if((in[0] & 0x1e) == 0) return 0;
n = CAST_I32(in[0] & 0x1f) << 6;
n |= CAST_I32(in[1] & 0x3f);
in += 2;
} else if(0xe0 <= c && c < 0xf0) {
if(!utf8_later(in[1]) || !utf8_later(in[2])) return 0;
if((in[0] & 0x0f) == 0 && (in[1] & 0x20) == 0) return 0;
n = CAST_I32(in[0] & 0x0f) << 12;
n |= CAST_I32(in[1] & 0x3f) << 6;
n |= CAST_I32(in[2] & 0x3f);
in += 3;
} else if(0xf0 <= c && c < 0xf8) {
if(!utf8_later(in[1]) || !utf8_later(in[2]) || !utf8_later(in[3])) return 0;
if((in[0] & 0x07) == 0 && (in[1] & 0x30) == 0) return 0;
n = CAST_I32(in[0] & 0x07) << 18;
n |= CAST_I32(in[1] & 0x3f) << 12;
n |= CAST_I32(in[2] & 0x3f) << 6;
n |= CAST_I32(in[3] & 0x3f);
in += 4;
}
n = ucs_to_euc(n);
out += eucjp_write(out, n);
}
return out - o_out;
}
static int is_high_surr(wchar_t ch) {
return 0xD800 <= ch && ch < 0xDC00;
}
static int is_low_urr(wchar_t ch) {
return 0xDC00 <= ch && ch < 0xE000;
}
int sj4_from_utf16(u_char* out, const u_char* in, int len) {
const wchar_t* w_in = (const wchar_t*)in;
const wchar_t* o_in = w_in;
u_char* o_out = out;
while((w_in - o_in) < len) {
u_int n = 0;
if(is_high_surr(w_in[0])) {
if(is_low_urr(w_in[1])) {
n = 0x10000 + CAST_I32(w_in[0] - 0xd800) * 0x400 + CAST_I32(w_in[1] - 0xdc00);
w_in += 2;
} else if(w_in[1] == 0) {
n = w_in[0];
w_in += 2;
} else {
return 0;
}
} else if(is_low_urr(w_in[0])) {
if(w_in[1] == 0) {
n = w_in[0];
w_in += 2;
} else {
return 0;
}
} else {
n = w_in[0];
w_in += 1;
}
n = ucs_to_euc(n);
out += eucjp_write(out, n);
}
return out - o_out;
}
static u_int eucjp_read(const u_char* in) {
u_char c = *in;
u_int n = 0;
if(c <= 0x7f) {
n = c;
} else if(c != 0x8f) {
n = CAST_I32(in[0]) << 8;
n |= CAST_I32(in[1]);
} else {
n = CAST_I32(in[0]) << 16;
n |= CAST_I32(in[1]) << 8;
n |= CAST_I32(in[2]);
}
return n;
}
static int eucjp_codesize(u_int n) {
if(n <= 0xff) {
return 1;
} else if(n <= 0xffff) {
return 2;
} else {
return 3;
}
}
#endif
int sj4_to_sjis(u_char* out, const u_char* in, int len) {
unsigned char d[] = {0, 0};
int uf = 0;
return sj4_str_euctosjis(out, 0xffffff, (u_char*)in, len, d, &uf);
}
#ifdef UCS
int sj4_to_utf8(u_char* out, const u_char* in, int len) {
const u_char* o_in = in;
u_char* o_out = out;
while((in - o_in) < len) {
int i, j = 0;
u_int n = eucjp_read(in);
in += eucjp_codesize(n);
n = euc_to_ucs(n);
if(n >= 0x10000) {
*out++ = ((n >> (6 * 3)) & 7) | 0xf0;
j = 3;
} else if(n >= 0x800) {
*out++ = ((n >> (6 * 2)) & 15) | 0xe0;
j = 2;
} else if(n >= 0x80) {
*out++ = ((n >> (6 * 1)) & 31) | 0xc0;
j = 1;
} else {
*out++ = n;
}
for(i = 0; i < j; i++) {
*out++ = ((n >> (6 * (j - i - 1))) & 63) | 0x80;
}
}
return out - o_out;
}
int sj4_to_utf16(u_char* out, const u_char* in, int len) {
wchar_t* w_out = (wchar_t*)out;
const u_char* o_in = in;
wchar_t* o_out = w_out;
while((in - o_in) < len) {
int i, j = 0;
u_int n = eucjp_read(in);
in += eucjp_codesize(n);
n = euc_to_ucs(n);
if(n < 0x10000) {
*w_out++ = n;
} else {
*w_out++ = (n - 0x10000) / 0x400 + 0xd800;
*w_out++ = (n - 0x10000) % 0x400 + 0xdc00;
}
}
return w_out - o_out;
}
#endif

View file

@ -1,26 +1,7 @@
/* #include "sj_euc2ucs.h"
* file:euc_jp_to_utf16_table.h
*/
/*
# EUC-JP Unicode
# Character Code Mappings
# <EUC-JP>
# <制御コード>0x000x1f, 0x7f</制御コード>
# <ASCII文字>0x200x7e</ASCII文字>
# <半角カタカナ>0x8ea10x8edf</半角カタカナ>
# <漢字>0xa1a10xf4a6, 0x8fa2af0x8fede3<漢字>
# </EUC-JP>
*/
struct _E2U_BITMAP_INDEX
{
unsigned char byType; /* 1:isEmpty 2:BitmapIndex 3:Data */
unsigned long dwBitmapIndex; /* BitmapIndexへのポインタ(0の場合はBitmapIndexが存在しない) */
unsigned long dwEucJpCode; /* EUC_JP コード(未知の場合には0) */
unsigned long dwUtf16Code; /* UTF16コード(未知の場合には0) */
};
typedef struct _E2U_BITMAP_INDEX T_E2U_BITMAP_INDEX;
static const T_E2U_BITMAP_INDEX euc_jp_to_utf16_table[] = { #ifdef UCS
const T_E2U_BITMAP_INDEX euc_jp_to_utf16_table[] = {
{3, 0x00000000, 0x000000, 0x0000}, {3, 0x00000000, 0x000001, 0x0001}, {3, 0x00000000, 0x000000, 0x0000}, {3, 0x00000000, 0x000001, 0x0001},
{3, 0x00000000, 0x000002, 0x0002}, {3, 0x00000000, 0x000003, 0x0003}, {3, 0x00000000, 0x000002, 0x0002}, {3, 0x00000000, 0x000003, 0x0003},
{3, 0x00000000, 0x000004, 0x0004}, {3, 0x00000000, 0x000005, 0x0005}, {3, 0x00000000, 0x000004, 0x0004}, {3, 0x00000000, 0x000005, 0x0005},
@ -18967,3 +18948,4 @@ static const T_E2U_BITMAP_INDEX euc_jp_to_utf16_table[] = {
{1, 0x00000000, 0x000000, 0x0000}, {1, 0x00000000, 0x000000, 0x0000}, {1, 0x00000000, 0x000000, 0x0000}, {1, 0x00000000, 0x000000, 0x0000},
{1, 0x00000000, 0x000000, 0x0000} {1, 0x00000000, 0x000000, 0x0000}
}; };
#endif

File diff suppressed because one or more lines are too long

View file

@ -2,12 +2,9 @@
#include <sj_kanakan.h> #include <sj_kanakan.h>
#include <sj_string.h> #include <sj_string.h>
#include <stdlib.h> #include <sj_charset.h>
#ifdef UCS #include <stdlib.h>
#include <sj_euc2ucs.h>
#include <sj_ucs2euc.h>
#endif
struct sj4lib { struct sj4lib {
Sj4Context* ctx; Sj4Context* ctx;
@ -22,288 +19,6 @@ struct sj4lib {
Sj4Kouho* kouho; Sj4Kouho* kouho;
}; };
#ifdef UCS
static u_int ucs_to_euc(u_int in) {
if(in <= 0xffff) {
const T_U2E_BITMAP_INDEX* b = &utf16_to_euc_jp_table[(in >> 8) & 0xff];
if(b->byType == 2) {
b = &utf16_to_euc_jp_table[b->dwBitmapIndex + (in & 0xff)];
if(b->byType == 3) {
return b->dwEucJpCode;
}
}
return in;
}
return 0;
}
static u_int euc_to_ucs(u_int in) {
const T_E2U_BITMAP_INDEX* b = NULL;
if(in <= 0xff) {
b = &euc_jp_to_utf16_table[in];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
} else if(in <= 0xffff) {
b = &euc_jp_to_utf16_table[(in >> 8) & 0xff];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 0) & 0xff)];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
} else {
b = &euc_jp_to_utf16_table[(in >> 16) & 0xff];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 8) & 0xff)];
if(b->byType != 2) return 0;
b = &euc_jp_to_utf16_table[b->dwBitmapIndex + ((in >> 0) & 0xff)];
if(b->byType != 3) return 0;
return b->dwUtf16Code;
}
return 0;
}
static int eucjp_write(u_char* out, u_int n) {
if(n <= 0xff) {
*out++ = n;
return 1;
} else if(n <= 0xffff) {
*out++ = (n >> 8) & 0xff;
*out++ = (n >> 0) & 0xff;
return 2;
} else {
*out++ = (n >> 16) & 0xff;
*out++ = (n >> 8) & 0xff;
*out++ = (n >> 0) & 0xff;
return 3;
}
}
#endif
static int from_sjis(u_char* out, const u_char* in, int len) {
unsigned char d[] = {0, 0};
int uf = 0;
return sj4_str_sjistoeuc(out, SJ4BUFSZ, (u_char*)in, len, d, &uf);
}
#ifdef UCS
static int utf8_later(unsigned char c) {
return 0x80 <= c && c < 0xc0;
}
#define CAST_I32(x) ((int)(x))
static int from_utf8(u_char* out, const u_char* in, int len) {
const u_char* o_in = in;
u_char* o_out = out;
while((in - o_in) < len) {
u_char c = *in;
u_int n = 0;
if(c < 0x80) {
n = c;
in += 1;
} else if(0xc2 <= c && c < 0xe0) {
if(!utf8_later(in[1])) return 0;
if((in[0] & 0x1e) == 0) return 0;
n = CAST_I32(in[0] & 0x1f) << 6;
n |= CAST_I32(in[1] & 0x3f);
in += 2;
} else if(0xe0 <= c && c < 0xf0) {
if(!utf8_later(in[1]) || !utf8_later(in[2])) return 0;
if((in[0] & 0x0f) == 0 && (in[1] & 0x20) == 0) return 0;
n = CAST_I32(in[0] & 0x0f) << 12;
n |= CAST_I32(in[1] & 0x3f) << 6;
n |= CAST_I32(in[2] & 0x3f);
in += 3;
} else if(0xf0 <= c && c < 0xf8) {
if(!utf8_later(in[1]) || !utf8_later(in[2]) || !utf8_later(in[3])) return 0;
if((in[0] & 0x07) == 0 && (in[1] & 0x30) == 0) return 0;
n = CAST_I32(in[0] & 0x07) << 18;
n |= CAST_I32(in[1] & 0x3f) << 12;
n |= CAST_I32(in[2] & 0x3f) << 6;
n |= CAST_I32(in[3] & 0x3f);
in += 4;
}
n = ucs_to_euc(n);
out += eucjp_write(out, n);
}
return out - o_out;
}
int is_high_surr(wchar_t ch) {
return 0xD800 <= ch && ch < 0xDC00;
}
int is_low_urr(wchar_t ch) {
return 0xDC00 <= ch && ch < 0xE000;
}
static int from_utf16(u_char* out, const u_char* in, int len) {
const wchar_t* w_in = (const wchar_t*)in;
const wchar_t* o_in = w_in;
u_char* o_out = out;
while((w_in - o_in) < len) {
u_int n = 0;
if(is_high_surr(w_in[0])) {
if(is_low_urr(w_in[1])) {
n = 0x10000 + CAST_I32(w_in[0] - 0xd800) * 0x400 + CAST_I32(w_in[1] - 0xdc00);
w_in += 2;
} else if(w_in[1] == 0) {
n = w_in[0];
w_in += 2;
} else {
return 0;
}
} else if(is_low_urr(w_in[0])) {
if(w_in[1] == 0) {
n = w_in[0];
w_in += 2;
} else {
return 0;
}
} else {
n = w_in[0];
w_in += 1;
}
n = ucs_to_euc(n);
out += eucjp_write(out, n);
}
return out - o_out;
}
static u_int eucjp_read(const u_char* in) {
u_char c = *in;
u_int n = 0;
if(c <= 0x7f) {
n = c;
} else if(c != 0x8f) {
n = CAST_I32(in[0]) << 8;
n |= CAST_I32(in[1]);
} else {
n = CAST_I32(in[0]) << 16;
n |= CAST_I32(in[1]) << 8;
n |= CAST_I32(in[2]);
}
return n;
}
static int eucjp_codesize(u_int n) {
if(n <= 0xff) {
return 1;
} else if(n <= 0xffff) {
return 2;
} else {
return 3;
}
}
#endif
static int to_sjis(u_char* out, const u_char* in, int len) {
unsigned char d[] = {0, 0};
int uf = 0;
return sj4_str_euctosjis(out, SJ4BUFSZ, (u_char*)in, len, d, &uf);
}
#ifdef UCS
static int to_utf8(u_char* out, const u_char* in, int len) {
const u_char* o_in = in;
u_char* o_out = out;
while((in - o_in) < len) {
int i, j = 0;
u_int n = eucjp_read(in);
in += eucjp_codesize(n);
n = euc_to_ucs(n);
if(n >= 0x10000) {
*out++ = ((n >> (6 * 3)) & 7) | 0xf0;
j = 3;
} else if(n >= 0x800) {
*out++ = ((n >> (6 * 2)) & 15) | 0xe0;
j = 2;
} else if(n >= 0x80) {
*out++ = ((n >> (6 * 1)) & 31) | 0xc0;
j = 1;
} else {
*out++ = n;
}
for(i = 0; i < j; i++) {
*out++ = ((n >> (6 * (j - i - 1))) & 63) | 0x80;
}
}
return out - o_out;
}
static int to_utf16(u_char* out, const u_char* in, int len) {
wchar_t* w_out = (wchar_t*)out;
const u_char* o_in = in;
wchar_t* o_out = w_out;
while((in - o_in) < len) {
int i, j = 0;
u_int n = eucjp_read(in);
in += eucjp_codesize(n);
n = euc_to_ucs(n);
if(n < 0x10000) {
*w_out++ = n;
} else {
*w_out++ = (n - 0x10000) / 0x400 + 0xd800;
*w_out++ = (n - 0x10000) % 0x400 + 0xdc00;
}
}
return w_out - o_out;
}
#endif
Sj4Lib* sj4_open(int charset, const char* dic) { Sj4Lib* sj4_open(int charset, const char* dic) {
Sj4Lib* ctx; Sj4Lib* ctx;
@ -329,18 +44,18 @@ Sj4Lib* sj4_open(int charset, const char* dic) {
if(ctx->charset == SJ4EUCJP) { \ if(ctx->charset == SJ4EUCJP) { \
memcpy(to, from, len); \ memcpy(to, from, len); \
} else if(ctx->charset == SJ4SJIS) { \ } else if(ctx->charset == SJ4SJIS) { \
len = mode##_sjis(to, from, len); \ len = sj4_##mode##_sjis(to, from, len); \
} else if(ctx->charset == SJ4UTF8) { \ } else if(ctx->charset == SJ4UTF8) { \
len = mode##_utf8(to, from, len); \ len = sj4_##mode##_utf8(to, from, len); \
} else if(ctx->charset == SJ4UTF16) { \ } else if(ctx->charset == SJ4UTF16) { \
len = mode##_utf16(to, from, len); \ len = sj4_##mode##_utf16(to, from, len); \
} }
#else #else
#define ICONV(to, from, len, mode) \ #define ICONV(to, from, len, mode) \
if(ctx->charset == SJ4EUCJP) { \ if(ctx->charset == SJ4EUCJP) { \
memcpy(to, from, len); \ memcpy(to, from, len); \
} else if(ctx->charset == SJ4SJIS) { \ } else if(ctx->charset == SJ4SJIS) { \
len = mode##_sjis(to, from, len); \ len = sj4_##mode##_sjis(to, from, len); \
} }
#endif #endif

View file

@ -2,4 +2,4 @@
while [ ! -d .git ]; do while [ ! -d .git ]; do
cd .. cd ..
done done
clang-format --verbose -i `find src lib include "(" -name "*.c" -or -name "*.h" ")" -and -not -name sj_euc2ucs.h -and -not -name sj_ucs2euc.h -and -not -name maindic"*".c` clang-format --verbose -i `find src lib include "(" -name "*.c" -or -name "*.h" ")" -and -not -name euc2ucs.c -and -not -name ucs2euc.c -and -not -name maindic"*".c`