C-printf Parser
提出詳細
type ControlsMap = { c: 'char' s: 'string' d: 'dec' o: 'oct' h: 'hex' f: 'float' p: 'pointer' } type Format<T extends string, Res extends ControlsMap[keyof ControlsMap][] = []> = T extends `${infer L}%${infer Fmt}${infer R}` ? Fmt extends keyof ControlsMap ? Format<R, [...Res, ControlsMap[Fmt]]> : Format<R, Res> : Res type ParsePrintFormat<T extends string> = Format<T>
提出日時 | 2023-08-30 08:56:00 |
---|---|
問題 | C-printf Parser |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<ParsePrintFormat<''>, []>>, Expect<Equal<ParsePrintFormat<'Any string.'>, []>>, Expect<Equal<ParsePrintFormat<'The result is %d.'>, ['dec']>>, Expect<Equal<ParsePrintFormat<'The result is %%d.'>, []>>, Expect<Equal<ParsePrintFormat<'The result is %%%d.'>, ['dec']>>, Expect<Equal<ParsePrintFormat<'The result is %f.'>, ['float']>>, Expect<Equal<ParsePrintFormat<'The result is %h.'>, ['hex']>>, Expect<Equal<ParsePrintFormat<'The result is %q.'>, []>>, Expect<Equal<ParsePrintFormat<'Hello %s: score is %d.'>, ['string', 'dec']>>, Expect<Equal<ParsePrintFormat<'The result is %'>, []>>, ]