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