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