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