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

uset_spanUTF8

関数
UTF-8文字列先頭からUSet条件に合う長さを返す。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT uset_spanUTF8(
    const USet* set,
    LPCSTR s,
    INT length,
    USetSpanCondition spanCondition
);

パラメーター

名前方向説明
setUSet*in走査に用いるUnicodeセット。
sLPCSTRin走査対象のUTF-8文字列へのポインタ。
lengthINTinsの長さ(バイト単位)。-1の場合はNUL終端文字列として扱う。
spanConditionUSetSpanConditionin先頭から連続して所属/非所属のいずれを数えるかを指定する条件。

戻り値の型: INT

各言語での呼び出し定義

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

INT uset_spanUTF8(
    const USet* set,
    LPCSTR s,
    INT length,
    USetSpanCondition spanCondition
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int uset_spanUTF8(
    ref IntPtr set,   // USet*
    [MarshalAs(UnmanagedType.LPStr)] string s,   // LPCSTR
    int length,   // INT
    int spanCondition   // USetSpanCondition
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function uset_spanUTF8(
    ByRef [set] As IntPtr,   ' USet*
    <MarshalAs(UnmanagedType.LPStr)> s As String,   ' LPCSTR
    length As Integer,   ' INT
    spanCondition As Integer   ' USetSpanCondition
) As Integer
End Function
' set : USet*
' s : LPCSTR
' length : INT
' spanCondition : USetSpanCondition
Declare PtrSafe Function uset_spanUTF8 Lib "icuuc" ( _
    ByRef set As LongPtr, _
    ByVal s As String, _
    ByVal length As Long, _
    ByVal spanCondition As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

uset_spanUTF8 = ctypes.cdll.icuuc.uset_spanUTF8
uset_spanUTF8.restype = ctypes.c_int
uset_spanUTF8.argtypes = [
    ctypes.c_void_p,  # set : USet*
    wintypes.LPCSTR,  # s : LPCSTR
    ctypes.c_int,  # length : INT
    ctypes.c_int,  # spanCondition : USetSpanCondition
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
uset_spanUTF8 = Fiddle::Function.new(
  lib['uset_spanUTF8'],
  [
    Fiddle::TYPE_VOIDP,  # set : USet*
    Fiddle::TYPE_VOIDP,  # s : LPCSTR
    Fiddle::TYPE_INT,  # length : INT
    Fiddle::TYPE_INT,  # spanCondition : USetSpanCondition
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn uset_spanUTF8(
        set: *const isize,  // USet*
        s: *const u8,  // LPCSTR
        length: i32,  // INT
        spanCondition: i32  // USetSpanCondition
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int uset_spanUTF8(ref IntPtr set, [MarshalAs(UnmanagedType.LPStr)] string s, int length, int spanCondition);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_uset_spanUTF8' -Namespace Win32 -PassThru
# $api::uset_spanUTF8(set, s, length, spanCondition)
#uselib "icuuc.dll"
#func global uset_spanUTF8 "uset_spanUTF8" sptr, sptr, sptr, sptr
; uset_spanUTF8 varptr(set), s, length, spanCondition   ; 戻り値は stat
; set : USet* -> "sptr"
; s : LPCSTR -> "sptr"
; length : INT -> "sptr"
; spanCondition : USetSpanCondition -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global uset_spanUTF8 "uset_spanUTF8" var, str, int, int
; res = uset_spanUTF8(set, s, length, spanCondition)
; set : USet* -> "var"
; s : LPCSTR -> "str"
; length : INT -> "int"
; spanCondition : USetSpanCondition -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT uset_spanUTF8(USet* set, LPCSTR s, INT length, USetSpanCondition spanCondition)
#uselib "icuuc.dll"
#cfunc global uset_spanUTF8 "uset_spanUTF8" var, str, int, int
; res = uset_spanUTF8(set, s, length, spanCondition)
; set : USet* -> "var"
; s : LPCSTR -> "str"
; length : INT -> "int"
; spanCondition : USetSpanCondition -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procuset_spanUTF8 = icuuc.NewProc("uset_spanUTF8")
)

// set (USet*), s (LPCSTR), length (INT), spanCondition (USetSpanCondition)
r1, _, err := procuset_spanUTF8.Call(
	uintptr(set),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(s))),
	uintptr(length),
	uintptr(spanCondition),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function uset_spanUTF8(
  set: Pointer;   // USet*
  s: PAnsiChar;   // LPCSTR
  length: Integer;   // INT
  spanCondition: Integer   // USetSpanCondition
): Integer; cdecl;
  external 'icuuc.dll' name 'uset_spanUTF8';
result := DllCall("icuuc\uset_spanUTF8"
    , "Ptr", set   ; USet*
    , "AStr", s   ; LPCSTR
    , "Int", length   ; INT
    , "Int", spanCondition   ; USetSpanCondition
    , "Cdecl Int")   ; return: INT
●uset_spanUTF8(set, s, length, spanCondition) = DLL("icuuc.dll", "int uset_spanUTF8(void*, char*, int, int)")
# 呼び出し: uset_spanUTF8(set, s, length, spanCondition)
# set : USet* -> "void*"
# s : LPCSTR -> "char*"
# length : INT -> "int"
# spanCondition : USetSpanCondition -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
const std = @import("std");

extern "icuuc" fn uset_spanUTF8(
    set: [*c]isize, // USet*
    s: [*c]const u8, // LPCSTR
    length: i32, // INT
    spanCondition: i32 // USetSpanCondition
) callconv(.c) i32;
proc uset_spanUTF8(
    set: ptr int,  # USet*
    s: cstring,  # LPCSTR
    length: int32,  # INT
    spanCondition: int32  # USetSpanCondition
): int32 {.importc: "uset_spanUTF8", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
int uset_spanUTF8(
    ptrdiff_t* set,   // USet*
    const(char)* s,   // LPCSTR
    int length,   // INT
    int spanCondition   // USetSpanCondition
);
ccall((:uset_spanUTF8, "icuuc.dll"), Int32,
      (Ptr{Int}, Cstring, Int32, Int32),
      set, s, length, spanCondition)
# set : USet* -> Ptr{Int}
# s : LPCSTR -> Cstring
# length : INT -> Int32
# spanCondition : USetSpanCondition -> Int32
local ffi = require("ffi")
ffi.cdef[[
int32_t uset_spanUTF8(
    intptr_t* set,
    const char* s,
    int32_t length,
    int32_t spanCondition);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.uset_spanUTF8(set, s, length, spanCondition)
-- set : USet*
-- s : LPCSTR
-- length : INT
-- spanCondition : USetSpanCondition
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const uset_spanUTF8 = lib.func('__cdecl', 'uset_spanUTF8', 'int32_t', ['intptr_t *', 'str', 'int32_t', 'int32_t']);
// uset_spanUTF8(set, s, length, spanCondition)
// set : USet* -> 'intptr_t *'
// s : LPCSTR -> 'str'
// length : INT -> 'int32_t'
// spanCondition : USetSpanCondition -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("icuuc.dll", {
  uset_spanUTF8: { parameters: ["pointer", "buffer", "i32", "i32"], result: "i32" },
});
// lib.symbols.uset_spanUTF8(set, s, length, spanCondition)
// set : USet* -> "pointer"
// s : LPCSTR -> "buffer"
// length : INT -> "i32"
// spanCondition : USetSpanCondition -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t uset_spanUTF8(
    intptr_t* set,
    const char* s,
    int32_t length,
    int32_t spanCondition);
C, "icuuc.dll");
// $ffi->uset_spanUTF8(set, s, length, spanCondition);
// set : USet*
// s : LPCSTR
// length : INT
// spanCondition : USetSpanCondition
// 構造体/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 uset_spanUTF8(
        LongByReference set,   // USet*
        String s,   // LPCSTR
        int length,   // INT
        int spanCondition   // USetSpanCondition
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun uset_spanUTF8 = uset_spanUTF8(
    set : LibC::SSizeT*,   # USet*
    s : UInt8*,   # LPCSTR
    length : Int32,   # INT
    spanCondition : Int32   # USetSpanCondition
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef uset_spanUTF8Native = Int32 Function(Pointer<IntPtr>, Pointer<Utf8>, Int32, Int32);
typedef uset_spanUTF8Dart = int Function(Pointer<IntPtr>, Pointer<Utf8>, int, int);
final uset_spanUTF8 = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<uset_spanUTF8Native, uset_spanUTF8Dart>('uset_spanUTF8');
// set : USet* -> Pointer<IntPtr>
// s : LPCSTR -> Pointer<Utf8>
// length : INT -> Int32
// spanCondition : USetSpanCondition -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function uset_spanUTF8(
  set: Pointer;   // USet*
  s: PAnsiChar;   // LPCSTR
  length: Integer;   // INT
  spanCondition: Integer   // USetSpanCondition
): Integer; cdecl;
  external 'icuuc.dll' name 'uset_spanUTF8';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "uset_spanUTF8"
  c_uset_spanUTF8 :: Ptr CIntPtr -> CString -> Int32 -> Int32 -> IO Int32
-- set : USet* -> Ptr CIntPtr
-- s : LPCSTR -> CString
-- length : INT -> Int32
-- spanCondition : USetSpanCondition -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let uset_spanutf8 =
  foreign "uset_spanUTF8"
    ((ptr intptr_t) @-> string @-> int32_t @-> int32_t @-> returning int32_t)
(* set : USet* -> (ptr intptr_t) *)
(* s : LPCSTR -> string *)
(* length : INT -> int32_t *)
(* spanCondition : USetSpanCondition -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)

(cffi:defcfun ("uset_spanUTF8" uset-span-utf8 :convention :cdecl) :int32
  (set :pointer)   ; USet*
  (s :string)   ; LPCSTR
  (length :int32)   ; INT
  (span-condition :int32))   ; USetSpanCondition
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $uset_spanUTF8 = Win32::API::More->new('icuuc',
    'int uset_spanUTF8(LPVOID set, LPCSTR s, int length, int spanCondition)');
# my $ret = $uset_spanUTF8->Call($set, $s, $length, $spanCondition);
# set : USet* -> LPVOID
# s : LPCSTR -> LPCSTR
# length : INT -> int
# spanCondition : USetSpanCondition -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型