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

u_strspn

関数
集合の文字のみが続く先頭部分の長さを返す。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT u_strspn(
    const WORD* string,
    const WORD* matchSet
);

パラメーター

名前方向説明
stringWORD*in走査対象のNUL終端UTF-16文字列へのポインタ。
matchSetWORD*in許容文字の集合へのポインタ。matchSet内の文字のみで構成される先頭部分の長さを返す。

戻り値の型: INT

各言語での呼び出し定義

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

INT u_strspn(
    const WORD* string,
    const WORD* matchSet
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int u_strspn(
    ref ushort string,   // WORD*
    ref ushort matchSet   // WORD*
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strspn(
    ByRef [string] As UShort,   ' WORD*
    ByRef matchSet As UShort   ' WORD*
) As Integer
End Function
' string : WORD*
' matchSet : WORD*
Declare PtrSafe Function u_strspn Lib "icuuc" ( _
    ByRef string As Integer, _
    ByRef matchSet As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

u_strspn = ctypes.cdll.icuuc.u_strspn
u_strspn.restype = ctypes.c_int
u_strspn.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # string : WORD*
    ctypes.POINTER(ctypes.c_ushort),  # matchSet : WORD*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_strspn = icuuc.NewProc("u_strspn")
)

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

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

typedef u_strspnNative = Int32 Function(Pointer<Uint16>, Pointer<Uint16>);
typedef u_strspnDart = int Function(Pointer<Uint16>, Pointer<Uint16>);
final u_strspn = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_strspnNative, u_strspnDart>('u_strspn');
// string : WORD* -> Pointer<Uint16>
// matchSet : WORD* -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function u_strspn(
  string: Pointer;   // WORD*
  matchSet: Pointer   // WORD*
): Integer; cdecl;
  external 'icuuc.dll' name 'u_strspn';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_strspn"
  c_u_strspn :: Ptr Word16 -> Ptr Word16 -> IO Int32
-- string : WORD* -> Ptr Word16
-- matchSet : WORD* -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_strspn =
  foreign "u_strspn"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* string : WORD* -> (ptr uint16_t) *)
(* matchSet : WORD* -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)

(cffi:defcfun ("u_strspn" u-strspn :convention :cdecl) :int32
  (string :pointer)   ; WORD*
  (match-set :pointer))   ; WORD*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_strspn = Win32::API::More->new('icuuc',
    'int u_strspn(LPVOID string, LPVOID matchSet)');
# my $ret = $u_strspn->Call($string, $matchSet);
# string : WORD* -> LPVOID
# matchSet : WORD* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。