From 6e1b378e7610bea09c342765b8d0674d1554d80f Mon Sep 17 00:00:00 2001 From: zx@soe.com.ua Date: Thu, 12 Aug 2010 13:32:40 +0300 Subject: [PATCH] search ranges Signed-off-by: zx --- SpellWork/Forms/FormMain.cs | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-) diff --git a/SpellWork/Forms/FormMain.cs b/SpellWork/Forms/FormMain.cs index 7640c8e..a2ae19b 100644 --- a/SpellWork/Forms/FormMain.cs +++ b/SpellWork/Forms/FormMain.cs @@ -154,19 +154,61 @@ namespace SpellWork AdvansedFilter(); } + private static System.Text.RegularExpressions.Regex FParseRangeRegEx = + new System.Text.RegularExpressions.Regex(@"^\d+-\d+$"); + + /// + /// returns true if input string contains range of integer numbers: "nnnn-nnnn", + /// regular expression to parse is: "^\d+-\d+$". If the range is set, method + /// also sets a couple of output uint values; otherwise they are set to 0 + /// + /// an input string to parse + /// left (lower) bound of range + /// right (upper) bound of range + /// + private static bool ParseRange(string AStr, out uint AFrom, out uint ATo) + { + bool locResult = false; + uint locFrom = 0, locTo = 0, locEx; + if (FParseRangeRegEx.IsMatch(AStr)) + { + string[] locRange = AStr.Split(new char[] { '-' }); + locFrom = locRange[0].ToUInt32(); + locTo = locRange[1].ToUInt32(); + if (locFrom > locTo) + { + locEx = locFrom; + locFrom = locTo; + locTo = locEx; + } + locResult = true; + } + AFrom = locFrom; + ATo = locTo; + return locResult; + } + private void AdvancedSearch() { string name = _tbSearchId.Text; uint id = name.ToUInt32(); + uint id_L, id_R; + bool id_isRange = ParseRange(name, out id_L, out id_R); uint ic = _tbSearchIcon.Text.ToUInt32(); + uint ic_L, ic_R; + bool ic_isRange = ParseRange(_tbSearchIcon.Text, out ic_L, out ic_R); uint at = _tbSearchAttributes.Text.ToUInt32(); _spellList = (from spell in DBC.Spell.Values where ((id == 0 || spell.ID == id) + && (!id_isRange || ((spell.ID >= id_L) && (spell.ID <= id_R))) + && (ic == 0 || spell.SpellIconID == ic) + && (!ic_isRange || (spell.SpellIconID >= ic_L && spell.SpellIconID <= ic_R)) + && (at == 0 || (spell.Attributes & at) != 0 || (spell.AttributesEx & at) != 0 || (spell.AttributesEx2 & at) != 0 @@ -176,7 +218,7 @@ namespace SpellWork || (spell.AttributesEx6 & at) != 0 || (spell.AttributesExG & at) != 0)) - && ((id != 0 || ic != 0 && at != 0) || spell.SpellName.ContainsText(name)) + && ((id != 0 || id_isRange || (ic != 0 || ic_isRange) && at != 0) || spell.SpellName.ContainsText(name)) select spell).ToList(); -- 1.6.5.1.1367.gcd48