ホーム › Globalization › ucnv_getInvalidChars
ucnv_getInvalidChars
関数直近の変換で無効だったバイト列を取得する。
シグネチャ
// icuuc.dll
#include <windows.h>
void ucnv_getInvalidChars(
const UConverter* converter,
LPSTR errBytes,
CHAR* len,
UErrorCode* err
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| converter | UConverter* | in | 対象のコンバーターへのポインタ。 |
| errBytes | LPSTR | in | 直近の不正入力バイト列を受け取る出力バッファ。 |
| len | CHAR* | inout | 入力時はバッファ容量、出力時は実際のバイト長を示すポインタ。 |
| err | UErrorCode* | inout | エラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。 |
戻り値の型: void
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
void ucnv_getInvalidChars(
const UConverter* converter,
LPSTR errBytes,
CHAR* len,
UErrorCode* err
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void ucnv_getInvalidChars(
ref IntPtr converter, // UConverter*
[MarshalAs(UnmanagedType.LPStr)] string errBytes, // LPSTR
IntPtr len, // CHAR* in/out
ref int err // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub ucnv_getInvalidChars(
ByRef converter As IntPtr, ' UConverter*
<MarshalAs(UnmanagedType.LPStr)> errBytes As String, ' LPSTR
len As IntPtr, ' CHAR* in/out
ByRef err As Integer ' UErrorCode* in/out
)
End Sub' converter : UConverter*
' errBytes : LPSTR
' len : CHAR* in/out
' err : UErrorCode* in/out
Declare PtrSafe Sub ucnv_getInvalidChars Lib "icuuc" ( _
ByRef converter As LongPtr, _
ByVal errBytes As String, _
ByVal len As LongPtr, _
ByRef err As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ucnv_getInvalidChars = ctypes.cdll.icuuc.ucnv_getInvalidChars
ucnv_getInvalidChars.restype = None
ucnv_getInvalidChars.argtypes = [
ctypes.c_void_p, # converter : UConverter*
wintypes.LPCSTR, # errBytes : LPSTR
ctypes.POINTER(ctypes.c_byte), # len : CHAR* in/out
ctypes.c_void_p, # err : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ucnv_getInvalidChars = Fiddle::Function.new(
lib['ucnv_getInvalidChars'],
[
Fiddle::TYPE_VOIDP, # converter : UConverter*
Fiddle::TYPE_VOIDP, # errBytes : LPSTR
Fiddle::TYPE_VOIDP, # len : CHAR* in/out
Fiddle::TYPE_VOIDP, # err : UErrorCode* in/out
],
Fiddle::TYPE_VOID, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn ucnv_getInvalidChars(
converter: *const isize, // UConverter*
errBytes: *mut u8, // LPSTR
len: *mut i8, // CHAR* in/out
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_getInvalidChars(ref IntPtr converter, [MarshalAs(UnmanagedType.LPStr)] string errBytes, IntPtr len, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_getInvalidChars' -Namespace Win32 -PassThru
# $api::ucnv_getInvalidChars(converter, errBytes, len, err)#uselib "icuuc.dll"
#func global ucnv_getInvalidChars "ucnv_getInvalidChars" sptr, sptr, sptr, sptr
; ucnv_getInvalidChars varptr(converter), errBytes, varptr(len), varptr(err)
; converter : UConverter* -> "sptr"
; errBytes : LPSTR -> "sptr"
; len : CHAR* in/out -> "sptr"
; err : UErrorCode* in/out -> "sptr"出力引数:
#uselib "icuuc.dll" #func global ucnv_getInvalidChars "ucnv_getInvalidChars" var, str, var, var ; ucnv_getInvalidChars converter, errBytes, len, err ; converter : UConverter* -> "var" ; errBytes : LPSTR -> "str" ; len : CHAR* in/out -> "var" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #func global ucnv_getInvalidChars "ucnv_getInvalidChars" sptr, str, sptr, sptr ; ucnv_getInvalidChars varptr(converter), errBytes, varptr(len), varptr(err) ; converter : UConverter* -> "sptr" ; errBytes : LPSTR -> "str" ; len : CHAR* in/out -> "sptr" ; err : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void ucnv_getInvalidChars(UConverter* converter, LPSTR errBytes, CHAR* len, UErrorCode* err) #uselib "icuuc.dll" #func global ucnv_getInvalidChars "ucnv_getInvalidChars" var, str, var, var ; ucnv_getInvalidChars converter, errBytes, len, err ; converter : UConverter* -> "var" ; errBytes : LPSTR -> "str" ; len : CHAR* in/out -> "var" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void ucnv_getInvalidChars(UConverter* converter, LPSTR errBytes, CHAR* len, UErrorCode* err) #uselib "icuuc.dll" #func global ucnv_getInvalidChars "ucnv_getInvalidChars" intptr, str, intptr, intptr ; ucnv_getInvalidChars varptr(converter), errBytes, varptr(len), varptr(err) ; converter : UConverter* -> "intptr" ; errBytes : LPSTR -> "str" ; len : CHAR* in/out -> "intptr" ; err : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procucnv_getInvalidChars = icuuc.NewProc("ucnv_getInvalidChars")
)
// converter (UConverter*), errBytes (LPSTR), len (CHAR* in/out), err (UErrorCode* in/out)
r1, _, err := procucnv_getInvalidChars.Call(
uintptr(converter),
uintptr(unsafe.Pointer(windows.BytePtrFromString(errBytes))),
uintptr(len),
uintptr(err),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure ucnv_getInvalidChars(
converter: Pointer; // UConverter*
errBytes: PAnsiChar; // LPSTR
len: Pointer; // CHAR* in/out
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'ucnv_getInvalidChars';result := DllCall("icuuc\ucnv_getInvalidChars"
, "Ptr", converter ; UConverter*
, "AStr", errBytes ; LPSTR
, "Ptr", len ; CHAR* in/out
, "Ptr", err ; UErrorCode* in/out
, "Cdecl Int") ; return: void●ucnv_getInvalidChars(converter, errBytes, len, err) = DLL("icuuc.dll", "int ucnv_getInvalidChars(void*, char*, void*, void*)")
# 呼び出し: ucnv_getInvalidChars(converter, errBytes, len, err)
# converter : UConverter* -> "void*"
# errBytes : LPSTR -> "char*"
# len : CHAR* in/out -> "void*"
# 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_getInvalidChars(
converter: [*c]isize, // UConverter*
errBytes: [*c]const u8, // LPSTR
len: [*c]i8, // CHAR* in/out
err: [*c]i32 // UErrorCode* in/out
) callconv(.c) void;proc ucnv_getInvalidChars(
`converter`: ptr int, # UConverter*
errBytes: cstring, # LPSTR
len: ptr int8, # CHAR* in/out
err: ptr int32 # UErrorCode* in/out
) {.importc: "ucnv_getInvalidChars", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
void ucnv_getInvalidChars(
ptrdiff_t* converter, // UConverter*
const(char)* errBytes, // LPSTR
byte* len, // CHAR* in/out
int* err // UErrorCode* in/out
);ccall((:ucnv_getInvalidChars, "icuuc.dll"), Cvoid,
(Ptr{Int}, Cstring, Ptr{Int8}, Ptr{Int32}),
converter, errBytes, len, err)
# converter : UConverter* -> Ptr{Int}
# errBytes : LPSTR -> Cstring
# len : CHAR* in/out -> Ptr{Int8}
# err : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
void ucnv_getInvalidChars(
intptr_t* converter,
const char* errBytes,
int8_t* len,
int32_t* err);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_getInvalidChars(converter, errBytes, len, err)
-- converter : UConverter*
-- errBytes : LPSTR
-- len : CHAR* in/out
-- err : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_getInvalidChars = lib.func('__cdecl', 'ucnv_getInvalidChars', 'void', ['intptr_t *', 'str', 'int8_t *', 'int32_t *']);
// ucnv_getInvalidChars(converter, errBytes, len, err)
// converter : UConverter* -> 'intptr_t *'
// errBytes : LPSTR -> 'str'
// len : CHAR* in/out -> 'int8_t *'
// err : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
ucnv_getInvalidChars: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "void" },
});
// lib.symbols.ucnv_getInvalidChars(converter, errBytes, len, err)
// converter : UConverter* -> "pointer"
// errBytes : LPSTR -> "buffer"
// len : CHAR* in/out -> "pointer"
// err : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void ucnv_getInvalidChars(
intptr_t* converter,
const char* errBytes,
int8_t* len,
int32_t* err);
C, "icuuc.dll");
// $ffi->ucnv_getInvalidChars(converter, errBytes, len, err);
// converter : UConverter*
// errBytes : LPSTR
// len : CHAR* in/out
// 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_getInvalidChars(
LongByReference converter, // UConverter*
String errBytes, // LPSTR
byte[] len, // CHAR* in/out
IntByReference err // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun ucnv_getInvalidChars = ucnv_getInvalidChars(
converter : LibC::SSizeT*, # UConverter*
errBytes : UInt8*, # LPSTR
len : Int8*, # CHAR* in/out
err : Int32* # UErrorCode* in/out
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ucnv_getInvalidCharsNative = Void Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Int8>, Pointer<Int32>);
typedef ucnv_getInvalidCharsDart = void Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Int8>, Pointer<Int32>);
final ucnv_getInvalidChars = DynamicLibrary.open('icuuc.dll')
.lookupFunction<ucnv_getInvalidCharsNative, ucnv_getInvalidCharsDart>('ucnv_getInvalidChars');
// converter : UConverter* -> Pointer<IntPtr>
// errBytes : LPSTR -> Pointer<Utf8>
// len : CHAR* in/out -> Pointer<Int8>
// err : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure ucnv_getInvalidChars(
converter: Pointer; // UConverter*
errBytes: PAnsiChar; // LPSTR
len: Pointer; // CHAR* in/out
err: Pointer // UErrorCode* in/out
); cdecl;
external 'icuuc.dll' name 'ucnv_getInvalidChars';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ucnv_getInvalidChars"
c_ucnv_getInvalidChars :: Ptr CIntPtr -> CString -> Ptr Int8 -> Ptr Int32 -> IO ()
-- converter : UConverter* -> Ptr CIntPtr
-- errBytes : LPSTR -> CString
-- len : CHAR* in/out -> Ptr Int8
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ucnv_getinvalidchars =
foreign "ucnv_getInvalidChars"
((ptr intptr_t) @-> string @-> (ptr int8_t) @-> (ptr int32_t) @-> returning void)
(* converter : UConverter* -> (ptr intptr_t) *)
(* errBytes : LPSTR -> string *)
(* len : CHAR* in/out -> (ptr 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_getInvalidChars" ucnv-get-invalid-chars :convention :cdecl) :void
(converter :pointer) ; UConverter*
(err-bytes :string) ; LPSTR
(len :pointer) ; CHAR* in/out
(err :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ucnv_getInvalidChars = Win32::API::More->new('icuuc',
'void ucnv_getInvalidChars(LPVOID converter, LPCSTR errBytes, LPVOID len, LPVOID err)');
# my $ret = $ucnv_getInvalidChars->Call($converter, $errBytes, $len, $err);
# converter : UConverter* -> LPVOID
# errBytes : LPSTR -> LPCSTR
# len : CHAR* in/out -> LPVOID
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型