ホーム › Globalization › utf8_nextCharSafeBody
utf8_nextCharSafeBody
関数UTF-8文字列から次のコードポイントを安全に取得する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT utf8_nextCharSafeBody(
const BYTE* s,
INT* pi,
INT length,
INT c,
CHAR strict
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| s | BYTE* | in |
| pi | INT* | inout |
| length | INT | in |
| c | INT | in |
| strict | CHAR | in |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT utf8_nextCharSafeBody(
const BYTE* s,
INT* pi,
INT length,
INT c,
CHAR strict
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int utf8_nextCharSafeBody(
IntPtr s, // BYTE*
ref int pi, // INT* in/out
int length, // INT
int c, // INT
sbyte strict // CHAR
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function utf8_nextCharSafeBody(
s As IntPtr, ' BYTE*
ByRef pi As Integer, ' INT* in/out
length As Integer, ' INT
c As Integer, ' INT
strict As SByte ' CHAR
) As Integer
End Function' s : BYTE*
' pi : INT* in/out
' length : INT
' c : INT
' strict : CHAR
Declare PtrSafe Function utf8_nextCharSafeBody Lib "icuuc" ( _
ByVal s As LongPtr, _
ByRef pi As Long, _
ByVal length As Long, _
ByVal c As Long, _
ByVal strict As Byte) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
utf8_nextCharSafeBody = ctypes.cdll.icuuc.utf8_nextCharSafeBody
utf8_nextCharSafeBody.restype = ctypes.c_int
utf8_nextCharSafeBody.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # s : BYTE*
ctypes.POINTER(ctypes.c_int), # pi : INT* in/out
ctypes.c_int, # length : INT
ctypes.c_int, # c : INT
ctypes.c_byte, # strict : CHAR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
utf8_nextCharSafeBody = Fiddle::Function.new(
lib['utf8_nextCharSafeBody'],
[
Fiddle::TYPE_VOIDP, # s : BYTE*
Fiddle::TYPE_VOIDP, # pi : INT* in/out
Fiddle::TYPE_INT, # length : INT
Fiddle::TYPE_INT, # c : INT
Fiddle::TYPE_CHAR, # strict : CHAR
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn utf8_nextCharSafeBody(
s: *const u8, // BYTE*
pi: *mut i32, // INT* in/out
length: i32, // INT
c: i32, // INT
strict: i8 // CHAR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int utf8_nextCharSafeBody(IntPtr s, ref int pi, int length, int c, sbyte strict);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_utf8_nextCharSafeBody' -Namespace Win32 -PassThru
# $api::utf8_nextCharSafeBody(s, pi, length, c, strict)#uselib "icuuc.dll"
#func global utf8_nextCharSafeBody "utf8_nextCharSafeBody" sptr, sptr, sptr, sptr, sptr
; utf8_nextCharSafeBody varptr(s), varptr(pi), length, c, strict ; 戻り値は stat
; s : BYTE* -> "sptr"
; pi : INT* in/out -> "sptr"
; length : INT -> "sptr"
; c : INT -> "sptr"
; strict : CHAR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global utf8_nextCharSafeBody "utf8_nextCharSafeBody" var, var, int, int, int ; res = utf8_nextCharSafeBody(s, pi, length, c, strict) ; s : BYTE* -> "var" ; pi : INT* in/out -> "var" ; length : INT -> "int" ; c : INT -> "int" ; strict : CHAR -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global utf8_nextCharSafeBody "utf8_nextCharSafeBody" sptr, sptr, int, int, int ; res = utf8_nextCharSafeBody(varptr(s), varptr(pi), length, c, strict) ; s : BYTE* -> "sptr" ; pi : INT* in/out -> "sptr" ; length : INT -> "int" ; c : INT -> "int" ; strict : CHAR -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT utf8_nextCharSafeBody(BYTE* s, INT* pi, INT length, INT c, CHAR strict) #uselib "icuuc.dll" #cfunc global utf8_nextCharSafeBody "utf8_nextCharSafeBody" var, var, int, int, int ; res = utf8_nextCharSafeBody(s, pi, length, c, strict) ; s : BYTE* -> "var" ; pi : INT* in/out -> "var" ; length : INT -> "int" ; c : INT -> "int" ; strict : CHAR -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT utf8_nextCharSafeBody(BYTE* s, INT* pi, INT length, INT c, CHAR strict) #uselib "icuuc.dll" #cfunc global utf8_nextCharSafeBody "utf8_nextCharSafeBody" intptr, intptr, int, int, int ; res = utf8_nextCharSafeBody(varptr(s), varptr(pi), length, c, strict) ; s : BYTE* -> "intptr" ; pi : INT* in/out -> "intptr" ; length : INT -> "int" ; c : INT -> "int" ; strict : CHAR -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procutf8_nextCharSafeBody = icuuc.NewProc("utf8_nextCharSafeBody")
)
// s (BYTE*), pi (INT* in/out), length (INT), c (INT), strict (CHAR)
r1, _, err := procutf8_nextCharSafeBody.Call(
uintptr(s),
uintptr(pi),
uintptr(length),
uintptr(c),
uintptr(strict),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction utf8_nextCharSafeBody(
s: Pointer; // BYTE*
pi: Pointer; // INT* in/out
length: Integer; // INT
c: Integer; // INT
strict: Shortint // CHAR
): Integer; cdecl;
external 'icuuc.dll' name 'utf8_nextCharSafeBody';result := DllCall("icuuc\utf8_nextCharSafeBody"
, "Ptr", s ; BYTE*
, "Ptr", pi ; INT* in/out
, "Int", length ; INT
, "Int", c ; INT
, "Char", strict ; CHAR
, "Cdecl Int") ; return: INT●utf8_nextCharSafeBody(s, pi, length, c, strict) = DLL("icuuc.dll", "int utf8_nextCharSafeBody(void*, void*, int, int, char)")
# 呼び出し: utf8_nextCharSafeBody(s, pi, length, c, strict)
# s : BYTE* -> "void*"
# pi : INT* in/out -> "void*"
# length : INT -> "int"
# c : INT -> "int"
# strict : CHAR -> "char"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。