Win32 API 日本語リファレンス
ホームGlobalization › utf8_prevCharSafeBody

utf8_prevCharSafeBody

関数
UTF-8文字列から前のコードポイントを安全に取得する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

// icuuc.dll
#include <windows.h>

INT utf8_prevCharSafeBody(
    const BYTE* s,
    INT start,
    INT* pi,
    INT c,
    CHAR strict
);

パラメーター

名前方向
sBYTE*in
startINTin
piINT*inout
cINTin
strictCHARin

戻り値の型: INT

各言語での呼び出し定義

// icuuc.dll
#include <windows.h>

INT utf8_prevCharSafeBody(
    const BYTE* s,
    INT start,
    INT* pi,
    INT c,
    CHAR strict
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int utf8_prevCharSafeBody(
    IntPtr s,   // BYTE*
    int start,   // INT
    ref int pi,   // INT* in/out
    int c,   // INT
    sbyte strict   // CHAR
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function utf8_prevCharSafeBody(
    s As IntPtr,   ' BYTE*
    start As Integer,   ' INT
    ByRef pi As Integer,   ' INT* in/out
    c As Integer,   ' INT
    strict As SByte   ' CHAR
) As Integer
End Function
' s : BYTE*
' start : INT
' pi : INT* in/out
' c : INT
' strict : CHAR
Declare PtrSafe Function utf8_prevCharSafeBody Lib "icuuc" ( _
    ByVal s As LongPtr, _
    ByVal start As Long, _
    ByRef pi 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_prevCharSafeBody = ctypes.cdll.icuuc.utf8_prevCharSafeBody
utf8_prevCharSafeBody.restype = ctypes.c_int
utf8_prevCharSafeBody.argtypes = [
    ctypes.POINTER(ctypes.c_ubyte),  # s : BYTE*
    ctypes.c_int,  # start : INT
    ctypes.POINTER(ctypes.c_int),  # pi : INT* in/out
    ctypes.c_int,  # c : INT
    ctypes.c_byte,  # strict : CHAR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
utf8_prevCharSafeBody = Fiddle::Function.new(
  lib['utf8_prevCharSafeBody'],
  [
    Fiddle::TYPE_VOIDP,  # s : BYTE*
    Fiddle::TYPE_INT,  # start : INT
    Fiddle::TYPE_VOIDP,  # pi : INT* in/out
    Fiddle::TYPE_INT,  # c : INT
    Fiddle::TYPE_CHAR,  # strict : CHAR
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn utf8_prevCharSafeBody(
        s: *const u8,  // BYTE*
        start: i32,  // INT
        pi: *mut i32,  // INT* in/out
        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_prevCharSafeBody(IntPtr s, int start, ref int pi, int c, sbyte strict);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_utf8_prevCharSafeBody' -Namespace Win32 -PassThru
# $api::utf8_prevCharSafeBody(s, start, pi, c, strict)
#uselib "icuuc.dll"
#func global utf8_prevCharSafeBody "utf8_prevCharSafeBody" sptr, sptr, sptr, sptr, sptr
; utf8_prevCharSafeBody varptr(s), start, varptr(pi), c, strict   ; 戻り値は stat
; s : BYTE* -> "sptr"
; start : INT -> "sptr"
; pi : INT* in/out -> "sptr"
; c : INT -> "sptr"
; strict : CHAR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global utf8_prevCharSafeBody "utf8_prevCharSafeBody" var, int, var, int, int
; res = utf8_prevCharSafeBody(s, start, pi, c, strict)
; s : BYTE* -> "var"
; start : INT -> "int"
; pi : INT* in/out -> "var"
; c : INT -> "int"
; strict : CHAR -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT utf8_prevCharSafeBody(BYTE* s, INT start, INT* pi, INT c, CHAR strict)
#uselib "icuuc.dll"
#cfunc global utf8_prevCharSafeBody "utf8_prevCharSafeBody" var, int, var, int, int
; res = utf8_prevCharSafeBody(s, start, pi, c, strict)
; s : BYTE* -> "var"
; start : INT -> "int"
; pi : INT* in/out -> "var"
; c : INT -> "int"
; strict : CHAR -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procutf8_prevCharSafeBody = icuuc.NewProc("utf8_prevCharSafeBody")
)

// s (BYTE*), start (INT), pi (INT* in/out), c (INT), strict (CHAR)
r1, _, err := procutf8_prevCharSafeBody.Call(
	uintptr(s),
	uintptr(start),
	uintptr(pi),
	uintptr(c),
	uintptr(strict),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function utf8_prevCharSafeBody(
  s: Pointer;   // BYTE*
  start: Integer;   // INT
  pi: Pointer;   // INT* in/out
  c: Integer;   // INT
  strict: Shortint   // CHAR
): Integer; cdecl;
  external 'icuuc.dll' name 'utf8_prevCharSafeBody';
result := DllCall("icuuc\utf8_prevCharSafeBody"
    , "Ptr", s   ; BYTE*
    , "Int", start   ; INT
    , "Ptr", pi   ; INT* in/out
    , "Int", c   ; INT
    , "Char", strict   ; CHAR
    , "Cdecl Int")   ; return: INT
●utf8_prevCharSafeBody(s, start, pi, c, strict) = DLL("icuuc.dll", "int utf8_prevCharSafeBody(void*, int, void*, int, char)")
# 呼び出し: utf8_prevCharSafeBody(s, start, pi, c, strict)
# s : BYTE* -> "void*"
# start : INT -> "int"
# pi : INT* in/out -> "void*"
# c : INT -> "int"
# strict : CHAR -> "char"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。