Core: CParser::ReadInt(int min, int max)

git-svn-id: svn://ultimatepp.org/upp/trunk@3367 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-04-22 12:40:07 +00:00
parent 143c6fb020
commit a5d2aa9aaf
5 changed files with 29 additions and 2 deletions

View file

@ -47,6 +47,7 @@ public:
String ReadIdt() throw(Error);
bool IsInt();
int ReadInt() throw(Error);
int ReadInt(int min, int max) throw(Error);
bool IsNumber() { return IsDigit(*term); }
bool IsNumber(int base);
uint32 ReadNumber(int base = 10) throw(Error);

View file

@ -149,6 +149,14 @@ int CParser::ReadInt() throw(Error) {
return sign * n;
}
int CParser::ReadInt(int min, int max) throw(Error)
{
int n = ReadInt();
if(n < min || n > max)
ThrowError("number is out of range");
return n;
}
bool CParser::IsNumber(int base)
{
if(IsDigit(*term))

View file

@ -199,11 +199,17 @@ spaces and digit.&]
[s5;:CParser`:`:ReadInt`(`)throw`(CParser`:`:Error`): [@(0.0.255) int]_[* ReadInt]()_[@(0.0.255) t
hrow](Error)&]
[s2;%% Reads the integer from the current position. If [* IsInt ]is
false, throws an [^topic`:`/`/Core`/src`/CParser`$en`-us`#CParser`:`:Error`:`:struct^ C
Parser`::Error].&]
false, throws an &]
[s7;%% [*/ Return value]-|Integer.&]
[s3; &]
[s4; &]
[s5;:CParser`:`:ReadInt`(int`,int`)throw`(CParser`:`:Error`): [@(0.0.255) int]_[* ReadInt
]([@(0.0.255) int]_[*@3 min], [@(0.0.255) int]_[*@3 max])_[@(0.0.255) throw](Error)&]
[s2;%% Performs ReadInt and then checks the result to be in [%-*@3 min]
<`= result <`= [%-*@3 max]. If not, throws a [^topic`:`/`/Core`/src`/CParser`$en`-us`#CParser`:`:Error`:`:struct^ C
Parser`::Error], otherwise returns it.&]
[s3;%% &]
[s4; &]
[s5;:CParser`:`:IsNumber`(`): [@(0.0.255) bool]_[* IsNumber]()&]
[s2;%% Tests for sign`-less number at current position `- there must
be digit at current position.&]

View file

@ -28,6 +28,9 @@ public:
int operator++(int) { int i = actual; Set(actual + 1); return i; }
int operator+=(int i) { Set(actual + i); return actual; }
int Get() const { return actual; }
int GetTotal() const { return total; }
operator int() { return actual; }
static const Style& StyleDefault();

View file

@ -68,6 +68,15 @@ nt]_[*@3 i])&]
[s2; Adds [%-*@3 i] steps to actual position.&]
[s3; &]
[s4;%- &]
[s5;:ProgressIndicator`:`:Get`(`)const:%- [@(0.0.255) int]_[* Get]()_[@(0.0.255) const]&]
[s2; Returns the current actual position. &]
[s3;%- &]
[s4;%- &]
[s5;:ProgressIndicator`:`:GetTotal`(`)const:%- [@(0.0.255) int]_[* GetTotal]()_[@(0.0.255) c
onst]&]
[s2; Returns the total number of steps (set by SetTotal).&]
[s3;%- &]
[s4;%- &]
[s5;:ProgressIndicator`:`:operator int`(`):%- [* operator_int]()&]
[s2; Returns the current actual position. &]
[s3; &]