Created
October 29, 2013 14:19
-
-
Save ishisaka/7215545 to your computer and use it in GitHub Desktop.
IVS文字かどうか調べる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Globalization; | |
using System.Windows.Forms; | |
namespace ConsoleApplication3 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var testString = "渡\u908A\uDB40\uDD07さん"; | |
var ivs = new TestIVS(); | |
for (int i = 0; i < testString.Length; i++) | |
{ | |
Console.WriteLine(ivs.IsIvsChar(testString, i)); | |
} | |
MessageBox.Show(testString); | |
Console.Read(); | |
} | |
} | |
public class TestIVS | |
{ | |
//日本の漢字の異字体セレクタはVariation Selector Supplementの範囲だけ使用される | |
private char VariationSelectorSupplementHi = '\uDB40'; | |
private char VariationSelectorSupplementLoStart = '\uDD00'; | |
private char VariationSelectorSupplementLoEnd = '\uDDEF'; | |
//それ以外だと以下が使われている可能性がある | |
private char VariationSelectorStart = '\uFE00'; | |
private char VariationSelectorEnd = '\uFE0F'; | |
//モンゴル文字用 | |
private char MongolianFreeVariationSelectorOne = '\u180B'; | |
private char MongolianFreeVariationSelectorThree = '\u180d'; | |
public bool IsIvsChar(string text, int index) | |
{ | |
char buf = text[index]; | |
if (buf == VariationSelectorSupplementHi | |
|| (VariationSelectorSupplementLoStart <= buf && buf <= VariationSelectorSupplementLoEnd) | |
||(VariationSelectorStart <= buf && buf <= VariationSelectorEnd) | |
|| (MongolianFreeVariationSelectorOne <= buf && buf <= MongolianFreeVariationSelectorThree)) | |
{ | |
return true; | |
} | |
return false; | |
} | |
} | |
} | |
/** | |
* http://www.fileformat.info/info/unicode/block/variation_selectors_supplement/list.htm | |
* http://www.fileformat.info/info/unicode/block/variation_selectors/index.htm | |
* http://ja.wikipedia.org/wiki/%E7%95%B0%E4%BD%93%E5%AD%97%E3%82%BB%E3%83%AC%E3%82%AF%E3%82%BF | |
* | |
* | |
* | |
* | |
* | |
* */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment