private static Func <char, bool> MapPredicate(CharTypes type) { switch (type) { case CharTypes.Letter: return(char.IsLetter); case CharTypes.Digit: return(char.IsDigit); case CharTypes.Number: return(char.IsNumber); case CharTypes.Symbol: return(char.IsSymbol); case CharTypes.Punctuation: return(char.IsPunctuation); case CharTypes.WhiteSpace: return(char.IsWhiteSpace); case CharTypes.UpperCase: return(char.IsUpper); case CharTypes.LowerCase: return(char.IsLower); case CharTypes.Control: return(char.IsControl); case CharTypes.HighSurrogate: return(char.IsHighSurrogate); case CharTypes.LowSurrogate: return(char.IsLowSurrogate); case CharTypes.Separator: return(char.IsSeparator); default: throw new ArgumentOutOfRangeException(nameof(type)); } }
public CharClass(AttackTypes style, CharTypes classe, RaceTypes race, EntityTypes type, string name, string description, float attackPower, float defensePower, float attackSpeed, float attackRange, float moveSpeed, float maxHealth, float maxMana ) { this.style = style; this.classe = classe; this.race = race; this.type = type; this.attackPower = attackPower; this.defensePower = defensePower; this.attackSpeed = attackSpeed; this.attackRange = attackRange; this.moveSpeed = moveSpeed; this.maxHealth = maxHealth; this.maxMana = maxMana; this.name = name; this.description = description; }
static bool GetNumber(string source, CharTypes type, ref int pos, out long value) { INumberComverter number = null; switch (type) { case CharTypes.kNumber: number = new NumberConverter(source[pos]); break; case CharTypes.kRomanNumber: number = new RomanNumberConverter(source[pos]); break; case CharTypes.kJpRomanNumber: number = new JpRomanNumberConverter(source[pos]); break; case CharTypes.kCircleNumber: number = new CircleNumberConverter(source[pos]); break; case CharTypes.kKanjiNumber: number = new KanjiNumberConverter(source[pos]); break; } for (int i0 = pos + 1; i0 < source.Length; ++i0) { if (number.AddChar(source[i0]) == false) { break; } } if (number.IsError == false) { value = number.Value; pos += number.Length; } else { value = 0; } return(number.IsError == false); }
public static IEnumerable<char> WhereAny(this IEnumerable<char> chars, CharTypes types) { var predicate = Enum.GetValues(typeof(CharTypes)) .Cast<CharTypes>() .ToDictionary(x => x, MapPredicate) .Where(x => types.HasFlag(x.Key)) .Select(x => x.Value) .AnyTrue(); return chars.Where(predicate); }
public static IEnumerable <char> WhereAny(this IEnumerable <char> chars, CharTypes types) { var predicate = Enum.GetValues(typeof(CharTypes)) .Cast <CharTypes>() .ToDictionary(x => x, MapPredicate) .Where(x => types.HasFlag(x.Key)) .Select(x => x.Value) .AnyTrue(); return(chars.Where(predicate)); }
private void AddOthers(CharTypes type, string word) { if (type == CharTypes.Other && word.Length > 2) { for (var i = 0; i < word.Length; i++) { for (var j = 1; i + j <= word.Length; j++) { Results.Add(word.Substring(i, j)); } } } }
private void Add(CharTypes type, string word) { if (word != string.Empty) { if (word.Length >= 2 && word.EndsWith("ー")) { word = word.Substring(0, word.Length - 1); } Results.Add(word); if (CreateIndex) { AddAlphabets(type, word); AddOthers(type, word); } } }
/// <summary> /// Builds a predicate from multiple character types /// </summary> /// <param name="charTypes"></param> /// <returns></returns> private static Func <char, bool> CharFunc(CharTypes charTypes) { var predicates = new Collection <Func <char, bool> >(); // Letters or Digits if (charTypes.HasFlags(CharTypes.LettersOrDigits)) { predicates.Add(char.IsLetterOrDigit); } else if (charTypes.HasFlags(CharTypes.Letters)) { predicates.Add(char.IsLetter); } else if (charTypes.HasFlags(CharTypes.Digits)) { predicates.Add(char.IsDigit); } // XML if (charTypes.HasFlags(CharTypes.XmlChar)) { predicates.Add(XmlConvert.IsXmlChar); } // White space if (charTypes.HasFlags(CharTypes.WhiteSpace)) { predicates.Add(char.IsWhiteSpace); } switch (predicates.Count) { case 1: return(predicates[0]); case 2: return(c => predicates[0](c) || predicates[1](c)); case 3: return(c => predicates[0](c) || predicates[1](c) || predicates[2](c)); } return(null); // //unfortunately, this slows things way down - if anyone knows of a better // //way to combine predicates, please weigh in! //return c => predicates.Any(p => p(c)); }
private static Func<char, bool> MapPredicate(CharTypes type) { switch (type) { case CharTypes.Letter: return char.IsLetter; case CharTypes.Digit: return char.IsDigit; case CharTypes.Number: return char.IsNumber; case CharTypes.Symbol: return char.IsSymbol; case CharTypes.Punctuation: return char.IsPunctuation; case CharTypes.WhiteSpace: return char.IsWhiteSpace; case CharTypes.UpperCase: return char.IsUpper; case CharTypes.LowerCase: return char.IsLower; case CharTypes.Control: return char.IsControl; case CharTypes.HighSurrogate: return char.IsHighSurrogate; case CharTypes.LowSurrogate: return char.IsLowSurrogate; case CharTypes.Separator: return char.IsSeparator; default: throw new ArgumentOutOfRangeException(nameof(type)); } }
private void AddAlphabets(CharTypes type, string word) { if (type == CharTypes.Lower || type == CharTypes.Upper) { Alphabets.Select((o, i) => new { Alphabet = o, Index = i }).ForEach(data => { for (var i = data.Index + 1; i <= Alphabets.Count() && i <= 3; i++) { Results.Add(Alphabets .Skip(data.Index) .Take(i) .Join(string.Empty) + word); } }); Alphabets.Add(word); } else { Alphabets.Clear(); } }
private void Add(CharTypes type, string word) { if (word != string.Empty) { switch (type) { case CharTypes.Hiragana: word = KanaEx.ToKatakana(word); break; } if (word.Length >= 2 && word.EndsWith("ー")) { word = word.Substring(0, word.Length - 1); } Results.Add(word); if (CreateIndex) { AddAlphabets(type, word); AddOthers(type, word); } } }
protected int InternalCompare(string s1, string s2) { if (string.IsNullOrEmpty(s1) != false) { return(string.IsNullOrEmpty(s2)? 0 : -1); } else if (string.IsNullOrEmpty(s2) != false) { return(1); } CharTypes filter = (CharTypes)(options & ComparerOptions.kNumberAll); CharTypes t1 = CharTypes.kNone; CharTypes t2 = CharTypes.kNone; char c1 = char.MinValue; char c2 = char.MinValue; int p1 = 0; int p2 = 0; s1 = ConvertChar(s1); s2 = ConvertChar(s2); while (p1 < s1.Length && p2 < s2.Length) { t1 = GetCharType(s1[p1], c1, t1) & filter; t2 = GetCharType(s2[p2], c2, t2) & filter; c1 = s1[p1]; c2 = s2[p2]; /* 両方とも何らかの数字の場合 */ if ((IgnoreNumber != false || (IgnoreNumber == false && t1 == t2)) && t1 != CharTypes.kNone && t2 != CharTypes.kNone) { int i1 = p1; int i2 = p2; long v1 = 0; long v2 = 0; bool success = (GetNumber(s1, t1, ref i1, out v1) != false) && (GetNumber(s2, t2, ref i2, out v2) != false); if (success != false) { if (v1 < v2) { return(-1); } else if (v1 > v2) { return(1); } p1 = i1; p2 = i2; } else { int diff = CompareChar(s1[p1], s2[p2]); if (diff != 0) { return(diff); } p1++; p2++; } } /* いずれかが数字の場合 */ else if ((t1 != CharTypes.kNone || t2 != CharTypes.kNone) && t1 != CharTypes.kRomanNumber && t2 != CharTypes.kRomanNumber) { return((t1 != CharTypes.kNone) ? 1 : -1); } /* 数字でない場合は文字コードを比較する */ else { int diff = CompareChar(s1[p1], s2[p2]); if (diff != 0) { return(diff); } p1++; p2++; } } /* 共通部分が一致している場合は、残りの文字列長で大小関係を決める */ if (p1 >= s1.Length) { return((p2 >= s2.Length) ? 0 : -1); } return(1); }
public RandomCharSequence(CharTypes charTypes) { CharTypes = charTypes; }
public static IEnumerable<char> WhereAny(CharTypes types) { return All.WhereAny(types); }
/// <summary>文字の種類を取得します。</summary> /// <param name="c">取得対象の文字を表す char。</param> /// <param name="back">直前の文字を表す char。</param> /// <param name="state">直前の文字の種類を表す <see cref="CharTypes"/>。</param> /// <returns>取得した文字の種類を表す <see cref="CharTypes"/>。</returns> private CharTypes GetCharType(char c, char back, CharTypes state) { // ASCIIアラビア数字 (0~9) if (c >= '0' && c <= '9') { return(CharTypes.Number); } // 日本語アラビア数字 (0~9) else if (c >= '0' && c <= '9') { return(CharTypes.Number); } // 日本語丸数字 (①~⑳) else if (c >= '①' && c <= '⑳') { return(CharTypes.CircleNumber); } // ASCII英大文字 (A~Z) else if (c >= 'A' && c <= 'Z') { // ASCIIローマ数字 (I,V,X,L,C,D,M) if (back < 'A' || back > 'Z') { switch (c) { case 'I': case 'V': case 'X': case 'L': case 'C': case 'D': case 'M': return(CharTypes.RomanNumber); } } } // ASCII英小文字 (a~z) else if (c >= 'a' && c <= 'z') { // ASCIIローマ数字 (i,v,x,l,c,d,m) if ((back < 'A' || back > 'Z') && (back < 'a' || back > 'z')) { switch (c) { case 'i': case 'v': case 'x': case 'l': case 'c': case 'd': case 'm': return(CharTypes.RomanNumber); } } } // 日本語英大文字 (A~Z) else if (c >= 'A' && c <= 'Z') { // 日本語ローマ数字 (I,V,X,L,C,D,M) if (back < 'A' || back > 'Z') { switch (c) { case 'I': case 'V': case 'X': case 'L': case 'C': case 'D': case 'M': return(CharTypes.RomanNumber); } } } // 日本語英小文字 (a~z) else if (c >= 'a' && c <= 'z') { // 日本語ローマ数字 (ⅰ,ⅴ,ⅹ,l,c,d,m) if ((back < 'A' || back > 'Z') && (back < 'a' || back > 'z')) { switch (c) { case 'ⅰ': case 'ⅴ': case 'ⅹ': case 'l': case 'c': case 'd': case 'm': return(CharTypes.RomanNumber); } } } // ローマ数字 else if (c >= 0x2160 && c <= 0x217F) { return(CharTypes.JpRomanNumber); } else { // 日本語漢数字 if (state == CharTypes.KanjiNumber) { switch (c) { case '〇': case '一': case '二': case '三': case '四': case '五': case '六': case '七': case '八': case '九': case '十': case '百': case '千': case '万': case '億': case '兆': case '京': case '壱': case '弐': case '参': case '拾': return(CharTypes.KanjiNumber); } } else { switch (c) { case '〇': case '一': case '二': case '三': case '四': case '五': case '六': case '七': case '八': case '九': case '十': case '百': case '千': case '壱': case '弐': case '参': return(CharTypes.KanjiNumber); } } } return(CharTypes.None); }
static void Main(string[] args) { //***** Exemple 1 ***** // Spécifiez une instance de balise. ColorTypes tagValue = ColorTypes.Rouge; if (tagValue == ColorTypes.Rouge) { // Sera afficher. Console.WriteLine("Rouge"); } else { // Ne Sera pas afficher. Console.WriteLine("Pas Vrai"); } Console.WriteLine(); //Affiche : //Rouge //***** Exemple 2 ***** //Console.WriteLine peut appeler automatiquement la méthode ToString. // ... Deux variables enum. ColorTypes color = ColorTypes.Bleu; VisibilityTypes visible = VisibilityTypes.Hidden; // ... Utilisez Console.WriteLine pour imprimer les valeurs d'héritier. Console.WriteLine(color); Console.WriteLine(visible); Console.WriteLine(); //***** Exemple 3 ***** // ... Test enum avec la méthode switch. FormatTypes formatValue = FormatTypes.None; if (IsFormat(formatValue)) { // Ceci n'est pas atteint, car None ne renvoie pas une vraie valeur dans IsFormat. Console.WriteLine("Error"); } // ... Testez une autre énumération avec switch. formatValue = FormatTypes.ItalicsFormat; if (IsFormat(formatValue)) { // Ceci est imprimé, car nous recevons true de IsFormat. Console.WriteLine("True"); } Console.WriteLine(); //Affiche : //True //*********************************************************** // ***** recupere un Char defini dans l'enum ***** CharTypes charEnum = CharTypes.AnoniemNIETActive; Console.WriteLine("{0}: {1}", (char)charEnum, charEnum); Console.WriteLine(); //Affiche : //R : AnoniemNIETActive // ***** recupere un string defini dans l'enum ***** ColorTypes colorType = ColorTypes.Bleu; Console.WriteLine(colorType); Console.WriteLine("string : " + colorType + ", " + "Valeur : " + (int)colorType); Console.WriteLine(); //Affiche : //Bleu //string : Bleu, Valeur : 33 //ou foreach (var item in Enum.GetNames(typeof(ColorTypes)).ToList()) { Console.WriteLine(item); } Console.WriteLine(); //Affiche : //Rouge //Vert //Bleu // ***** recupere les valeurs defini dans l'enum ***** foreach (int item in Enum.GetValues(typeof(ColorTypes))) { Console.WriteLine(item); } Console.WriteLine(); //Affiche : //0 //1 //2 //33 foreach (int item in Enum.GetValues(typeof(CharTypes))) { Console.WriteLine(item); } Console.WriteLine(); //Affiche : //32 //65 //82 //87 //90 Console.WriteLine((char)(int)CharTypes.Archive); Console.WriteLine((char)CharTypes.AnoniemActive); Console.WriteLine(CharTypes.AnoniemActive); }
public static IEnumerable <char> WhereAny(CharTypes types) { return(All.WhereAny(types)); }
// conflicts with 3.5 versions //public static string Remove(this string value, params char[] chars) //{ // return value.Remove(c => Array.IndexOf(chars, c) > -1); //} //public static string Remove(this string value, string chars) //{ // return value.Remove(chars.ToCharArray()); //} /// <summary> /// Removes characters by character type /// </summary> /// <param name="value"></param> /// <param name="charTypes"></param> /// <returns></returns> public static string Remove(this string value, CharTypes charTypes) { return(value.Remove(CharFunc(charTypes))); }
/// <summary>オブジェクトの大小関係を比較します。</summary> /// <param name="s1">比較対象のオブジェクトを表す string。</param> /// <param name="s2">比較対象のオブジェクトを表す string。</param> /// <returns> /// <list type="table"> /// <item><term>0 より小さい</term><description><paramref name="s1"/> が <paramref name="s2"/> より小さい。</description></item> /// <item><term>0</term><description><paramref name="s1"/> と <paramref name="s2"/> は等しい。</description></item> /// <item><term>0 より大きい</term><description><paramref name="s1"/> が <paramref name="s2"/> より大きい。</description></item> /// </list> /// </returns> protected virtual int LocalCompare(string s1, string s2) { // いずれかが null もしくは空文字であれば比較終了 if (string.IsNullOrEmpty(s1)) { return(string.IsNullOrEmpty(s2) ? 0 : -1); } else if (string.IsNullOrEmpty(s2)) { return(1); } CharTypes filter = (CharTypes)(_options & NaturalComparerOptions.NumberAll); CharTypes t1 = CharTypes.None; CharTypes t2 = CharTypes.None; int p1 = 0; int p2 = 0; char c1 = char.MinValue; char c2 = char.MinValue; s1 = ConvertChar(s1); s2 = ConvertChar(s2); // 除外文字を読み飛ばす if (_ignoreTable.Length > 0) { SkipIgnoreCharacter(s1, ref p1); SkipIgnoreCharacter(s1, ref p2); } while (p1 < s1.Length && p2 < s2.Length) { t1 = GetCharType(s1[p1], c1, t1) & filter; t2 = GetCharType(s2[p2], c2, t2) & filter; c1 = s1[p1]; c2 = s2[p2]; // 両方とも何らかの数字の場合 if ((this.IgnoreNumber || (this.IgnoreNumber == false && t1 == t2)) && t1 != CharTypes.None && t2 != CharTypes.None) { int i1 = p1; int i2 = p2; long v1 = 0; long v2 = 0; bool success = GetNumber(s1, t1, ref i1, out v1) && GetNumber(s2, t2, ref i2, out v2); if (success) { if (v1 < v2) { return(-1); } else if (v1 > v2) { return(1); } p1 = i1; p2 = i2; } else { int diff = CompareChar(s1[p1], s2[p2]); if (diff != 0) { return(diff); } p1++; p2++; } } // いずれかが数字の場合 else if ((t1 != CharTypes.None || t2 != CharTypes.None) && t1 != CharTypes.RomanNumber && t2 != CharTypes.RomanNumber) { return((t1 != CharTypes.None) ? 1 : -1); } // 数字でない場合は文字コードを比較する else { int diff = CompareChar(s1[p1], s2[p2]); if (diff != 0) { return(diff); } p1++; p2++; } // 除外文字を読み飛ばす if (_ignoreTable.Length > 0) { SkipIgnoreCharacter(s1, ref p1); SkipIgnoreCharacter(s2, ref p2); } } // 共通部分が一致している場合は、残りの文字列長で大小関係を決める if (p1 >= s1.Length) { return((p2 >= s2.Length) ? 0 : -1); } else { return(1); } }
/// <summary> /// Extracts characters by character type /// </summary> /// <param name="value"></param> /// <param name="charTypes"></param> /// <returns></returns> public static string Extract(this string value, CharTypes charTypes) { return(value.Extract(CharFunc(charTypes))); }
public CharClass GetClass(CharTypes classe) { return(characters.First(x => x.Classe == classe)); }