[Oberon] Username which contains the "@" char ...
jan verhoeven
jan at verhoeven272.nl
Thu Jan 5 23:26:59 CET 2006
Op Thursday 05 January 2006 21:49 schreef shark at gulfnet.sd64.bc.ca:
> "http://carnot.pathology.ubc.ca/pe.RFC2396.Mod" => pe.RFC2396.Mod ~
Some comments from a nitpicker, which might work and perhaps not. My
experience with Oberon is yet minimal. I do mostly Modula-2.
-------------------------------------------
PROCEDURE HexVal(ch: CHAR): INTEGER;
BEGIN
IF (ch >= "0") & (ch <= "9") THEN
RETURN ORD(ch)-ORD("0")
ELSIF (ch >= "A") & (ch <= "F") THEN
RETURN ORD(ch)-ORD("A")+10
ELSIF (ch >= "a") & (ch <= "f") THEN
RETURN ORD(ch)-ORD("a")+10
END
END HexVal;
mine:
PROCEDURE HexVal(ch: CHAR): INTEGER;
BEGIN
ch := CAP (ch);
IF (ch >= "0") & (ch <= "9") THEN
RETURN ORD(ch)-ORD("0")
ELSIF (ch >= "A") & (ch <= "F") THEN
RETURN ORD(ch)-ORD("A")+10
END
END HexVal;
-------------------------------------------
PROCEDURE LogChars(s: ARRAY OF CHAR);
VAR i: LONGINT;
BEGIN
i := 0;
WHILE ~((i = LEN(s)) OR (s[i] = 0X)) DO
Texts.Write(W, s[i]);
INC(i)
END;
END LogChars;
mine:
PROCEDURE LogChars(s: ARRAY OF CHAR);
VAR i: LONGINT;
BEGIN
i := 0;
WHILE (i < LEN(s)) AND (s[i] # 0X) DO
Texts.Write(W, s[i]);
INC(i)
END;
END LogChars;
Complex negations are not easy to read.
-------------------------------------------
PROCEDURE HexDigit(i: INTEGER): CHAR;
BEGIN
IF i < 10 THEN
RETURN CHR(i+ORD("0"))
ELSE
RETURN CHR(i-10+ORD("A"))
END
END HexDigit;
mine:
PROCEDURE HexDigit(i: INTEGER): CHAR;
BEGIN
RETURN HexDigs [i];
END HexDigit;
Where HexDigs = "0123456789ABCDEF"
-------------------------------------------
ELSIF (source[is] = "%") & Strings.IsHexDigit(source[is+1])
& Strings.IsHexDigit(source[is+2]) THEN INC(is); INC(is)
(* ELSE literal character *)
mine:
ELSIF (source[is] = "%") & Strings.IsHexDigit(source[is+1])
& Strings.IsHexDigit(source[is+2]) THEN INC(is, 2)
(* ELSE literal character *)
Question: what happens when someone enters '%GG' in the string? The
condition will be false, so the conversion will not be carried out. But
also the indexes are not incremented. Hence the '%' is stripped but the
'GG' part remains in the string. Is this the meaning?
-------------------------------------------
PROCEDURE RequiresEscape(ch:CHAR):BOOLEAN;
BEGIN
IF (ch = 0X)
THEN
RETURN(FALSE)
ELSIF (ch <= 020X) OR (ch = "+") OR (ch = "&") OR (ch = "=") OR (ch = "?")
OR (ch = "%") OR (ch = "$") OR (ch = ";") OR (ch = "#") OR (ch = ":")
OR (ch = special)
THEN
RETURN(TRUE)
ELSE
RETURN(FALSE)
END
END RequiresEscape;
mine:
TYPE SpecalChar = ('+', '&', '=', '?', '%', '$', ';', '#', ':');
SpecialCharSet = SET OF SpecialChar;
PROCEDURE RequiresEscape(ch:CHAR):BOOLEAN;
BEGIN
IF (ch = 0X)
THEN
RETURN(FALSE)
ELSIF (ch <= 020X) OR (ch IN SpecialCharSet OR (ch = special) THEN
RETURN(TRUE)
ELSE
RETURN(FALSE)
END
END RequiresEscape;
-------------------------------------------
ELSIF RequiresEscape(source[is]) THEN INC(it); INC(it); INC(it); INC(is)
mine:
ELSIF RequiresEscape(source[is]) THEN INC(it, 3); INC(is)
If you forget one INC (it) you're in for a surprise.
-------------------------------------------
IF it < tlen THEN (* The escaped version will fit into the target array. *)
ELSE
INC(errors);
LogString("RFC2396.ESC.ESC1: Escaped version of string "); LogLn;
Log(22X); LogString(source); Log(22X); LogLn;
LogString("will be too long for the array. Not escaping."); LogLn;
RETURN
END;
THEN what? If only the ELSE is needed, why not invert the Boolean
expression?
-------------------------------------------
I think you are overcomplicating things with the backward fill/conversion
cycle. It doesn't really matter if you do a normal fill/conversion. Your
method is slightly easier to code due to the filling with HexDigits.
-------------------------------------------
--
Met vriendelijke groeten
Jan Verhoeven
http://fruttenboel.verhoeven272.nl
More information about the Oberon
mailing list