From 009c6deb61bdba3dc31c1710478b3877388d8e12 Mon Sep 17 00:00:00 2001 From: otya128 Date: Sun, 23 Aug 2015 13:03:57 +0900 Subject: [PATCH] =?UTF-8?q?HEX$=E3=81=AB=E6=A1=81=E6=95=B0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/TEST.txt | 1 + SMILEBASIC/builtinfunctions.d | 21 ++++++++++++++++++--- SMILEBASIC/error.d | 8 ++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/SMILEBASIC/TEST.txt b/SMILEBASIC/TEST.txt index c031f3f..6fa6adf 100644 --- a/SMILEBASIC/TEST.txt +++ b/SMILEBASIC/TEST.txt @@ -32,6 +32,7 @@ ASSERT__ VAL("aa")==0, "VAL" ASSERT__ RAD(180)==PI(), "RAD" ASSERT__ DEG(RAD(180)), "DEG" +ASSERT__ HEX$(65535, 8)=="0000FFFF", "HEX$" ASSERT__ SUBST$("0123456789",0,"B")=="B","SUBST$" ASSERT__ SUBST$("0123456789",0,4,"B")=="B456789","SUBST$" ASSERT__ SUBST$("",0,4,"B")=="B","SUBST$" diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 20add47..66e21b2 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -365,10 +365,25 @@ class BuiltinFunction { return val.to!wstring; } - static wstring HEX(int val) + static wstring HEX(int val, DefaultValue!(int, false) digits) { - //ひどい - return val.to!string(16).to!wstring; + import std.format; + if(digits.isDefault) + { + //ひどい + return val.to!string(16).to!wstring; + } + if(digits > 8) + { + throw new OutOfRange(); + } + FormatSpec!char f; + f.spec = 'X'; + f.flZero = true; + f.width = cast(int)digits; + auto w = appender!wstring(); + formatValue(w, val, f); + return cast(immutable)(w.data); } static void SPSET(PetitComputer p, int id, int defno) { diff --git a/SMILEBASIC/error.d b/SMILEBASIC/error.d index 9a3c8a2..3450d74 100644 --- a/SMILEBASIC/error.d +++ b/SMILEBASIC/error.d @@ -64,6 +64,14 @@ class TypeMismatch : SmileBasicError super("Type mismatch"); } } +class OutOfRange : SmileBasicError +{ + this() + { + this.errnum = 10; + super("Out of range"); + } +} class OutOfDATA : SmileBasicError { this()