Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created February 14, 2012 18:09
Show Gist options
  • Save kumpera/1828685 to your computer and use it in GitHub Desktop.
Save kumpera/1828685 to your computer and use it in GitHub Desktop.
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
unsafe class Driver {
private unsafe static byte *category_data;
[MethodImpl (MethodImplOptions.AggressiveInlining)]
public static bool IsWhiteSpace (char c)
{
unsafe {
int category = category_data [c];
if (category <= ((int)UnicodeCategory.OtherNumber))
return false;
if (category <= ((int)UnicodeCategory.ParagraphSeparator))
return true;
// FIXME: (char)0x205F Medium Mathematical Space has wrong category in 2.0 Profile
// Remove the if NET_2_0 case once the error is corrected
return c >= (char)0x09 && c <= (char)0x0d || c == (char)0x85 || c == (char)0x205F;
}
}
static void Main () {
Console.WriteLine (IsWhiteSpace (' '));
Console.WriteLine (IsWhiteSpace ('x'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment