ホーム › Globalization › UCNV_TO_U_CALLBACK_SUBSTITUTE
UCNV_TO_U_CALLBACK_SUBSTITUTE
関数Unicodeへの変換失敗時に代替文字へ置換するコールバック。
シグネチャ
// icuuc.dll
#include <windows.h>
void UCNV_TO_U_CALLBACK_SUBSTITUTE(
const void* context,
UConverterToUnicodeArgs* toUArgs,
LPCSTR codeUnits,
INT length,
UConverterCallbackReason reason,
UErrorCode* err
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| context | void* | in | コールバックに渡される任意のユーザーデータ。NULL可。 |
| toUArgs | UConverterToUnicodeArgs* | inout | 外部符号化→Unicode変換の状態を保持する引数構造体へのポインタ。 |
| codeUnits | LPCSTR | in | 問題が生じた入力バイト列へのポインタ。 |
| length | INT | in | codeUnitsのバイト数。 |
| reason | UConverterCallbackReason | in | コールバックが呼ばれた理由を示す列挙値。 |
| err | UErrorCode* | inout | エラーコードを入出力するポインタ。SUBSTITUTEではU+FFFD等の置換文字を出力する。 |
戻り値の型: void
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
void UCNV_TO_U_CALLBACK_SUBSTITUTE(
const void* context,
UConverterToUnicodeArgs* toUArgs,
LPCSTR codeUnits,
INT length,
UConverterCallbackReason reason,
UErrorCode* err
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void UCNV_TO_U_CALLBACK_SUBSTITUTE(
IntPtr context, // void*
IntPtr toUArgs, // UConverterToUnicodeArgs* in/out
[MarshalAs(UnmanagedType.LPStr)] string codeUnits, // LPCSTR
int length, // INT
int reason, // UConverterCallbackReason
ref int err // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub UCNV_TO_U_CALLBACK_SUBSTITUTE(
context As IntPtr, ' void*
toUArgs As IntPtr, ' UConverterToUnicodeArgs* in/out
<MarshalAs(UnmanagedType.LPStr)> codeUnits As String, ' LPCSTR
length As Integer, ' INT
reason As Integer, ' UConverterCallbackReason
ByRef err As Integer ' UErrorCode* in/out
)
End Sub' context : void*
' toUArgs : UConverterToUnicodeArgs* in/out
' codeUnits : LPCSTR
' length : INT
' reason : UConverterCallbackReason
' err : UErrorCode* in/out
Declare PtrSafe Sub UCNV_TO_U_CALLBACK_SUBSTITUTE Lib "icuuc" ( _
ByVal context As LongPtr, _
ByVal toUArgs As LongPtr, _
ByVal codeUnits As String, _
ByVal length As Long, _
ByVal reason As Long, _
ByRef err As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
UCNV_TO_U_CALLBACK_SUBSTITUTE = ctypes.cdll.icuuc.UCNV_TO_U_CALLBACK_SUBSTITUTE
UCNV_TO_U_CALLBACK_SUBSTITUTE.restype = None
UCNV_TO_U_CALLBACK_SUBSTITUTE.argtypes = [
ctypes.POINTER(None), # context : void*
ctypes.c_void_p, # toUArgs : UConverterToUnicodeArgs* in/out
wintypes.LPCSTR, # codeUnits : LPCSTR
ctypes.c_int, # length : INT
ctypes.c_int, # reason : UConverterCallbackReason
ctypes.c_void_p, # err : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
UCNV_TO_U_CALLBACK_SUBSTITUTE = Fiddle::Function.new(
lib['UCNV_TO_U_CALLBACK_SUBSTITUTE'],
[
Fiddle::TYPE_VOIDP, # context : void*
Fiddle::TYPE_VOIDP, # toUArgs : UConverterToUnicodeArgs* in/out
Fiddle::TYPE_VOIDP, # codeUnits : LPCSTR
Fiddle::TYPE_INT, # length : INT
Fiddle::TYPE_INT, # reason : UConverterCallbackReason
Fiddle::TYPE_VOIDP, # err : UErrorCode* in/out
],
Fiddle::TYPE_VOID, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn UCNV_TO_U_CALLBACK_SUBSTITUTE(
context: *const (), // void*
toUArgs: *mut UConverterToUnicodeArgs, // UConverterToUnicodeArgs* in/out
codeUnits: *const u8, // LPCSTR
length: i32, // INT
reason: i32, // UConverterCallbackReason
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_TO_U_CALLBACK_SUBSTITUTE(IntPtr context, IntPtr toUArgs, [MarshalAs(UnmanagedType.LPStr)] string codeUnits, int length, int reason, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_UCNV_TO_U_CALLBACK_SUBSTITUTE' -Namespace Win32 -PassThru
# $api::UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err)#uselib "icuuc.dll"
#func global UCNV_TO_U_CALLBACK_SUBSTITUTE "UCNV_TO_U_CALLBACK_SUBSTITUTE" sptr, sptr, sptr, sptr, sptr, sptr
; UCNV_TO_U_CALLBACK_SUBSTITUTE context, varptr(toUArgs), codeUnits, length, reason, varptr(err)
; context : void* -> "sptr"
; toUArgs : UConverterToUnicodeArgs* in/out -> "sptr"
; codeUnits : LPCSTR -> "sptr"
; length : INT -> "sptr"
; reason : UConverterCallbackReason -> "sptr"
; err : UErrorCode* in/out -> "sptr"出力引数:
#uselib "icuuc.dll" #func global UCNV_TO_U_CALLBACK_SUBSTITUTE "UCNV_TO_U_CALLBACK_SUBSTITUTE" sptr, var, str, int, int, var ; UCNV_TO_U_CALLBACK_SUBSTITUTE context, toUArgs, codeUnits, length, reason, err ; context : void* -> "sptr" ; toUArgs : UConverterToUnicodeArgs* in/out -> "var" ; codeUnits : LPCSTR -> "str" ; length : INT -> "int" ; reason : UConverterCallbackReason -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #func global UCNV_TO_U_CALLBACK_SUBSTITUTE "UCNV_TO_U_CALLBACK_SUBSTITUTE" sptr, sptr, str, int, int, sptr ; UCNV_TO_U_CALLBACK_SUBSTITUTE context, varptr(toUArgs), codeUnits, length, reason, varptr(err) ; context : void* -> "sptr" ; toUArgs : UConverterToUnicodeArgs* in/out -> "sptr" ; codeUnits : LPCSTR -> "str" ; length : INT -> "int" ; reason : UConverterCallbackReason -> "int" ; err : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void UCNV_TO_U_CALLBACK_SUBSTITUTE(void* context, UConverterToUnicodeArgs* toUArgs, LPCSTR codeUnits, INT length, UConverterCallbackReason reason, UErrorCode* err) #uselib "icuuc.dll" #func global UCNV_TO_U_CALLBACK_SUBSTITUTE "UCNV_TO_U_CALLBACK_SUBSTITUTE" intptr, var, str, int, int, var ; UCNV_TO_U_CALLBACK_SUBSTITUTE context, toUArgs, codeUnits, length, reason, err ; context : void* -> "intptr" ; toUArgs : UConverterToUnicodeArgs* in/out -> "var" ; codeUnits : LPCSTR -> "str" ; length : INT -> "int" ; reason : UConverterCallbackReason -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void UCNV_TO_U_CALLBACK_SUBSTITUTE(void* context, UConverterToUnicodeArgs* toUArgs, LPCSTR codeUnits, INT length, UConverterCallbackReason reason, UErrorCode* err) #uselib "icuuc.dll" #func global UCNV_TO_U_CALLBACK_SUBSTITUTE "UCNV_TO_U_CALLBACK_SUBSTITUTE" intptr, intptr, str, int, int, intptr ; UCNV_TO_U_CALLBACK_SUBSTITUTE context, varptr(toUArgs), codeUnits, length, reason, varptr(err) ; context : void* -> "intptr" ; toUArgs : UConverterToUnicodeArgs* in/out -> "intptr" ; codeUnits : LPCSTR -> "str" ; length : INT -> "int" ; reason : UConverterCallbackReason -> "int" ; err : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procUCNV_TO_U_CALLBACK_SUBSTITUTE = icuuc.NewProc("UCNV_TO_U_CALLBACK_SUBSTITUTE")
)
// context (void*), toUArgs (UConverterToUnicodeArgs* in/out), codeUnits (LPCSTR), length (INT), reason (UConverterCallbackReason), err (UErrorCode* in/out)
r1, _, err := procUCNV_TO_U_CALLBACK_SUBSTITUTE.Call(
uintptr(context),
uintptr(toUArgs),
uintptr(unsafe.Pointer(windows.BytePtrFromString(codeUnits))),
uintptr(length),
uintptr(reason),
uintptr(err),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure UCNV_TO_U_CALLBACK_SUBSTITUTE(
context: Pointer; // void*
toUArgs: Pointer; // UConverterToUnicodeArgs* in/out
codeUnits: PAnsiChar; // LPCSTR
length: Integer; // INT
reason: Integer; // UConverterCallbackReason
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'UCNV_TO_U_CALLBACK_SUBSTITUTE';result := DllCall("icuuc\UCNV_TO_U_CALLBACK_SUBSTITUTE"
, "Ptr", context ; void*
, "Ptr", toUArgs ; UConverterToUnicodeArgs* in/out
, "AStr", codeUnits ; LPCSTR
, "Int", length ; INT
, "Int", reason ; UConverterCallbackReason
, "Ptr", err ; UErrorCode* in/out
, "Cdecl Int") ; return: void●UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err) = DLL("icuuc.dll", "int UCNV_TO_U_CALLBACK_SUBSTITUTE(void*, void*, char*, int, int, void*)")
# 呼び出し: UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err)
# context : void* -> "void*"
# toUArgs : UConverterToUnicodeArgs* in/out -> "void*"
# codeUnits : LPCSTR -> "char*"
# length : INT -> "int"
# reason : UConverterCallbackReason -> "int"
# 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_TO_U_CALLBACK_SUBSTITUTE(
context: ?*anyopaque, // void*
toUArgs: [*c]UConverterToUnicodeArgs, // UConverterToUnicodeArgs* in/out
codeUnits: [*c]const u8, // LPCSTR
length: i32, // INT
reason: i32, // UConverterCallbackReason
err: [*c]i32 // UErrorCode* in/out
) callconv(.c) void;proc UCNV_TO_U_CALLBACK_SUBSTITUTE(
context: pointer, # void*
toUArgs: ptr UConverterToUnicodeArgs, # UConverterToUnicodeArgs* in/out
codeUnits: cstring, # LPCSTR
length: int32, # INT
reason: int32, # UConverterCallbackReason
err: ptr int32 # UErrorCode* in/out
) {.importc: "UCNV_TO_U_CALLBACK_SUBSTITUTE", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
void UCNV_TO_U_CALLBACK_SUBSTITUTE(
void* context, // void*
UConverterToUnicodeArgs* toUArgs, // UConverterToUnicodeArgs* in/out
const(char)* codeUnits, // LPCSTR
int length, // INT
int reason, // UConverterCallbackReason
int* err // UErrorCode* in/out
);ccall((:UCNV_TO_U_CALLBACK_SUBSTITUTE, "icuuc.dll"), Cvoid,
(Ptr{Cvoid}, Ptr{UConverterToUnicodeArgs}, Cstring, Int32, Int32, Ptr{Int32}),
context, toUArgs, codeUnits, length, reason, err)
# context : void* -> Ptr{Cvoid}
# toUArgs : UConverterToUnicodeArgs* in/out -> Ptr{UConverterToUnicodeArgs}
# codeUnits : LPCSTR -> Cstring
# length : INT -> Int32
# reason : UConverterCallbackReason -> Int32
# err : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
void UCNV_TO_U_CALLBACK_SUBSTITUTE(
void* context,
void* toUArgs,
const char* codeUnits,
int32_t length,
int32_t reason,
int32_t* err);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err)
-- context : void*
-- toUArgs : UConverterToUnicodeArgs* in/out
-- codeUnits : LPCSTR
-- length : INT
-- reason : UConverterCallbackReason
-- err : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const UCNV_TO_U_CALLBACK_SUBSTITUTE = lib.func('__cdecl', 'UCNV_TO_U_CALLBACK_SUBSTITUTE', 'void', ['void *', 'void *', 'str', 'int32_t', 'int32_t', 'int32_t *']);
// UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err)
// context : void* -> 'void *'
// toUArgs : UConverterToUnicodeArgs* in/out -> 'void *'
// codeUnits : LPCSTR -> 'str'
// length : INT -> 'int32_t'
// reason : UConverterCallbackReason -> 'int32_t'
// err : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
UCNV_TO_U_CALLBACK_SUBSTITUTE: { parameters: ["pointer", "pointer", "buffer", "i32", "i32", "pointer"], result: "void" },
});
// lib.symbols.UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err)
// context : void* -> "pointer"
// toUArgs : UConverterToUnicodeArgs* in/out -> "pointer"
// codeUnits : LPCSTR -> "buffer"
// length : INT -> "i32"
// reason : UConverterCallbackReason -> "i32"
// err : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void UCNV_TO_U_CALLBACK_SUBSTITUTE(
void* context,
void* toUArgs,
const char* codeUnits,
int32_t length,
int32_t reason,
int32_t* err);
C, "icuuc.dll");
// $ffi->UCNV_TO_U_CALLBACK_SUBSTITUTE(context, toUArgs, codeUnits, length, reason, err);
// context : void*
// toUArgs : UConverterToUnicodeArgs* in/out
// codeUnits : LPCSTR
// length : INT
// reason : UConverterCallbackReason
// 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_TO_U_CALLBACK_SUBSTITUTE(
Pointer context, // void*
Pointer toUArgs, // UConverterToUnicodeArgs* in/out
String codeUnits, // LPCSTR
int length, // INT
int reason, // UConverterCallbackReason
IntByReference err // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun UCNV_TO_U_CALLBACK_SUBSTITUTE = UCNV_TO_U_CALLBACK_SUBSTITUTE(
context : Void*, # void*
toUArgs : UConverterToUnicodeArgs*, # UConverterToUnicodeArgs* in/out
codeUnits : UInt8*, # LPCSTR
length : Int32, # INT
reason : Int32, # UConverterCallbackReason
err : Int32* # UErrorCode* in/out
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef UCNV_TO_U_CALLBACK_SUBSTITUTENative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Int32, Int32, Pointer<Int32>);
typedef UCNV_TO_U_CALLBACK_SUBSTITUTEDart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, int, int, Pointer<Int32>);
final UCNV_TO_U_CALLBACK_SUBSTITUTE = DynamicLibrary.open('icuuc.dll')
.lookupFunction<UCNV_TO_U_CALLBACK_SUBSTITUTENative, UCNV_TO_U_CALLBACK_SUBSTITUTEDart>('UCNV_TO_U_CALLBACK_SUBSTITUTE');
// context : void* -> Pointer<Void>
// toUArgs : UConverterToUnicodeArgs* in/out -> Pointer<Void>
// codeUnits : LPCSTR -> Pointer<Utf8>
// length : INT -> Int32
// reason : UConverterCallbackReason -> Int32
// err : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure UCNV_TO_U_CALLBACK_SUBSTITUTE(
context: Pointer; // void*
toUArgs: Pointer; // UConverterToUnicodeArgs* in/out
codeUnits: PAnsiChar; // LPCSTR
length: Integer; // INT
reason: Integer; // UConverterCallbackReason
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'UCNV_TO_U_CALLBACK_SUBSTITUTE';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "UCNV_TO_U_CALLBACK_SUBSTITUTE"
c_UCNV_TO_U_CALLBACK_SUBSTITUTE :: Ptr () -> Ptr () -> CString -> Int32 -> Int32 -> Ptr Int32 -> IO ()
-- context : void* -> Ptr ()
-- toUArgs : UConverterToUnicodeArgs* in/out -> Ptr ()
-- codeUnits : LPCSTR -> CString
-- length : INT -> Int32
-- reason : UConverterCallbackReason -> Int32
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ucnv_to_u_callback_substitute =
foreign "UCNV_TO_U_CALLBACK_SUBSTITUTE"
((ptr void) @-> (ptr void) @-> string @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning void)
(* context : void* -> (ptr void) *)
(* toUArgs : UConverterToUnicodeArgs* in/out -> (ptr void) *)
(* codeUnits : LPCSTR -> string *)
(* length : INT -> int32_t *)
(* reason : UConverterCallbackReason -> int32_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_TO_U_CALLBACK_SUBSTITUTE" ucnv-to-u-callback-substitute :convention :cdecl) :void
(context :pointer) ; void*
(to-uargs :pointer) ; UConverterToUnicodeArgs* in/out
(code-units :string) ; LPCSTR
(length :int32) ; INT
(reason :int32) ; UConverterCallbackReason
(err :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $UCNV_TO_U_CALLBACK_SUBSTITUTE = Win32::API::More->new('icuuc',
'void UCNV_TO_U_CALLBACK_SUBSTITUTE(LPVOID context, LPVOID toUArgs, LPCSTR codeUnits, int length, int reason, LPVOID err)');
# my $ret = $UCNV_TO_U_CALLBACK_SUBSTITUTE->Call($context, $toUArgs, $codeUnits, $length, $reason, $err);
# context : void* -> LPVOID
# toUArgs : UConverterToUnicodeArgs* in/out -> LPVOID
# codeUnits : LPCSTR -> LPCSTR
# length : INT -> int
# reason : UConverterCallbackReason -> int
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。