Matthias Wächter
9/12/2007 12:49:00 PM
On 12.09.2007 13:45, F. Senault wrote:
> You should look in the 3rd part, chapter 22, under "The Basic Types".
> Table 22.2, page 306 (in my PDF edition).
>
> It says :
>
> | Table 22.2. Substitutions in double-quoted strings
> | --------------------------------------------------------------
> | \a Bell / alert (0x07) \nnn Octal nnn
> | \b Backspace (0x08) \xnn Hex nn
> | \e Escape (0x1b) \cx Control-x
> | \f Formfeed (0x0c) \C-x Control-x
> | \n Newline (0x0a) \M-x Meta-x
> | \r Return (0x0d) \M-\C-x Meta-control-x
> | \s Space (0x20) \x x
> | \t Tab (0x09) #{code} Value of code
> | \v Vertical tab (0x0b)
> | --------------------------------------------------------------
>
> So, your example uses the octal representation.
Does anyone know a good reason for outputting 8 bit byte characters
as octals in String#inspect?
see string.c (1.8.6):
[...]
else {
sprintf(s, "\\%03o", c & 0377);
rb_str_buf_cat2(result, s);
}
[...]
why not make it:
sprintf(s, "\\x%02x", c & 0377);
I can't understand why it is desirable to introduce yet another base
that is rarely used outside of chmod and od (without options). We
learned decimals, we got used to binary and even hex, but why do we
need octals just for these control characters when there is no
benefit compared to the hex representation (note: both take 4 chars
to display)?
- Matthias