ホーム › Globalization › ucnv_detectUnicodeSignature
ucnv_detectUnicodeSignature
関数バイト列からUnicodeのBOM署名を検出する。
シグネチャ
// icuuc.dll
#include <windows.h>
LPSTR ucnv_detectUnicodeSignature(
LPCSTR source,
INT sourceLength,
INT* signatureLength,
UErrorCode* pErrorCode
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| source | LPCSTR | in | BOM/シグネチャを検出する対象のバイト列へのポインタ。 |
| sourceLength | INT | in | sourceのバイト数。-1でNUL終端を意味する。 |
| signatureLength | INT* | inout | 検出したシグネチャのバイト長を受け取る出力ポインタ。NULL可。 |
| pErrorCode | UErrorCode* | inout | エラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。 |
戻り値の型: LPSTR
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
LPSTR ucnv_detectUnicodeSignature(
LPCSTR source,
INT sourceLength,
INT* signatureLength,
UErrorCode* pErrorCode
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ucnv_detectUnicodeSignature(
[MarshalAs(UnmanagedType.LPStr)] string source, // LPCSTR
int sourceLength, // INT
ref int signatureLength, // INT* in/out
ref int pErrorCode // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ucnv_detectUnicodeSignature(
<MarshalAs(UnmanagedType.LPStr)> source As String, ' LPCSTR
sourceLength As Integer, ' INT
ByRef signatureLength As Integer, ' INT* in/out
ByRef pErrorCode As Integer ' UErrorCode* in/out
) As IntPtr
End Function' source : LPCSTR
' sourceLength : INT
' signatureLength : INT* in/out
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function ucnv_detectUnicodeSignature Lib "icuuc" ( _
ByVal source As String, _
ByVal sourceLength As Long, _
ByRef signatureLength As Long, _
ByRef pErrorCode As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ucnv_detectUnicodeSignature = ctypes.cdll.icuuc.ucnv_detectUnicodeSignature
ucnv_detectUnicodeSignature.restype = wintypes.LPSTR
ucnv_detectUnicodeSignature.argtypes = [
wintypes.LPCSTR, # source : LPCSTR
ctypes.c_int, # sourceLength : INT
ctypes.POINTER(ctypes.c_int), # signatureLength : INT* in/out
ctypes.c_void_p, # pErrorCode : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ucnv_detectUnicodeSignature = Fiddle::Function.new(
lib['ucnv_detectUnicodeSignature'],
[
Fiddle::TYPE_VOIDP, # source : LPCSTR
Fiddle::TYPE_INT, # sourceLength : INT
Fiddle::TYPE_VOIDP, # signatureLength : INT* in/out
Fiddle::TYPE_VOIDP, # pErrorCode : UErrorCode* in/out
],
Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn ucnv_detectUnicodeSignature(
source: *const u8, // LPCSTR
sourceLength: i32, // INT
signatureLength: *mut i32, // INT* in/out
pErrorCode: *mut i32 // UErrorCode* in/out
) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ucnv_detectUnicodeSignature([MarshalAs(UnmanagedType.LPStr)] string source, int sourceLength, ref int signatureLength, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_detectUnicodeSignature' -Namespace Win32 -PassThru
# $api::ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode)#uselib "icuuc.dll"
#func global ucnv_detectUnicodeSignature "ucnv_detectUnicodeSignature" sptr, sptr, sptr, sptr
; ucnv_detectUnicodeSignature source, sourceLength, varptr(signatureLength), varptr(pErrorCode) ; 戻り値は stat
; source : LPCSTR -> "sptr"
; sourceLength : INT -> "sptr"
; signatureLength : INT* in/out -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global ucnv_detectUnicodeSignature "ucnv_detectUnicodeSignature" str, int, var, var ; res = ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode) ; source : LPCSTR -> "str" ; sourceLength : INT -> "int" ; signatureLength : INT* in/out -> "var" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global ucnv_detectUnicodeSignature "ucnv_detectUnicodeSignature" str, int, sptr, sptr ; res = ucnv_detectUnicodeSignature(source, sourceLength, varptr(signatureLength), varptr(pErrorCode)) ; source : LPCSTR -> "str" ; sourceLength : INT -> "int" ; signatureLength : INT* in/out -> "sptr" ; pErrorCode : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPSTR ucnv_detectUnicodeSignature(LPCSTR source, INT sourceLength, INT* signatureLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_detectUnicodeSignature "ucnv_detectUnicodeSignature" str, int, var, var ; res = ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode) ; source : LPCSTR -> "str" ; sourceLength : INT -> "int" ; signatureLength : INT* in/out -> "var" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPSTR ucnv_detectUnicodeSignature(LPCSTR source, INT sourceLength, INT* signatureLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_detectUnicodeSignature "ucnv_detectUnicodeSignature" str, int, intptr, intptr ; res = ucnv_detectUnicodeSignature(source, sourceLength, varptr(signatureLength), varptr(pErrorCode)) ; source : LPCSTR -> "str" ; sourceLength : INT -> "int" ; signatureLength : INT* in/out -> "intptr" ; pErrorCode : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procucnv_detectUnicodeSignature = icuuc.NewProc("ucnv_detectUnicodeSignature")
)
// source (LPCSTR), sourceLength (INT), signatureLength (INT* in/out), pErrorCode (UErrorCode* in/out)
r1, _, err := procucnv_detectUnicodeSignature.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(source))),
uintptr(sourceLength),
uintptr(signatureLength),
uintptr(pErrorCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPSTRfunction ucnv_detectUnicodeSignature(
source: PAnsiChar; // LPCSTR
sourceLength: Integer; // INT
signatureLength: Pointer; // INT* in/out
pErrorCode: Pointer // UErrorCode* in/out
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'ucnv_detectUnicodeSignature';result := DllCall("icuuc\ucnv_detectUnicodeSignature"
, "AStr", source ; LPCSTR
, "Int", sourceLength ; INT
, "Ptr", signatureLength ; INT* in/out
, "Ptr", pErrorCode ; UErrorCode* in/out
, "Cdecl Ptr") ; return: LPSTR●ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode) = DLL("icuuc.dll", "char* ucnv_detectUnicodeSignature(char*, int, void*, void*)")
# 呼び出し: ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode)
# source : LPCSTR -> "char*"
# sourceLength : INT -> "int"
# signatureLength : INT* in/out -> "void*"
# pErrorCode : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "icuuc" fn ucnv_detectUnicodeSignature(
source: [*c]const u8, // LPCSTR
sourceLength: i32, // INT
signatureLength: [*c]i32, // INT* in/out
pErrorCode: [*c]i32 // UErrorCode* in/out
) callconv(.c) [*c]const u8;proc ucnv_detectUnicodeSignature(
source: cstring, # LPCSTR
sourceLength: int32, # INT
signatureLength: ptr int32, # INT* in/out
pErrorCode: ptr int32 # UErrorCode* in/out
): cstring {.importc: "ucnv_detectUnicodeSignature", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
const(char)* ucnv_detectUnicodeSignature(
const(char)* source, // LPCSTR
int sourceLength, // INT
int* signatureLength, // INT* in/out
int* pErrorCode // UErrorCode* in/out
);ccall((:ucnv_detectUnicodeSignature, "icuuc.dll"), Cstring,
(Cstring, Int32, Ptr{Int32}, Ptr{Int32}),
source, sourceLength, signatureLength, pErrorCode)
# source : LPCSTR -> Cstring
# sourceLength : INT -> Int32
# signatureLength : INT* in/out -> Ptr{Int32}
# pErrorCode : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
const char* ucnv_detectUnicodeSignature(
const char* source,
int32_t sourceLength,
int32_t* signatureLength,
int32_t* pErrorCode);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode)
-- source : LPCSTR
-- sourceLength : INT
-- signatureLength : INT* in/out
-- pErrorCode : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_detectUnicodeSignature = lib.func('__cdecl', 'ucnv_detectUnicodeSignature', 'void *', ['str', 'int32_t', 'int32_t *', 'int32_t *']);
// ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode)
// source : LPCSTR -> 'str'
// sourceLength : INT -> 'int32_t'
// signatureLength : INT* in/out -> 'int32_t *'
// pErrorCode : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
ucnv_detectUnicodeSignature: { parameters: ["buffer", "i32", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode)
// source : LPCSTR -> "buffer"
// sourceLength : INT -> "i32"
// signatureLength : INT* in/out -> "pointer"
// pErrorCode : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const char* ucnv_detectUnicodeSignature(
const char* source,
int32_t sourceLength,
int32_t* signatureLength,
int32_t* pErrorCode);
C, "icuuc.dll");
// $ffi->ucnv_detectUnicodeSignature(source, sourceLength, signatureLength, pErrorCode);
// source : LPCSTR
// sourceLength : INT
// signatureLength : INT* in/out
// pErrorCode : UErrorCode* in/out
// 構造体/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);
Pointer ucnv_detectUnicodeSignature(
String source, // LPCSTR
int sourceLength, // INT
IntByReference signatureLength, // INT* in/out
IntByReference pErrorCode // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun ucnv_detectUnicodeSignature = ucnv_detectUnicodeSignature(
source : UInt8*, # LPCSTR
sourceLength : Int32, # INT
signatureLength : Int32*, # INT* in/out
pErrorCode : Int32* # UErrorCode* in/out
) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ucnv_detectUnicodeSignatureNative = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Int32>, Pointer<Int32>);
typedef ucnv_detectUnicodeSignatureDart = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Int32>, Pointer<Int32>);
final ucnv_detectUnicodeSignature = DynamicLibrary.open('icuuc.dll')
.lookupFunction<ucnv_detectUnicodeSignatureNative, ucnv_detectUnicodeSignatureDart>('ucnv_detectUnicodeSignature');
// source : LPCSTR -> Pointer<Utf8>
// sourceLength : INT -> Int32
// signatureLength : INT* in/out -> Pointer<Int32>
// pErrorCode : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ucnv_detectUnicodeSignature(
source: PAnsiChar; // LPCSTR
sourceLength: Integer; // INT
signatureLength: Pointer; // INT* in/out
pErrorCode: Pointer // UErrorCode* in/out
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'ucnv_detectUnicodeSignature';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ucnv_detectUnicodeSignature"
c_ucnv_detectUnicodeSignature :: CString -> Int32 -> Ptr Int32 -> Ptr Int32 -> IO CString
-- source : LPCSTR -> CString
-- sourceLength : INT -> Int32
-- signatureLength : INT* in/out -> Ptr Int32
-- pErrorCode : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ucnv_detectunicodesignature =
foreign "ucnv_detectUnicodeSignature"
(string @-> int32_t @-> (ptr int32_t) @-> (ptr int32_t) @-> returning string)
(* source : LPCSTR -> string *)
(* sourceLength : INT -> int32_t *)
(* signatureLength : INT* in/out -> (ptr int32_t) *)
(* pErrorCode : UErrorCode* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)
(cffi:defcfun ("ucnv_detectUnicodeSignature" ucnv-detect-unicode-signature :convention :cdecl) :string
(source :string) ; LPCSTR
(source-length :int32) ; INT
(signature-length :pointer) ; INT* in/out
(p-error-code :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ucnv_detectUnicodeSignature = Win32::API::More->new('icuuc',
'LPSTR ucnv_detectUnicodeSignature(LPCSTR source, int sourceLength, LPVOID signatureLength, LPVOID pErrorCode)');
# my $ret = $ucnv_detectUnicodeSignature->Call($source, $sourceLength, $signatureLength, $pErrorCode);
# source : LPCSTR -> LPCSTR
# sourceLength : INT -> int
# signatureLength : INT* in/out -> LPVOID
# pErrorCode : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型