ホーム › Globalization › ucnv_toUnicode
ucnv_toUnicode
関数バイト列からUnicodeへストリーム変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
void ucnv_toUnicode(
UConverter* converter,
WORD** target,
const WORD* targetLimit,
const CHAR** source,
LPCSTR sourceLimit,
INT* offsets,
CHAR flush,
UErrorCode* err
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| converter | UConverter* | inout | 外部符号化→Unicode変換に用いるコンバーターへのポインタ。 |
| target | WORD** | inout | 出力Unicodeバッファ位置を指すポインタのポインタ。書き込みに応じて進む。 |
| targetLimit | WORD* | in | 出力バッファの終端を示すポインタ。 |
| source | CHAR** | in | 入力バイト列位置を指すポインタのポインタ。読み取りに応じて進む。 |
| sourceLimit | LPCSTR | in | 入力バイト列の終端を示すポインタ。 |
| offsets | INT* | inout | 出力各コードユニットに対応する入力オフセットを受け取る配列。NULL可。 |
| flush | CHAR | in | 残存入力を確定するか(TRUE)、継続呼び出しか(FALSE)を示すブール値。 |
| err | UErrorCode* | inout | エラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。 |
戻り値の型: void
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
void ucnv_toUnicode(
UConverter* converter,
WORD** target,
const WORD* targetLimit,
const CHAR** source,
LPCSTR sourceLimit,
INT* offsets,
CHAR flush,
UErrorCode* err
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void ucnv_toUnicode(
ref IntPtr converter, // UConverter* in/out
IntPtr target, // WORD** in/out
ref ushort targetLimit, // WORD*
IntPtr source, // CHAR**
[MarshalAs(UnmanagedType.LPStr)] string sourceLimit, // LPCSTR
ref int offsets, // INT* in/out
sbyte flush, // CHAR
ref int err // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub ucnv_toUnicode(
ByRef converter As IntPtr, ' UConverter* in/out
target As IntPtr, ' WORD** in/out
ByRef targetLimit As UShort, ' WORD*
source As IntPtr, ' CHAR**
<MarshalAs(UnmanagedType.LPStr)> sourceLimit As String, ' LPCSTR
ByRef offsets As Integer, ' INT* in/out
flush As SByte, ' CHAR
ByRef err As Integer ' UErrorCode* in/out
)
End Sub' converter : UConverter* in/out
' target : WORD** in/out
' targetLimit : WORD*
' source : CHAR**
' sourceLimit : LPCSTR
' offsets : INT* in/out
' flush : CHAR
' err : UErrorCode* in/out
Declare PtrSafe Sub ucnv_toUnicode Lib "icuuc" ( _
ByRef converter As LongPtr, _
ByVal target As LongPtr, _
ByRef targetLimit As Integer, _
ByVal source As LongPtr, _
ByVal sourceLimit As String, _
ByRef offsets As Long, _
ByVal flush As Byte, _
ByRef err As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ucnv_toUnicode = ctypes.cdll.icuuc.ucnv_toUnicode
ucnv_toUnicode.restype = None
ucnv_toUnicode.argtypes = [
ctypes.c_void_p, # converter : UConverter* in/out
ctypes.c_void_p, # target : WORD** in/out
ctypes.POINTER(ctypes.c_ushort), # targetLimit : WORD*
ctypes.c_void_p, # source : CHAR**
wintypes.LPCSTR, # sourceLimit : LPCSTR
ctypes.POINTER(ctypes.c_int), # offsets : INT* in/out
ctypes.c_byte, # flush : CHAR
ctypes.c_void_p, # err : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ucnv_toUnicode = Fiddle::Function.new(
lib['ucnv_toUnicode'],
[
Fiddle::TYPE_VOIDP, # converter : UConverter* in/out
Fiddle::TYPE_VOIDP, # target : WORD** in/out
Fiddle::TYPE_VOIDP, # targetLimit : WORD*
Fiddle::TYPE_VOIDP, # source : CHAR**
Fiddle::TYPE_VOIDP, # sourceLimit : LPCSTR
Fiddle::TYPE_VOIDP, # offsets : INT* in/out
Fiddle::TYPE_CHAR, # flush : CHAR
Fiddle::TYPE_VOIDP, # err : UErrorCode* in/out
],
Fiddle::TYPE_VOID, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn ucnv_toUnicode(
converter: *mut isize, // UConverter* in/out
target: *mut *mut u16, // WORD** in/out
targetLimit: *const u16, // WORD*
source: *const *const i8, // CHAR**
sourceLimit: *const u8, // LPCSTR
offsets: *mut i32, // INT* in/out
flush: i8, // CHAR
err: *mut i32 // UErrorCode* in/out
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void ucnv_toUnicode(ref IntPtr converter, IntPtr target, ref ushort targetLimit, IntPtr source, [MarshalAs(UnmanagedType.LPStr)] string sourceLimit, ref int offsets, sbyte flush, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_toUnicode' -Namespace Win32 -PassThru
# $api::ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)#uselib "icuuc.dll"
#func global ucnv_toUnicode "ucnv_toUnicode" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ucnv_toUnicode varptr(converter), varptr(target), varptr(targetLimit), varptr(source), sourceLimit, varptr(offsets), flush, varptr(err)
; converter : UConverter* in/out -> "sptr"
; target : WORD** in/out -> "sptr"
; targetLimit : WORD* -> "sptr"
; source : CHAR** -> "sptr"
; sourceLimit : LPCSTR -> "sptr"
; offsets : INT* in/out -> "sptr"
; flush : CHAR -> "sptr"
; err : UErrorCode* in/out -> "sptr"出力引数:
#uselib "icuuc.dll" #func global ucnv_toUnicode "ucnv_toUnicode" var, var, var, var, str, var, int, var ; ucnv_toUnicode converter, target, targetLimit, source, sourceLimit, offsets, flush, err ; converter : UConverter* in/out -> "var" ; target : WORD** in/out -> "var" ; targetLimit : WORD* -> "var" ; source : CHAR** -> "var" ; sourceLimit : LPCSTR -> "str" ; offsets : INT* in/out -> "var" ; flush : CHAR -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #func global ucnv_toUnicode "ucnv_toUnicode" sptr, sptr, sptr, sptr, str, sptr, int, sptr ; ucnv_toUnicode varptr(converter), varptr(target), varptr(targetLimit), varptr(source), sourceLimit, varptr(offsets), flush, varptr(err) ; converter : UConverter* in/out -> "sptr" ; target : WORD** in/out -> "sptr" ; targetLimit : WORD* -> "sptr" ; source : CHAR** -> "sptr" ; sourceLimit : LPCSTR -> "str" ; offsets : INT* in/out -> "sptr" ; flush : CHAR -> "int" ; err : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void ucnv_toUnicode(UConverter* converter, WORD** target, WORD* targetLimit, CHAR** source, LPCSTR sourceLimit, INT* offsets, CHAR flush, UErrorCode* err) #uselib "icuuc.dll" #func global ucnv_toUnicode "ucnv_toUnicode" var, var, var, var, str, var, int, var ; ucnv_toUnicode converter, target, targetLimit, source, sourceLimit, offsets, flush, err ; converter : UConverter* in/out -> "var" ; target : WORD** in/out -> "var" ; targetLimit : WORD* -> "var" ; source : CHAR** -> "var" ; sourceLimit : LPCSTR -> "str" ; offsets : INT* in/out -> "var" ; flush : CHAR -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void ucnv_toUnicode(UConverter* converter, WORD** target, WORD* targetLimit, CHAR** source, LPCSTR sourceLimit, INT* offsets, CHAR flush, UErrorCode* err) #uselib "icuuc.dll" #func global ucnv_toUnicode "ucnv_toUnicode" intptr, intptr, intptr, intptr, str, intptr, int, intptr ; ucnv_toUnicode varptr(converter), varptr(target), varptr(targetLimit), varptr(source), sourceLimit, varptr(offsets), flush, varptr(err) ; converter : UConverter* in/out -> "intptr" ; target : WORD** in/out -> "intptr" ; targetLimit : WORD* -> "intptr" ; source : CHAR** -> "intptr" ; sourceLimit : LPCSTR -> "str" ; offsets : INT* in/out -> "intptr" ; flush : CHAR -> "int" ; err : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procucnv_toUnicode = icuuc.NewProc("ucnv_toUnicode")
)
// converter (UConverter* in/out), target (WORD** in/out), targetLimit (WORD*), source (CHAR**), sourceLimit (LPCSTR), offsets (INT* in/out), flush (CHAR), err (UErrorCode* in/out)
r1, _, err := procucnv_toUnicode.Call(
uintptr(converter),
uintptr(target),
uintptr(targetLimit),
uintptr(source),
uintptr(unsafe.Pointer(windows.BytePtrFromString(sourceLimit))),
uintptr(offsets),
uintptr(flush),
uintptr(err),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure ucnv_toUnicode(
converter: Pointer; // UConverter* in/out
target: Pointer; // WORD** in/out
targetLimit: Pointer; // WORD*
source: Pointer; // CHAR**
sourceLimit: PAnsiChar; // LPCSTR
offsets: Pointer; // INT* in/out
flush: Shortint; // CHAR
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'ucnv_toUnicode';result := DllCall("icuuc\ucnv_toUnicode"
, "Ptr", converter ; UConverter* in/out
, "Ptr", target ; WORD** in/out
, "Ptr", targetLimit ; WORD*
, "Ptr", source ; CHAR**
, "AStr", sourceLimit ; LPCSTR
, "Ptr", offsets ; INT* in/out
, "Char", flush ; CHAR
, "Ptr", err ; UErrorCode* in/out
, "Cdecl Int") ; return: void●ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err) = DLL("icuuc.dll", "int ucnv_toUnicode(void*, void*, void*, void*, char*, void*, char, void*)")
# 呼び出し: ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
# converter : UConverter* in/out -> "void*"
# target : WORD** in/out -> "void*"
# targetLimit : WORD* -> "void*"
# source : CHAR** -> "void*"
# sourceLimit : LPCSTR -> "char*"
# offsets : INT* in/out -> "void*"
# flush : CHAR -> "char"
# err : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "icuuc" fn ucnv_toUnicode(
converter: [*c]isize, // UConverter* in/out
target: [*c][*c]u16, // WORD** in/out
targetLimit: [*c]u16, // WORD*
source: [*c][*c]i8, // CHAR**
sourceLimit: [*c]const u8, // LPCSTR
offsets: [*c]i32, // INT* in/out
flush: i8, // CHAR
err: [*c]i32 // UErrorCode* in/out
) callconv(.c) void;proc ucnv_toUnicode(
`converter`: ptr int, # UConverter* in/out
target: ptr uint16, # WORD** in/out
targetLimit: ptr uint16, # WORD*
source: ptr int8, # CHAR**
sourceLimit: cstring, # LPCSTR
offsets: ptr int32, # INT* in/out
flush: int8, # CHAR
err: ptr int32 # UErrorCode* in/out
) {.importc: "ucnv_toUnicode", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
void ucnv_toUnicode(
ptrdiff_t* converter, // UConverter* in/out
ushort** target, // WORD** in/out
ushort* targetLimit, // WORD*
byte** source, // CHAR**
const(char)* sourceLimit, // LPCSTR
int* offsets, // INT* in/out
byte flush, // CHAR
int* err // UErrorCode* in/out
);ccall((:ucnv_toUnicode, "icuuc.dll"), Cvoid,
(Ptr{Int}, Ptr{UInt16}, Ptr{UInt16}, Ptr{Int8}, Cstring, Ptr{Int32}, Int8, Ptr{Int32}),
converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
# converter : UConverter* in/out -> Ptr{Int}
# target : WORD** in/out -> Ptr{UInt16}
# targetLimit : WORD* -> Ptr{UInt16}
# source : CHAR** -> Ptr{Int8}
# sourceLimit : LPCSTR -> Cstring
# offsets : INT* in/out -> Ptr{Int32}
# flush : CHAR -> Int8
# err : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
void ucnv_toUnicode(
intptr_t* converter,
uint16_t** target,
uint16_t* targetLimit,
int8_t** source,
const char* sourceLimit,
int32_t* offsets,
int8_t flush,
int32_t* err);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
-- converter : UConverter* in/out
-- target : WORD** in/out
-- targetLimit : WORD*
-- source : CHAR**
-- sourceLimit : LPCSTR
-- offsets : INT* in/out
-- flush : CHAR
-- err : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_toUnicode = lib.func('__cdecl', 'ucnv_toUnicode', 'void', ['intptr_t *', 'uint16_t *', 'uint16_t *', 'int8_t *', 'str', 'int32_t *', 'int8_t', 'int32_t *']);
// ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
// converter : UConverter* in/out -> 'intptr_t *'
// target : WORD** in/out -> 'uint16_t *'
// targetLimit : WORD* -> 'uint16_t *'
// source : CHAR** -> 'int8_t *'
// sourceLimit : LPCSTR -> 'str'
// offsets : INT* in/out -> 'int32_t *'
// flush : CHAR -> 'int8_t'
// err : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
ucnv_toUnicode: { parameters: ["pointer", "pointer", "pointer", "pointer", "buffer", "pointer", "i8", "pointer"], result: "void" },
});
// lib.symbols.ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
// converter : UConverter* in/out -> "pointer"
// target : WORD** in/out -> "pointer"
// targetLimit : WORD* -> "pointer"
// source : CHAR** -> "pointer"
// sourceLimit : LPCSTR -> "buffer"
// offsets : INT* in/out -> "pointer"
// flush : CHAR -> "i8"
// err : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void ucnv_toUnicode(
intptr_t* converter,
uint16_t** target,
uint16_t* targetLimit,
int8_t** source,
const char* sourceLimit,
int32_t* offsets,
int8_t flush,
int32_t* err);
C, "icuuc.dll");
// $ffi->ucnv_toUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err);
// converter : UConverter* in/out
// target : WORD** in/out
// targetLimit : WORD*
// source : CHAR**
// sourceLimit : LPCSTR
// offsets : INT* in/out
// flush : CHAR
// err : UErrorCode* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Icuuc extends Library {
Icuuc INSTANCE = Native.load("icuuc", Icuuc.class);
void ucnv_toUnicode(
LongByReference converter, // UConverter* in/out
Pointer target, // WORD** in/out
ShortByReference targetLimit, // WORD*
Pointer source, // CHAR**
String sourceLimit, // LPCSTR
IntByReference offsets, // INT* in/out
byte flush, // CHAR
IntByReference err // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun ucnv_toUnicode = ucnv_toUnicode(
converter : LibC::SSizeT*, # UConverter* in/out
target : UInt16**, # WORD** in/out
targetLimit : UInt16*, # WORD*
source : Int8**, # CHAR**
sourceLimit : UInt8*, # LPCSTR
offsets : Int32*, # INT* in/out
flush : Int8, # CHAR
err : Int32* # UErrorCode* in/out
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ucnv_toUnicodeNative = Void Function(Pointer<IntPtr>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Int8>, Pointer<Utf8>, Pointer<Int32>, Int8, Pointer<Int32>);
typedef ucnv_toUnicodeDart = void Function(Pointer<IntPtr>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Int8>, Pointer<Utf8>, Pointer<Int32>, int, Pointer<Int32>);
final ucnv_toUnicode = DynamicLibrary.open('icuuc.dll')
.lookupFunction<ucnv_toUnicodeNative, ucnv_toUnicodeDart>('ucnv_toUnicode');
// converter : UConverter* in/out -> Pointer<IntPtr>
// target : WORD** in/out -> Pointer<Uint16>
// targetLimit : WORD* -> Pointer<Uint16>
// source : CHAR** -> Pointer<Int8>
// sourceLimit : LPCSTR -> Pointer<Utf8>
// offsets : INT* in/out -> Pointer<Int32>
// flush : CHAR -> Int8
// err : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure ucnv_toUnicode(
converter: Pointer; // UConverter* in/out
target: Pointer; // WORD** in/out
targetLimit: Pointer; // WORD*
source: Pointer; // CHAR**
sourceLimit: PAnsiChar; // LPCSTR
offsets: Pointer; // INT* in/out
flush: Shortint; // CHAR
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'ucnv_toUnicode';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ucnv_toUnicode"
c_ucnv_toUnicode :: Ptr CIntPtr -> Ptr Word16 -> Ptr Word16 -> Ptr Int8 -> CString -> Ptr Int32 -> Int8 -> Ptr Int32 -> IO ()
-- converter : UConverter* in/out -> Ptr CIntPtr
-- target : WORD** in/out -> Ptr Word16
-- targetLimit : WORD* -> Ptr Word16
-- source : CHAR** -> Ptr Int8
-- sourceLimit : LPCSTR -> CString
-- offsets : INT* in/out -> Ptr Int32
-- flush : CHAR -> Int8
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ucnv_tounicode =
foreign "ucnv_toUnicode"
((ptr intptr_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr int8_t) @-> string @-> (ptr int32_t) @-> int8_t @-> (ptr int32_t) @-> returning void)
(* converter : UConverter* in/out -> (ptr intptr_t) *)
(* target : WORD** in/out -> (ptr uint16_t) *)
(* targetLimit : WORD* -> (ptr uint16_t) *)
(* source : CHAR** -> (ptr int8_t) *)
(* sourceLimit : LPCSTR -> string *)
(* offsets : INT* in/out -> (ptr int32_t) *)
(* flush : CHAR -> int8_t *)
(* err : UErrorCode* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)
(cffi:defcfun ("ucnv_toUnicode" ucnv-to-unicode :convention :cdecl) :void
(converter :pointer) ; UConverter* in/out
(target :pointer) ; WORD** in/out
(target-limit :pointer) ; WORD*
(source :pointer) ; CHAR**
(source-limit :string) ; LPCSTR
(offsets :pointer) ; INT* in/out
(flush :int8) ; CHAR
(err :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ucnv_toUnicode = Win32::API::More->new('icuuc',
'void ucnv_toUnicode(LPVOID converter, LPVOID target, LPVOID targetLimit, LPVOID source, LPCSTR sourceLimit, LPVOID offsets, char flush, LPVOID err)');
# my $ret = $ucnv_toUnicode->Call($converter, $target, $targetLimit, $source, $sourceLimit, $offsets, $flush, $err);
# converter : UConverter* in/out -> LPVOID
# target : WORD** in/out -> LPVOID
# targetLimit : WORD* -> LPVOID
# source : CHAR** -> LPVOID
# sourceLimit : LPCSTR -> LPCSTR
# offsets : INT* in/out -> LPVOID
# flush : CHAR -> char
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型