This entire function needs to be rewritten if you take my proposed approach, but I just wanted to note here that parsing of the number can be simplified using `std::num::from_str_radix()`. Assuming we have an arg `s: &str` that contains e.g. `"#39"` it would look like

```rust
if s.starts_with("#") {
    let s = s.slice_from(1);
    let n: Option<u32> = if s.starts_with("x") {
        // hex
        num::from_str_radix(s.slice_from(1), 16)
    } else {
        num::from_str_radix(s, 10)
    };
    let n = match n {
        None => return Slice(""), // elide it completely for a parse error, I guess
        Some(n) => n
    };
    let c = match char::from_u32(n) {
        None => return Slice("\uFFFD"), // required according to HTML5 spec
        Some(c) => c
    };
    return str::from_char(c);
}
```