ホーム › Globalization › uidna_nameToASCII_UTF8
uidna_nameToASCII_UTF8
関数UTF-8のドメイン名全体をASCII形式へ変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT uidna_nameToASCII_UTF8(
const UIDNA* idna,
LPCSTR name,
INT length,
LPSTR dest,
INT capacity,
UIDNAInfo* pInfo,
UErrorCode* pErrorCode
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| idna | UIDNA* | in | 変換に用いる開いたUIDNAインスタンスを指す。 |
| name | LPCSTR | in | ASCIIへ変換するドメイン名全体のUTF-8文字列を指す。 |
| length | INT | in | nameの長さをバイト単位で指定する。-1でNUL終端。 |
| dest | LPSTR | in | 変換結果のASCIIドメイン名を格納するUTF-8出力バッファ。NULL可。 |
| capacity | INT | in | destの容量をバイト単位で指定する。0で事前長取得。 |
| pInfo | UIDNAInfo* | inout | 処理結果やエラーフラグを受け取るUIDNAInfo構造体を指す。 |
| pErrorCode | UErrorCode* | inout | ICUエラーコードを入出力するポインタ。呼出前に成功値で初期化する。 |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT uidna_nameToASCII_UTF8(
const UIDNA* idna,
LPCSTR name,
INT length,
LPSTR dest,
INT capacity,
UIDNAInfo* pInfo,
UErrorCode* pErrorCode
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int uidna_nameToASCII_UTF8(
ref IntPtr idna, // UIDNA*
[MarshalAs(UnmanagedType.LPStr)] string name, // LPCSTR
int length, // INT
[MarshalAs(UnmanagedType.LPStr)] string dest, // LPSTR
int capacity, // INT
IntPtr pInfo, // UIDNAInfo* in/out
ref int pErrorCode // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function uidna_nameToASCII_UTF8(
ByRef idna As IntPtr, ' UIDNA*
<MarshalAs(UnmanagedType.LPStr)> name As String, ' LPCSTR
length As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> dest As String, ' LPSTR
capacity As Integer, ' INT
pInfo As IntPtr, ' UIDNAInfo* in/out
ByRef pErrorCode As Integer ' UErrorCode* in/out
) As Integer
End Function' idna : UIDNA*
' name : LPCSTR
' length : INT
' dest : LPSTR
' capacity : INT
' pInfo : UIDNAInfo* in/out
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function uidna_nameToASCII_UTF8 Lib "icuuc" ( _
ByRef idna As LongPtr, _
ByVal name As String, _
ByVal length As Long, _
ByVal dest As String, _
ByVal capacity As Long, _
ByVal pInfo As LongPtr, _
ByRef pErrorCode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
uidna_nameToASCII_UTF8 = ctypes.cdll.icuuc.uidna_nameToASCII_UTF8
uidna_nameToASCII_UTF8.restype = ctypes.c_int
uidna_nameToASCII_UTF8.argtypes = [
ctypes.c_void_p, # idna : UIDNA*
wintypes.LPCSTR, # name : LPCSTR
ctypes.c_int, # length : INT
wintypes.LPCSTR, # dest : LPSTR
ctypes.c_int, # capacity : INT
ctypes.c_void_p, # pInfo : UIDNAInfo* in/out
ctypes.c_void_p, # pErrorCode : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
uidna_nameToASCII_UTF8 = Fiddle::Function.new(
lib['uidna_nameToASCII_UTF8'],
[
Fiddle::TYPE_VOIDP, # idna : UIDNA*
Fiddle::TYPE_VOIDP, # name : LPCSTR
Fiddle::TYPE_INT, # length : INT
Fiddle::TYPE_VOIDP, # dest : LPSTR
Fiddle::TYPE_INT, # capacity : INT
Fiddle::TYPE_VOIDP, # pInfo : UIDNAInfo* in/out
Fiddle::TYPE_VOIDP, # pErrorCode : UErrorCode* in/out
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn uidna_nameToASCII_UTF8(
idna: *const isize, // UIDNA*
name: *const u8, // LPCSTR
length: i32, // INT
dest: *mut u8, // LPSTR
capacity: i32, // INT
pInfo: *mut UIDNAInfo, // UIDNAInfo* in/out
pErrorCode: *mut i32 // UErrorCode* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int uidna_nameToASCII_UTF8(ref IntPtr idna, [MarshalAs(UnmanagedType.LPStr)] string name, int length, [MarshalAs(UnmanagedType.LPStr)] string dest, int capacity, IntPtr pInfo, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_uidna_nameToASCII_UTF8' -Namespace Win32 -PassThru
# $api::uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode)#uselib "icuuc.dll"
#func global uidna_nameToASCII_UTF8 "uidna_nameToASCII_UTF8" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; uidna_nameToASCII_UTF8 varptr(idna), name, length, dest, capacity, varptr(pInfo), varptr(pErrorCode) ; 戻り値は stat
; idna : UIDNA* -> "sptr"
; name : LPCSTR -> "sptr"
; length : INT -> "sptr"
; dest : LPSTR -> "sptr"
; capacity : INT -> "sptr"
; pInfo : UIDNAInfo* in/out -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global uidna_nameToASCII_UTF8 "uidna_nameToASCII_UTF8" var, str, int, str, int, var, var ; res = uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode) ; idna : UIDNA* -> "var" ; name : LPCSTR -> "str" ; length : INT -> "int" ; dest : LPSTR -> "str" ; capacity : INT -> "int" ; pInfo : UIDNAInfo* in/out -> "var" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global uidna_nameToASCII_UTF8 "uidna_nameToASCII_UTF8" sptr, str, int, str, int, sptr, sptr ; res = uidna_nameToASCII_UTF8(varptr(idna), name, length, dest, capacity, varptr(pInfo), varptr(pErrorCode)) ; idna : UIDNA* -> "sptr" ; name : LPCSTR -> "str" ; length : INT -> "int" ; dest : LPSTR -> "str" ; capacity : INT -> "int" ; pInfo : UIDNAInfo* in/out -> "sptr" ; pErrorCode : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT uidna_nameToASCII_UTF8(UIDNA* idna, LPCSTR name, INT length, LPSTR dest, INT capacity, UIDNAInfo* pInfo, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global uidna_nameToASCII_UTF8 "uidna_nameToASCII_UTF8" var, str, int, str, int, var, var ; res = uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode) ; idna : UIDNA* -> "var" ; name : LPCSTR -> "str" ; length : INT -> "int" ; dest : LPSTR -> "str" ; capacity : INT -> "int" ; pInfo : UIDNAInfo* in/out -> "var" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT uidna_nameToASCII_UTF8(UIDNA* idna, LPCSTR name, INT length, LPSTR dest, INT capacity, UIDNAInfo* pInfo, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global uidna_nameToASCII_UTF8 "uidna_nameToASCII_UTF8" intptr, str, int, str, int, intptr, intptr ; res = uidna_nameToASCII_UTF8(varptr(idna), name, length, dest, capacity, varptr(pInfo), varptr(pErrorCode)) ; idna : UIDNA* -> "intptr" ; name : LPCSTR -> "str" ; length : INT -> "int" ; dest : LPSTR -> "str" ; capacity : INT -> "int" ; pInfo : UIDNAInfo* in/out -> "intptr" ; pErrorCode : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procuidna_nameToASCII_UTF8 = icuuc.NewProc("uidna_nameToASCII_UTF8")
)
// idna (UIDNA*), name (LPCSTR), length (INT), dest (LPSTR), capacity (INT), pInfo (UIDNAInfo* in/out), pErrorCode (UErrorCode* in/out)
r1, _, err := procuidna_nameToASCII_UTF8.Call(
uintptr(idna),
uintptr(unsafe.Pointer(windows.BytePtrFromString(name))),
uintptr(length),
uintptr(unsafe.Pointer(windows.BytePtrFromString(dest))),
uintptr(capacity),
uintptr(pInfo),
uintptr(pErrorCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction uidna_nameToASCII_UTF8(
idna: Pointer; // UIDNA*
name: PAnsiChar; // LPCSTR
length: Integer; // INT
dest: PAnsiChar; // LPSTR
capacity: Integer; // INT
pInfo: Pointer; // UIDNAInfo* in/out
pErrorCode: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'uidna_nameToASCII_UTF8';result := DllCall("icuuc\uidna_nameToASCII_UTF8"
, "Ptr", idna ; UIDNA*
, "AStr", name ; LPCSTR
, "Int", length ; INT
, "AStr", dest ; LPSTR
, "Int", capacity ; INT
, "Ptr", pInfo ; UIDNAInfo* in/out
, "Ptr", pErrorCode ; UErrorCode* in/out
, "Cdecl Int") ; return: INT●uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode) = DLL("icuuc.dll", "int uidna_nameToASCII_UTF8(void*, char*, int, char*, int, void*, void*)")
# 呼び出し: uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode)
# idna : UIDNA* -> "void*"
# name : LPCSTR -> "char*"
# length : INT -> "int"
# dest : LPSTR -> "char*"
# capacity : INT -> "int"
# pInfo : UIDNAInfo* 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 uidna_nameToASCII_UTF8(
idna: [*c]isize, // UIDNA*
name: [*c]const u8, // LPCSTR
length: i32, // INT
dest: [*c]const u8, // LPSTR
capacity: i32, // INT
pInfo: [*c]UIDNAInfo, // UIDNAInfo* in/out
pErrorCode: [*c]i32 // UErrorCode* in/out
) callconv(.c) i32;proc uidna_nameToASCII_UTF8(
idna: ptr int, # UIDNA*
name: cstring, # LPCSTR
length: int32, # INT
dest: cstring, # LPSTR
capacity: int32, # INT
pInfo: ptr UIDNAInfo, # UIDNAInfo* in/out
pErrorCode: ptr int32 # UErrorCode* in/out
): int32 {.importc: "uidna_nameToASCII_UTF8", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int uidna_nameToASCII_UTF8(
ptrdiff_t* idna, // UIDNA*
const(char)* name, // LPCSTR
int length, // INT
const(char)* dest, // LPSTR
int capacity, // INT
UIDNAInfo* pInfo, // UIDNAInfo* in/out
int* pErrorCode // UErrorCode* in/out
);ccall((:uidna_nameToASCII_UTF8, "icuuc.dll"), Int32,
(Ptr{Int}, Cstring, Int32, Cstring, Int32, Ptr{UIDNAInfo}, Ptr{Int32}),
idna, name, length, dest, capacity, pInfo, pErrorCode)
# idna : UIDNA* -> Ptr{Int}
# name : LPCSTR -> Cstring
# length : INT -> Int32
# dest : LPSTR -> Cstring
# capacity : INT -> Int32
# pInfo : UIDNAInfo* in/out -> Ptr{UIDNAInfo}
# pErrorCode : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
int32_t uidna_nameToASCII_UTF8(
intptr_t* idna,
const char* name,
int32_t length,
const char* dest,
int32_t capacity,
void* pInfo,
int32_t* pErrorCode);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode)
-- idna : UIDNA*
-- name : LPCSTR
-- length : INT
-- dest : LPSTR
-- capacity : INT
-- pInfo : UIDNAInfo* in/out
-- pErrorCode : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const uidna_nameToASCII_UTF8 = lib.func('__cdecl', 'uidna_nameToASCII_UTF8', 'int32_t', ['intptr_t *', 'str', 'int32_t', 'str', 'int32_t', 'void *', 'int32_t *']);
// uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode)
// idna : UIDNA* -> 'intptr_t *'
// name : LPCSTR -> 'str'
// length : INT -> 'int32_t'
// dest : LPSTR -> 'str'
// capacity : INT -> 'int32_t'
// pInfo : UIDNAInfo* in/out -> 'void *'
// pErrorCode : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
uidna_nameToASCII_UTF8: { parameters: ["pointer", "buffer", "i32", "buffer", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode)
// idna : UIDNA* -> "pointer"
// name : LPCSTR -> "buffer"
// length : INT -> "i32"
// dest : LPSTR -> "buffer"
// capacity : INT -> "i32"
// pInfo : UIDNAInfo* in/out -> "pointer"
// pErrorCode : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t uidna_nameToASCII_UTF8(
intptr_t* idna,
const char* name,
int32_t length,
const char* dest,
int32_t capacity,
void* pInfo,
int32_t* pErrorCode);
C, "icuuc.dll");
// $ffi->uidna_nameToASCII_UTF8(idna, name, length, dest, capacity, pInfo, pErrorCode);
// idna : UIDNA*
// name : LPCSTR
// length : INT
// dest : LPSTR
// capacity : INT
// pInfo : UIDNAInfo* 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);
int uidna_nameToASCII_UTF8(
LongByReference idna, // UIDNA*
String name, // LPCSTR
int length, // INT
String dest, // LPSTR
int capacity, // INT
Pointer pInfo, // UIDNAInfo* in/out
IntByReference pErrorCode // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun uidna_nameToASCII_UTF8 = uidna_nameToASCII_UTF8(
idna : LibC::SSizeT*, # UIDNA*
name : UInt8*, # LPCSTR
length : Int32, # INT
dest : UInt8*, # LPSTR
capacity : Int32, # INT
pInfo : UIDNAInfo*, # UIDNAInfo* in/out
pErrorCode : Int32* # UErrorCode* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef uidna_nameToASCII_UTF8Native = Int32 Function(Pointer<IntPtr>, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Void>, Pointer<Int32>);
typedef uidna_nameToASCII_UTF8Dart = int Function(Pointer<IntPtr>, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Void>, Pointer<Int32>);
final uidna_nameToASCII_UTF8 = DynamicLibrary.open('icuuc.dll')
.lookupFunction<uidna_nameToASCII_UTF8Native, uidna_nameToASCII_UTF8Dart>('uidna_nameToASCII_UTF8');
// idna : UIDNA* -> Pointer<IntPtr>
// name : LPCSTR -> Pointer<Utf8>
// length : INT -> Int32
// dest : LPSTR -> Pointer<Utf8>
// capacity : INT -> Int32
// pInfo : UIDNAInfo* in/out -> Pointer<Void>
// pErrorCode : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function uidna_nameToASCII_UTF8(
idna: Pointer; // UIDNA*
name: PAnsiChar; // LPCSTR
length: Integer; // INT
dest: PAnsiChar; // LPSTR
capacity: Integer; // INT
pInfo: Pointer; // UIDNAInfo* in/out
pErrorCode: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'uidna_nameToASCII_UTF8';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "uidna_nameToASCII_UTF8"
c_uidna_nameToASCII_UTF8 :: Ptr CIntPtr -> CString -> Int32 -> CString -> Int32 -> Ptr () -> Ptr Int32 -> IO Int32
-- idna : UIDNA* -> Ptr CIntPtr
-- name : LPCSTR -> CString
-- length : INT -> Int32
-- dest : LPSTR -> CString
-- capacity : INT -> Int32
-- pInfo : UIDNAInfo* in/out -> Ptr ()
-- pErrorCode : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let uidna_nametoascii_utf8 =
foreign "uidna_nameToASCII_UTF8"
((ptr intptr_t) @-> string @-> int32_t @-> string @-> int32_t @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* idna : UIDNA* -> (ptr intptr_t) *)
(* name : LPCSTR -> string *)
(* length : INT -> int32_t *)
(* dest : LPSTR -> string *)
(* capacity : INT -> int32_t *)
(* pInfo : UIDNAInfo* in/out -> (ptr void) *)
(* 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 ("uidna_nameToASCII_UTF8" uidna-name-to-ascii-utf8 :convention :cdecl) :int32
(idna :pointer) ; UIDNA*
(name :string) ; LPCSTR
(length :int32) ; INT
(dest :string) ; LPSTR
(capacity :int32) ; INT
(p-info :pointer) ; UIDNAInfo* 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 $uidna_nameToASCII_UTF8 = Win32::API::More->new('icuuc',
'int uidna_nameToASCII_UTF8(LPVOID idna, LPCSTR name, int length, LPCSTR dest, int capacity, LPVOID pInfo, LPVOID pErrorCode)');
# my $ret = $uidna_nameToASCII_UTF8->Call($idna, $name, $length, $dest, $capacity, $pInfo, $pErrorCode);
# idna : UIDNA* -> LPVOID
# name : LPCSTR -> LPCSTR
# length : INT -> int
# dest : LPSTR -> LPCSTR
# capacity : INT -> int
# pInfo : UIDNAInfo* in/out -> LPVOID
# pErrorCode : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。