silk.platform.windows.command_line.
MSVC command-line encoding and decoding over Windows UTF-16 code units.
When to use#
Use CommandLine.parse for a complete host command line. It returns raw canonical WTF-8 arguments.
Argument zero has its own quote rules. No wildcard expansion or shell interpretation occurs.
CommandLine.encode prepares a NUL-terminated command line for direct executable launch.
Import as CommandLine with import silk.platform.windows.command_line { CommandLine }.
Public declarations: 1.
CommandLine#
pub struct CommandLineEncoding and decoding of executable names and arguments in Windows command lines.
Implementation CommandLine#
impl CommandLineAssociated function encode#
pub effect fn encode(program: &[u16], arguments: &[u16]) -> List<u16>
! HostInputError | OutOfMemoryError ? &mut AllocatorReturns a NUL-terminated command line for an explicitly selected Windows executable.
Details#
program is its raw UTF-16 argument-zero spelling, without NUL. arguments is a sequence
of NUL-terminated raw UTF-16 arguments; an empty sequence means no arguments, and a single
NUL means one empty argument. Lone surrogates are preserved. Every argument is quoted;
backslashes before quotes and at argument ends are escaped using MSVC rules. Argument
zero uses its separate rule, in which backslashes are literal.
The result contains at most 32,767 code units including its terminator. The caller must
pass the executable separately to CreateProcessW. This encoding is for executables,
not batch files or shell command strings.
Errors#
HostInputErrorifprogramis empty or contains NUL or a quote,argumentslacks its final NUL, or the encoded command exceeds the Windows length limit.OutOfMemoryErrorif the result cannot be allocated.
Associated function parse#
pub effect fn parse(units: &[u16]) -> List<Bytes> ! HostInputError | OutOfMemoryError ? &mut AllocatorReturns arguments in order, with the executable name at index zero.
Details#
units excludes the host NUL terminator. Empty input produces one empty program name.
Leading space or tab also produces an empty program name. Only space and tab separate arguments.
Quotes in argument zero toggle quoting; its backslashes are literal. Later arguments use
MSVC backslash parity and doubled quotes inside quoted text. An unmatched quote consumes the rest.
Lone UTF-16 surrogates survive as WTF-8 bytes, never as a valid UTF-8 string.
Errors#
HostInputErrorifunitscontains NUL.OutOfMemoryErrorif an argument or the argument list cannot be allocated.
Category: Windows platform.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.