ホーム › Globalization › u_strFromUTF8Lenient
u_strFromUTF8Lenient
関数UTF-8バイト列を寛容な検証でUTF-16文字列へ変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
WORD* u_strFromUTF8Lenient(
WORD* dest,
INT destCapacity,
INT* pDestLength,
LPCSTR src,
INT srcLength,
UErrorCode* pErrorCode
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dest | WORD* | inout |
| destCapacity | INT | in |
| pDestLength | INT* | inout |
| src | LPCSTR | in |
| srcLength | INT | in |
| pErrorCode | UErrorCode* | inout |
戻り値の型: WORD*
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
WORD* u_strFromUTF8Lenient(
WORD* dest,
INT destCapacity,
INT* pDestLength,
LPCSTR src,
INT srcLength,
UErrorCode* pErrorCode
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_strFromUTF8Lenient(
ref ushort dest, // WORD* in/out
int destCapacity, // INT
ref int pDestLength, // INT* in/out
[MarshalAs(UnmanagedType.LPStr)] string src, // LPCSTR
int srcLength, // INT
ref int pErrorCode // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strFromUTF8Lenient(
ByRef dest As UShort, ' WORD* in/out
destCapacity As Integer, ' INT
ByRef pDestLength As Integer, ' INT* in/out
<MarshalAs(UnmanagedType.LPStr)> src As String, ' LPCSTR
srcLength As Integer, ' INT
ByRef pErrorCode As Integer ' UErrorCode* in/out
) As IntPtr
End Function' dest : WORD* in/out
' destCapacity : INT
' pDestLength : INT* in/out
' src : LPCSTR
' srcLength : INT
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function u_strFromUTF8Lenient Lib "icuuc" ( _
ByRef dest As Integer, _
ByVal destCapacity As Long, _
ByRef pDestLength As Long, _
ByVal src As String, _
ByVal srcLength 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
u_strFromUTF8Lenient = ctypes.cdll.icuuc.u_strFromUTF8Lenient
u_strFromUTF8Lenient.restype = ctypes.c_void_p
u_strFromUTF8Lenient.argtypes = [
ctypes.POINTER(ctypes.c_ushort), # dest : WORD* in/out
ctypes.c_int, # destCapacity : INT
ctypes.POINTER(ctypes.c_int), # pDestLength : INT* in/out
wintypes.LPCSTR, # src : LPCSTR
ctypes.c_int, # srcLength : INT
ctypes.c_void_p, # pErrorCode : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_strFromUTF8Lenient = Fiddle::Function.new(
lib['u_strFromUTF8Lenient'],
[
Fiddle::TYPE_VOIDP, # dest : WORD* in/out
Fiddle::TYPE_INT, # destCapacity : INT
Fiddle::TYPE_VOIDP, # pDestLength : INT* in/out
Fiddle::TYPE_VOIDP, # src : LPCSTR
Fiddle::TYPE_INT, # srcLength : INT
Fiddle::TYPE_VOIDP, # pErrorCode : UErrorCode* in/out
],
Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_strFromUTF8Lenient(
dest: *mut u16, // WORD* in/out
destCapacity: i32, // INT
pDestLength: *mut i32, // INT* in/out
src: *const u8, // LPCSTR
srcLength: i32, // INT
pErrorCode: *mut i32 // UErrorCode* in/out
) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr u_strFromUTF8Lenient(ref ushort dest, int destCapacity, ref int pDestLength, [MarshalAs(UnmanagedType.LPStr)] string src, int srcLength, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_strFromUTF8Lenient' -Namespace Win32 -PassThru
# $api::u_strFromUTF8Lenient(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)#uselib "icuuc.dll"
#func global u_strFromUTF8Lenient "u_strFromUTF8Lenient" sptr, sptr, sptr, sptr, sptr, sptr
; u_strFromUTF8Lenient varptr(dest), destCapacity, varptr(pDestLength), src, srcLength, pErrorCode ; 戻り値は stat
; dest : WORD* in/out -> "sptr"
; destCapacity : INT -> "sptr"
; pDestLength : INT* in/out -> "sptr"
; src : LPCSTR -> "sptr"
; srcLength : INT -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global u_strFromUTF8Lenient "u_strFromUTF8Lenient" var, int, var, str, int, int ; res = u_strFromUTF8Lenient(dest, destCapacity, pDestLength, src, srcLength, pErrorCode) ; dest : WORD* in/out -> "var" ; destCapacity : INT -> "int" ; pDestLength : INT* in/out -> "var" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global u_strFromUTF8Lenient "u_strFromUTF8Lenient" sptr, int, sptr, str, int, int ; res = u_strFromUTF8Lenient(varptr(dest), destCapacity, varptr(pDestLength), src, srcLength, pErrorCode) ; dest : WORD* in/out -> "sptr" ; destCapacity : INT -> "int" ; pDestLength : INT* in/out -> "sptr" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WORD* u_strFromUTF8Lenient(WORD* dest, INT destCapacity, INT* pDestLength, LPCSTR src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global u_strFromUTF8Lenient "u_strFromUTF8Lenient" var, int, var, str, int, int ; res = u_strFromUTF8Lenient(dest, destCapacity, pDestLength, src, srcLength, pErrorCode) ; dest : WORD* in/out -> "var" ; destCapacity : INT -> "int" ; pDestLength : INT* in/out -> "var" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WORD* u_strFromUTF8Lenient(WORD* dest, INT destCapacity, INT* pDestLength, LPCSTR src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global u_strFromUTF8Lenient "u_strFromUTF8Lenient" intptr, int, intptr, str, int, int ; res = u_strFromUTF8Lenient(varptr(dest), destCapacity, varptr(pDestLength), src, srcLength, pErrorCode) ; dest : WORD* in/out -> "intptr" ; destCapacity : INT -> "int" ; pDestLength : INT* in/out -> "intptr" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_strFromUTF8Lenient = icuuc.NewProc("u_strFromUTF8Lenient")
)
// dest (WORD* in/out), destCapacity (INT), pDestLength (INT* in/out), src (LPCSTR), srcLength (INT), pErrorCode (UErrorCode* in/out)
r1, _, err := procu_strFromUTF8Lenient.Call(
uintptr(dest),
uintptr(destCapacity),
uintptr(pDestLength),
uintptr(unsafe.Pointer(windows.BytePtrFromString(src))),
uintptr(srcLength),
uintptr(pErrorCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WORD*function u_strFromUTF8Lenient(
dest: Pointer; // WORD* in/out
destCapacity: Integer; // INT
pDestLength: Pointer; // INT* in/out
src: PAnsiChar; // LPCSTR
srcLength: Integer; // INT
pErrorCode: Pointer // UErrorCode* in/out
): Pointer; cdecl;
external 'icuuc.dll' name 'u_strFromUTF8Lenient';result := DllCall("icuuc\u_strFromUTF8Lenient"
, "Ptr", dest ; WORD* in/out
, "Int", destCapacity ; INT
, "Ptr", pDestLength ; INT* in/out
, "AStr", src ; LPCSTR
, "Int", srcLength ; INT
, "Ptr", pErrorCode ; UErrorCode* in/out
, "Cdecl Ptr") ; return: WORD*●u_strFromUTF8Lenient(dest, destCapacity, pDestLength, src, srcLength, pErrorCode) = DLL("icuuc.dll", "void* u_strFromUTF8Lenient(void*, int, void*, char*, int, void*)")
# 呼び出し: u_strFromUTF8Lenient(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
# dest : WORD* in/out -> "void*"
# destCapacity : INT -> "int"
# pDestLength : INT* in/out -> "void*"
# src : LPCSTR -> "char*"
# srcLength : INT -> "int"
# pErrorCode : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。