てきとうなメモ

本の感想とか技術メモとか

chucknorrisと色のパーズ

For example:

test
...produces a document with a red background across all browsers and platforms.

Interestingly, while chucknorri produces a red background as well, chucknorr produces a yellow background.

HTML5のパーズは変なこと書くとエラーにするのではなく、なんとかそれっぽくパーズするようにしているというのは聞いていたけど色も適当にパーズしているのだね

10. Replace any character in input that is not in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F, and U+0061 LATIN SMALL LETTER A to U+0066 LATIN SMALL LETTER F with the character U+0030 DIGIT ZERO (0).
11. While input's length is zero or not a multiple of three, append a U+0030 DIGIT ZERO (0) character to input.
12. Split input into three strings of equal length, to obtain three components. Let length be the length of those components (one third the length of input).
13. If length is greater than 8, then remove the leading length-8 characters in each component, and let length be 8.
14. While length is greater than two and the first character in each component is a U+0030 DIGIT ZERO (0) character, remove that character and reduce length by one.
15. If length is still greater than two, truncate each component, leaving only the first two characters in each.
16. Let result be a simple color.

chucknorrisでためしてみると、

10. [0-9a-fA-F]以外を0にする

c00c0000000

11. 長さが3の倍数になるように最後に0をくっつける

c00c00000000

12. 同じ長さの3つの要素に分割

c00c 0000 0000

13. 9文字以上だったら先頭8文字にする
14. 先頭が0の場合、0がなくなるか2文字になるまで0を削除

c00c 00 00

15. まだ3文字以上だったら、先頭の2文字のみにする

c0 00 00

16. simple colorにする

#c00000←赤

となる。

chucknorriだと10文字なので11のところで同じc00c00000000になり#c00000になる。

chucknorrだと9文字なので11のところでc00c00000になる。その後は

c00 c00 000
c00 c00 00
c0 c0 00
#c0c000←黄

となる