ホーム › Globalization › utf8_appendCharSafeBody
utf8_appendCharSafeBody
関数UTF-8バッファにコードポイントを安全に追加する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT utf8_appendCharSafeBody(
BYTE* s,
INT i,
INT length,
INT c,
CHAR* pIsError
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| s | BYTE* | inout | UTF-8バイト列を書き込むバッファへのポインタ。 |
| i | INT | in | 書き込みを開始するバイトインデックス。 |
| length | INT | in | バッファの容量(バイト)。 |
| c | INT | in | 追加するUnicodeコードポイント。 |
| pIsError | CHAR* | inout | エンコードエラー発生時にTRUEが設定されるフラグへのポインタ。 |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT utf8_appendCharSafeBody(
BYTE* s,
INT i,
INT length,
INT c,
CHAR* pIsError
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int utf8_appendCharSafeBody(
IntPtr s, // BYTE* in/out
int i, // INT
int length, // INT
int c, // INT
IntPtr pIsError // CHAR* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function utf8_appendCharSafeBody(
s As IntPtr, ' BYTE* in/out
i As Integer, ' INT
length As Integer, ' INT
c As Integer, ' INT
pIsError As IntPtr ' CHAR* in/out
) As Integer
End Function' s : BYTE* in/out
' i : INT
' length : INT
' c : INT
' pIsError : CHAR* in/out
Declare PtrSafe Function utf8_appendCharSafeBody Lib "icuuc" ( _
ByVal s As LongPtr, _
ByVal i As Long, _
ByVal length As Long, _
ByVal c As Long, _
ByVal pIsError As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
utf8_appendCharSafeBody = ctypes.cdll.icuuc.utf8_appendCharSafeBody
utf8_appendCharSafeBody.restype = ctypes.c_int
utf8_appendCharSafeBody.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # s : BYTE* in/out
ctypes.c_int, # i : INT
ctypes.c_int, # length : INT
ctypes.c_int, # c : INT
ctypes.POINTER(ctypes.c_byte), # pIsError : CHAR* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
utf8_appendCharSafeBody = Fiddle::Function.new(
lib['utf8_appendCharSafeBody'],
[
Fiddle::TYPE_VOIDP, # s : BYTE* in/out
Fiddle::TYPE_INT, # i : INT
Fiddle::TYPE_INT, # length : INT
Fiddle::TYPE_INT, # c : INT
Fiddle::TYPE_VOIDP, # pIsError : CHAR* in/out
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn utf8_appendCharSafeBody(
s: *mut u8, // BYTE* in/out
i: i32, // INT
length: i32, // INT
c: i32, // INT
pIsError: *mut i8 // CHAR* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int utf8_appendCharSafeBody(IntPtr s, int i, int length, int c, IntPtr pIsError);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_utf8_appendCharSafeBody' -Namespace Win32 -PassThru
# $api::utf8_appendCharSafeBody(s, i, length, c, pIsError)#uselib "icuuc.dll"
#func global utf8_appendCharSafeBody "utf8_appendCharSafeBody" sptr, sptr, sptr, sptr, sptr
; utf8_appendCharSafeBody varptr(s), i, length, c, varptr(pIsError) ; 戻り値は stat
; s : BYTE* in/out -> "sptr"
; i : INT -> "sptr"
; length : INT -> "sptr"
; c : INT -> "sptr"
; pIsError : CHAR* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global utf8_appendCharSafeBody "utf8_appendCharSafeBody" var, int, int, int, var ; res = utf8_appendCharSafeBody(s, i, length, c, pIsError) ; s : BYTE* in/out -> "var" ; i : INT -> "int" ; length : INT -> "int" ; c : INT -> "int" ; pIsError : CHAR* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global utf8_appendCharSafeBody "utf8_appendCharSafeBody" sptr, int, int, int, sptr ; res = utf8_appendCharSafeBody(varptr(s), i, length, c, varptr(pIsError)) ; s : BYTE* in/out -> "sptr" ; i : INT -> "int" ; length : INT -> "int" ; c : INT -> "int" ; pIsError : CHAR* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT utf8_appendCharSafeBody(BYTE* s, INT i, INT length, INT c, CHAR* pIsError) #uselib "icuuc.dll" #cfunc global utf8_appendCharSafeBody "utf8_appendCharSafeBody" var, int, int, int, var ; res = utf8_appendCharSafeBody(s, i, length, c, pIsError) ; s : BYTE* in/out -> "var" ; i : INT -> "int" ; length : INT -> "int" ; c : INT -> "int" ; pIsError : CHAR* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT utf8_appendCharSafeBody(BYTE* s, INT i, INT length, INT c, CHAR* pIsError) #uselib "icuuc.dll" #cfunc global utf8_appendCharSafeBody "utf8_appendCharSafeBody" intptr, int, int, int, intptr ; res = utf8_appendCharSafeBody(varptr(s), i, length, c, varptr(pIsError)) ; s : BYTE* in/out -> "intptr" ; i : INT -> "int" ; length : INT -> "int" ; c : INT -> "int" ; pIsError : CHAR* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procutf8_appendCharSafeBody = icuuc.NewProc("utf8_appendCharSafeBody")
)
// s (BYTE* in/out), i (INT), length (INT), c (INT), pIsError (CHAR* in/out)
r1, _, err := procutf8_appendCharSafeBody.Call(
uintptr(s),
uintptr(i),
uintptr(length),
uintptr(c),
uintptr(pIsError),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction utf8_appendCharSafeBody(
s: Pointer; // BYTE* in/out
i: Integer; // INT
length: Integer; // INT
c: Integer; // INT
pIsError: Pointer // CHAR* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'utf8_appendCharSafeBody';result := DllCall("icuuc\utf8_appendCharSafeBody"
, "Ptr", s ; BYTE* in/out
, "Int", i ; INT
, "Int", length ; INT
, "Int", c ; INT
, "Ptr", pIsError ; CHAR* in/out
, "Cdecl Int") ; return: INT●utf8_appendCharSafeBody(s, i, length, c, pIsError) = DLL("icuuc.dll", "int utf8_appendCharSafeBody(void*, int, int, int, void*)")
# 呼び出し: utf8_appendCharSafeBody(s, i, length, c, pIsError)
# s : BYTE* in/out -> "void*"
# i : INT -> "int"
# length : INT -> "int"
# c : INT -> "int"
# pIsError : CHAR* 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 utf8_appendCharSafeBody(
s: [*c]u8, // BYTE* in/out
i: i32, // INT
length: i32, // INT
c: i32, // INT
pIsError: [*c]i8 // CHAR* in/out
) callconv(.c) i32;proc utf8_appendCharSafeBody(
s: ptr uint8, # BYTE* in/out
i: int32, # INT
length: int32, # INT
c: int32, # INT
pIsError: ptr int8 # CHAR* in/out
): int32 {.importc: "utf8_appendCharSafeBody", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int utf8_appendCharSafeBody(
ubyte* s, // BYTE* in/out
int i, // INT
int length, // INT
int c, // INT
byte* pIsError // CHAR* in/out
);ccall((:utf8_appendCharSafeBody, "icuuc.dll"), Int32,
(Ptr{UInt8}, Int32, Int32, Int32, Ptr{Int8}),
s, i, length, c, pIsError)
# s : BYTE* in/out -> Ptr{UInt8}
# i : INT -> Int32
# length : INT -> Int32
# c : INT -> Int32
# pIsError : CHAR* in/out -> Ptr{Int8}local ffi = require("ffi")
ffi.cdef[[
int32_t utf8_appendCharSafeBody(
uint8_t* s,
int32_t i,
int32_t length,
int32_t c,
int8_t* pIsError);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.utf8_appendCharSafeBody(s, i, length, c, pIsError)
-- s : BYTE* in/out
-- i : INT
-- length : INT
-- c : INT
-- pIsError : CHAR* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const utf8_appendCharSafeBody = lib.func('__cdecl', 'utf8_appendCharSafeBody', 'int32_t', ['uint8_t *', 'int32_t', 'int32_t', 'int32_t', 'int8_t *']);
// utf8_appendCharSafeBody(s, i, length, c, pIsError)
// s : BYTE* in/out -> 'uint8_t *'
// i : INT -> 'int32_t'
// length : INT -> 'int32_t'
// c : INT -> 'int32_t'
// pIsError : CHAR* in/out -> 'int8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
utf8_appendCharSafeBody: { parameters: ["pointer", "i32", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.utf8_appendCharSafeBody(s, i, length, c, pIsError)
// s : BYTE* in/out -> "pointer"
// i : INT -> "i32"
// length : INT -> "i32"
// c : INT -> "i32"
// pIsError : CHAR* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t utf8_appendCharSafeBody(
uint8_t* s,
int32_t i,
int32_t length,
int32_t c,
int8_t* pIsError);
C, "icuuc.dll");
// $ffi->utf8_appendCharSafeBody(s, i, length, c, pIsError);
// s : BYTE* in/out
// i : INT
// length : INT
// c : INT
// pIsError : CHAR* 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);
int utf8_appendCharSafeBody(
byte[] s, // BYTE* in/out
int i, // INT
int length, // INT
int c, // INT
byte[] pIsError // CHAR* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun utf8_appendCharSafeBody = utf8_appendCharSafeBody(
s : UInt8*, # BYTE* in/out
i : Int32, # INT
length : Int32, # INT
c : Int32, # INT
pIsError : Int8* # CHAR* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef utf8_appendCharSafeBodyNative = Int32 Function(Pointer<Uint8>, Int32, Int32, Int32, Pointer<Int8>);
typedef utf8_appendCharSafeBodyDart = int Function(Pointer<Uint8>, int, int, int, Pointer<Int8>);
final utf8_appendCharSafeBody = DynamicLibrary.open('icuuc.dll')
.lookupFunction<utf8_appendCharSafeBodyNative, utf8_appendCharSafeBodyDart>('utf8_appendCharSafeBody');
// s : BYTE* in/out -> Pointer<Uint8>
// i : INT -> Int32
// length : INT -> Int32
// c : INT -> Int32
// pIsError : CHAR* in/out -> Pointer<Int8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function utf8_appendCharSafeBody(
s: Pointer; // BYTE* in/out
i: Integer; // INT
length: Integer; // INT
c: Integer; // INT
pIsError: Pointer // CHAR* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'utf8_appendCharSafeBody';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "utf8_appendCharSafeBody"
c_utf8_appendCharSafeBody :: Ptr Word8 -> Int32 -> Int32 -> Int32 -> Ptr Int8 -> IO Int32
-- s : BYTE* in/out -> Ptr Word8
-- i : INT -> Int32
-- length : INT -> Int32
-- c : INT -> Int32
-- pIsError : CHAR* in/out -> Ptr Int8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let utf8_appendcharsafebody =
foreign "utf8_appendCharSafeBody"
((ptr uint8_t) @-> int32_t @-> int32_t @-> int32_t @-> (ptr int8_t) @-> returning int32_t)
(* s : BYTE* in/out -> (ptr uint8_t) *)
(* i : INT -> int32_t *)
(* length : INT -> int32_t *)
(* c : INT -> int32_t *)
(* pIsError : CHAR* in/out -> (ptr int8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)
(cffi:defcfun ("utf8_appendCharSafeBody" utf8-append-char-safe-body :convention :cdecl) :int32
(s :pointer) ; BYTE* in/out
(i :int32) ; INT
(length :int32) ; INT
(c :int32) ; INT
(p-is-error :pointer)) ; CHAR* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $utf8_appendCharSafeBody = Win32::API::More->new('icuuc',
'int utf8_appendCharSafeBody(LPVOID s, int i, int length, int c, LPVOID pIsError)');
# my $ret = $utf8_appendCharSafeBody->Call($s, $i, $length, $c, $pIsError);
# s : BYTE* in/out -> LPVOID
# i : INT -> int
# length : INT -> int
# c : INT -> int
# pIsError : CHAR* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。