And yet another ...
5% slower ... than the fastest to date ->
SimmoTech's v2,
(an awesome piece of righteously parsimonious code).
85% less filling ... the diet version ->
44 vs 256 bytes
(.Net v2 and above)
private const int AddressBitsPerUnit = 5;
private const int BitsPerElement = 32;
private const int BitIndexMask = BitsPerElement - 1;
private static readonly int[] ValidLatinChars = { 0, 0, 134217726, 134217726, 0, 0, 2139095039, 2139095039 };
public static string ToggleCase_SimmoTech_MacMaverick( string s )
{
TextInfo currentCultureTextInfo = CultureInfo.CurrentCulture.TextInfo;
char[] chs = s.ToCharArray();
for ( int i = 0; i < s.Length; ++i )
{
char ch = chs[i];
if ( ch <= 0xFF )
{
int bitSet = 1 << ( ch & BitIndexMask );
if ( ( ValidLatinChars[( ch >> AddressBitsPerUnit )] & bitSet ) == bitSet )
{
chs[i] = (char) ( ch ^ 0x20 );
}
continue;
}
switch ( char.GetUnicodeCategory( ch ) )
{
case UnicodeCategory.UppercaseLetter:
chs[i] = currentCultureTextInfo.ToLower( ch );
break;
case UnicodeCategory.LowercaseLetter:
chs[i] = currentCultureTextInfo.ToUpper( ch );
break;
}
}
return ( new string( chs ) );
}
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.