This looks wrong - the `0xF0` case is repeated twice, and if I understand http://en.wikipedia.org/wiki/UTF-8 correctly, I think there are actually four lead byte types: 0xxxxxxx, 110xxxxx, 1110xxxx, and 11110xxx (it sounds like the 5- and 6-byte types are no longer used). So you shouldn't be masking by `0xF8` in each case (since other bits after the first couple might be 1s in the shorter byte sequence cases) - you should literally just be testing the leading bits.

Instead of checking for a lead byte, it might be easier to check that it's not a continuation byte (since all continuation bytes start with 10). I suppose that could lead to more false positives (since we're not explicitly testing that the byte starts with a legal UTF-8 bit sequence), but since we're just using this to figure out the length to pass to the validation code, that might be fine.