using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace miew.Character
{
public static class Extensions
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsDigit(this Char ch)
{
return ('0' <= ch && ch <= '9');
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsHex(this char ch)
{
return (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f'));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static Byte HexToByte(this Char ch)
{
if ('0' <= ch && ch <= '9')
return (Byte)(ch - '0');
else if ('A' <= ch && ch <= 'F')
return (Byte)(ch - 'A' + 10);
else if ('a' <= ch && ch <= 'f')
return (Byte)(ch - 'a' + 10);
return 0;
}
}
namespace Thai
{
public static class Extensions
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThai(this Char ch)
{
return ('ก' <= ch && ch <= '๛');
}
public static bool IsSEAsian(this Char ch)
{
// Thai, lao, and Khmer
return (0x0e00 <= ch && ch <= 0x0eff) || (0x1780 <= ch && ch <= 0x17ff);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThaiCons(this Char c)
{
return 'ก' <= c && c <= 'ฮ';
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThaiVowel(this Char c)
{
return 'ะ' <= c && c <= 'ๅ' && c != 'ฺ' && c != '฿';
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThaiDigit(this Char ch)
{
return ('๐' <= ch && ch <= '๙');
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// excludes Thai numeric digits
public static bool IsThaiAlpha(this Char ch)
{
return ('ก' <= ch && ch <= '๏');
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThaiNameChar(this Char ch)
{
return 'ก' <= ch && ch <= '์' && ch != '฿' && ch != 'ๆ'; // note: ฯ is allowed
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static bool IsThaiTone(this Char ch)
{
return (0x0e48 <= ch && ch <= 0x0e4b);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static Char Reinterpret(this Char ch, bool f_bullet)
{
if (0x00A1 <= ch && ch <= 0x00F9)
return (Char)(ch + 3424);
if (ch == 0x2022)
return f_bullet ? '•' : 'ท';
return ch;
}
};
};
}