ホーム › Globalization › u_strncmp
u_strncmp
関数二つの文字列を最大n文字まで比較する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT u_strncmp(
const WORD* ucs1,
const WORD* ucs2,
INT n
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ucs1 | WORD* | in | 比較する第一UTF-16文字列へのポインタ。 |
| ucs2 | WORD* | in | 比較する第二UTF-16文字列へのポインタ。 |
| n | INT | in | 比較する最大UChar数。コードユニット順の比較結果を返す。 |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT u_strncmp(
const WORD* ucs1,
const WORD* ucs2,
INT n
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int u_strncmp(
ref ushort ucs1, // WORD*
ref ushort ucs2, // WORD*
int n // INT
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strncmp(
ByRef ucs1 As UShort, ' WORD*
ByRef ucs2 As UShort, ' WORD*
n As Integer ' INT
) As Integer
End Function' ucs1 : WORD*
' ucs2 : WORD*
' n : INT
Declare PtrSafe Function u_strncmp Lib "icuuc" ( _
ByRef ucs1 As Integer, _
ByRef ucs2 As Integer, _
ByVal n As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
u_strncmp = ctypes.cdll.icuuc.u_strncmp
u_strncmp.restype = ctypes.c_int
u_strncmp.argtypes = [
ctypes.POINTER(ctypes.c_ushort), # ucs1 : WORD*
ctypes.POINTER(ctypes.c_ushort), # ucs2 : WORD*
ctypes.c_int, # n : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_strncmp = Fiddle::Function.new(
lib['u_strncmp'],
[
Fiddle::TYPE_VOIDP, # ucs1 : WORD*
Fiddle::TYPE_VOIDP, # ucs2 : WORD*
Fiddle::TYPE_INT, # n : INT
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_strncmp(
ucs1: *const u16, // WORD*
ucs2: *const u16, // WORD*
n: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int u_strncmp(ref ushort ucs1, ref ushort ucs2, int n);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_strncmp' -Namespace Win32 -PassThru
# $api::u_strncmp(ucs1, ucs2, n)#uselib "icuuc.dll"
#func global u_strncmp "u_strncmp" sptr, sptr, sptr
; u_strncmp varptr(ucs1), varptr(ucs2), n ; 戻り値は stat
; ucs1 : WORD* -> "sptr"
; ucs2 : WORD* -> "sptr"
; n : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" var, var, int ; res = u_strncmp(ucs1, ucs2, n) ; ucs1 : WORD* -> "var" ; ucs2 : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" sptr, sptr, int ; res = u_strncmp(varptr(ucs1), varptr(ucs2), n) ; ucs1 : WORD* -> "sptr" ; ucs2 : WORD* -> "sptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT u_strncmp(WORD* ucs1, WORD* ucs2, INT n) #uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" var, var, int ; res = u_strncmp(ucs1, ucs2, n) ; ucs1 : WORD* -> "var" ; ucs2 : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT u_strncmp(WORD* ucs1, WORD* ucs2, INT n) #uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" intptr, intptr, int ; res = u_strncmp(varptr(ucs1), varptr(ucs2), n) ; ucs1 : WORD* -> "intptr" ; ucs2 : WORD* -> "intptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_strncmp = icuuc.NewProc("u_strncmp")
)
// ucs1 (WORD*), ucs2 (WORD*), n (INT)
r1, _, err := procu_strncmp.Call(
uintptr(ucs1),
uintptr(ucs2),
uintptr(n),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction u_strncmp(
ucs1: Pointer; // WORD*
ucs2: Pointer; // WORD*
n: Integer // INT
): Integer; cdecl;
external 'icuuc.dll' name 'u_strncmp';result := DllCall("icuuc\u_strncmp"
, "Ptr", ucs1 ; WORD*
, "Ptr", ucs2 ; WORD*
, "Int", n ; INT
, "Cdecl Int") ; return: INT●u_strncmp(ucs1, ucs2, n) = DLL("icuuc.dll", "int u_strncmp(void*, void*, int)")
# 呼び出し: u_strncmp(ucs1, ucs2, n)
# ucs1 : WORD* -> "void*"
# ucs2 : WORD* -> "void*"
# n : 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 u_strncmp(
ucs1: [*c]u16, // WORD*
ucs2: [*c]u16, // WORD*
n: i32 // INT
) callconv(.c) i32;proc u_strncmp(
ucs1: ptr uint16, # WORD*
ucs2: ptr uint16, # WORD*
n: int32 # INT
): int32 {.importc: "u_strncmp", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int u_strncmp(
ushort* ucs1, // WORD*
ushort* ucs2, // WORD*
int n // INT
);ccall((:u_strncmp, "icuuc.dll"), Int32,
(Ptr{UInt16}, Ptr{UInt16}, Int32),
ucs1, ucs2, n)
# ucs1 : WORD* -> Ptr{UInt16}
# ucs2 : WORD* -> Ptr{UInt16}
# n : INT -> Int32local ffi = require("ffi")
ffi.cdef[[
int32_t u_strncmp(
uint16_t* ucs1,
uint16_t* ucs2,
int32_t n);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_strncmp(ucs1, ucs2, n)
-- ucs1 : WORD*
-- ucs2 : WORD*
-- n : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_strncmp = lib.func('__cdecl', 'u_strncmp', 'int32_t', ['uint16_t *', 'uint16_t *', 'int32_t']);
// u_strncmp(ucs1, ucs2, n)
// ucs1 : WORD* -> 'uint16_t *'
// ucs2 : WORD* -> 'uint16_t *'
// n : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
u_strncmp: { parameters: ["pointer", "pointer", "i32"], result: "i32" },
});
// lib.symbols.u_strncmp(ucs1, ucs2, n)
// ucs1 : WORD* -> "pointer"
// ucs2 : WORD* -> "pointer"
// n : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t u_strncmp(
uint16_t* ucs1,
uint16_t* ucs2,
int32_t n);
C, "icuuc.dll");
// $ffi->u_strncmp(ucs1, ucs2, n);
// ucs1 : WORD*
// ucs2 : WORD*
// n : 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 u_strncmp(
ShortByReference ucs1, // WORD*
ShortByReference ucs2, // WORD*
int n // INT
);
}@[Link("icuuc")]
lib Libicuuc
fun u_strncmp = u_strncmp(
ucs1 : UInt16*, # WORD*
ucs2 : UInt16*, # WORD*
n : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef u_strncmpNative = Int32 Function(Pointer<Uint16>, Pointer<Uint16>, Int32);
typedef u_strncmpDart = int Function(Pointer<Uint16>, Pointer<Uint16>, int);
final u_strncmp = DynamicLibrary.open('icuuc.dll')
.lookupFunction<u_strncmpNative, u_strncmpDart>('u_strncmp');
// ucs1 : WORD* -> Pointer<Uint16>
// ucs2 : WORD* -> Pointer<Uint16>
// n : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function u_strncmp(
ucs1: Pointer; // WORD*
ucs2: Pointer; // WORD*
n: Integer // INT
): Integer; cdecl;
external 'icuuc.dll' name 'u_strncmp';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "u_strncmp"
c_u_strncmp :: Ptr Word16 -> Ptr Word16 -> Int32 -> IO Int32
-- ucs1 : WORD* -> Ptr Word16
-- ucs2 : WORD* -> Ptr Word16
-- n : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let u_strncmp =
foreign "u_strncmp"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* ucs1 : WORD* -> (ptr uint16_t) *)
(* ucs2 : WORD* -> (ptr uint16_t) *)
(* n : 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 ("u_strncmp" u-strncmp :convention :cdecl) :int32
(ucs1 :pointer) ; WORD*
(ucs2 :pointer) ; WORD*
(n :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $u_strncmp = Win32::API::More->new('icuuc',
'int u_strncmp(LPVOID ucs1, LPVOID ucs2, int n)');
# my $ret = $u_strncmp->Call($ucs1, $ucs2, $n);
# ucs1 : WORD* -> LPVOID
# ucs2 : WORD* -> LPVOID
# n : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。