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