ホーム › 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 | UTF-8バイト列へのポインタ。 |
| pi | INT* | inout | 現在のバイトインデックスへのポインタ。読み取り後に次位置へ進む。 |
| length | INT | in | バイト列の全長。負値で終端不明として扱う。 |
| c | INT | in | 先頭バイトの値(呼び出し前に読み取った値)。 |
| strict | CHAR | in | 厳密検証モードを指定する。負値や0等で検証の厳しさを切り替える。 |
戻り値の型: 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`,…) を使用。const std = @import("std");
extern "icuuc" fn utf8_nextCharSafeBody(
s: [*c]u8, // BYTE*
pi: [*c]i32, // INT* in/out
length: i32, // INT
c: i32, // INT
strict: i8 // CHAR
) callconv(.c) i32;proc utf8_nextCharSafeBody(
s: ptr uint8, # BYTE*
pi: ptr int32, # INT* in/out
length: int32, # INT
c: int32, # INT
strict: int8 # CHAR
): int32 {.importc: "utf8_nextCharSafeBody", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int utf8_nextCharSafeBody(
ubyte* s, // BYTE*
int* pi, // INT* in/out
int length, // INT
int c, // INT
byte strict // CHAR
);ccall((:utf8_nextCharSafeBody, "icuuc.dll"), Int32,
(Ptr{UInt8}, Ptr{Int32}, Int32, Int32, Int8),
s, pi, length, c, strict)
# s : BYTE* -> Ptr{UInt8}
# pi : INT* in/out -> Ptr{Int32}
# length : INT -> Int32
# c : INT -> Int32
# strict : CHAR -> Int8local ffi = require("ffi")
ffi.cdef[[
int32_t utf8_nextCharSafeBody(
uint8_t* s,
int32_t* pi,
int32_t length,
int32_t c,
int8_t strict);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.utf8_nextCharSafeBody(s, pi, length, c, strict)
-- s : BYTE*
-- pi : INT* in/out
-- length : INT
-- c : INT
-- strict : CHAR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const utf8_nextCharSafeBody = lib.func('__cdecl', 'utf8_nextCharSafeBody', 'int32_t', ['uint8_t *', 'int32_t *', 'int32_t', 'int32_t', 'int8_t']);
// utf8_nextCharSafeBody(s, pi, length, c, strict)
// s : BYTE* -> 'uint8_t *'
// pi : INT* in/out -> 'int32_t *'
// length : INT -> 'int32_t'
// c : INT -> 'int32_t'
// strict : CHAR -> 'int8_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
utf8_nextCharSafeBody: { parameters: ["pointer", "pointer", "i32", "i32", "i8"], result: "i32" },
});
// lib.symbols.utf8_nextCharSafeBody(s, pi, length, c, strict)
// s : BYTE* -> "pointer"
// pi : INT* in/out -> "pointer"
// length : INT -> "i32"
// c : INT -> "i32"
// strict : CHAR -> "i8"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t utf8_nextCharSafeBody(
uint8_t* s,
int32_t* pi,
int32_t length,
int32_t c,
int8_t strict);
C, "icuuc.dll");
// $ffi->utf8_nextCharSafeBody(s, pi, length, c, strict);
// s : BYTE*
// pi : INT* in/out
// length : INT
// c : INT
// strict : CHAR
// 構造体/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_nextCharSafeBody(
byte[] s, // BYTE*
IntByReference pi, // INT* in/out
int length, // INT
int c, // INT
byte strict // CHAR
);
}@[Link("icuuc")]
lib Libicuuc
fun utf8_nextCharSafeBody = utf8_nextCharSafeBody(
s : UInt8*, # BYTE*
pi : Int32*, # INT* in/out
length : Int32, # INT
c : Int32, # INT
strict : Int8 # CHAR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef utf8_nextCharSafeBodyNative = Int32 Function(Pointer<Uint8>, Pointer<Int32>, Int32, Int32, Int8);
typedef utf8_nextCharSafeBodyDart = int Function(Pointer<Uint8>, Pointer<Int32>, int, int, int);
final utf8_nextCharSafeBody = DynamicLibrary.open('icuuc.dll')
.lookupFunction<utf8_nextCharSafeBodyNative, utf8_nextCharSafeBodyDart>('utf8_nextCharSafeBody');
// s : BYTE* -> Pointer<Uint8>
// pi : INT* in/out -> Pointer<Int32>
// length : INT -> Int32
// c : INT -> Int32
// strict : CHAR -> Int8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "utf8_nextCharSafeBody"
c_utf8_nextCharSafeBody :: Ptr Word8 -> Ptr Int32 -> Int32 -> Int32 -> Int8 -> IO Int32
-- s : BYTE* -> Ptr Word8
-- pi : INT* in/out -> Ptr Int32
-- length : INT -> Int32
-- c : INT -> Int32
-- strict : CHAR -> Int8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let utf8_nextcharsafebody =
foreign "utf8_nextCharSafeBody"
((ptr uint8_t) @-> (ptr int32_t) @-> int32_t @-> int32_t @-> int8_t @-> returning int32_t)
(* s : BYTE* -> (ptr uint8_t) *)
(* pi : INT* in/out -> (ptr int32_t) *)
(* length : INT -> int32_t *)
(* c : INT -> int32_t *)
(* strict : CHAR -> 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_nextCharSafeBody" utf8-next-char-safe-body :convention :cdecl) :int32
(s :pointer) ; BYTE*
(pi :pointer) ; INT* in/out
(length :int32) ; INT
(c :int32) ; INT
(strict :int8)) ; CHAR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $utf8_nextCharSafeBody = Win32::API::More->new('icuuc',
'int utf8_nextCharSafeBody(LPVOID s, LPVOID pi, int length, int c, char strict)');
# my $ret = $utf8_nextCharSafeBody->Call($s, $pi, $length, $c, $strict);
# s : BYTE* -> LPVOID
# pi : INT* in/out -> LPVOID
# length : INT -> int
# c : INT -> int
# strict : CHAR -> char
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。