private void Interpret(string rawLine) { if (AutoDetectLotro && LotroAutoDetect.IsLotroMarker(rawLine)) { lotroCompatible = true; } // remove comments string line = rawLine.Split('%')[0].Trim(); if (!inTune) { ParseHeader(line); } else { if (!(IsNullOrWhiteSpace.String(line) && rawLine != line)) // skip commented empty lines so they dont end tunes { if (!(!strict && IsNullOrWhiteSpace.String(line) && (tunes[tunes.Count - 1].RawCode == null || tunes[tunes.Count - 1].RawCode.Length == 0))) { ParseTune(line); } } } }
public void GetExpressionTestNullWhiteSpace() { var propertyName = "Country"; string value = string.Empty; var operation = new IsNullOrWhiteSpace(); var param = Expression.Parameter(typeof(Person), "x"); var parent = Expression.Property(param, "Birth"); var member = Expression.Property(parent, "Country"); var constant1 = Expression.Constant(4000D); var constant2 = Expression.Constant(5000D); BinaryExpression expression = (BinaryExpression)operation.GetExpression(member, constant1, constant2); //Testing the operation structure expression.Left.Should().BeNullChecking(propertyName, true); expression.NodeType.Should().Be(ExpressionType.OrElse); var isEmpty = (BinaryExpression)expression.Right; isEmpty.Left.Should().BeNullChecking(propertyName); isEmpty.NodeType.Should().Be(ExpressionType.AndAlso); isEmpty.Right.Should().BeAStringExpressionCheckingIf(propertyName, ExpressionType.Equal, value, false); //Testing the operation execution var lambda = Expression.Lambda <Func <Person, bool> >(expression, param); var people = TestData.People.Where(lambda.Compile()); var solution = TestData.People.Where(x => x.Birth == null || (x.Birth.Country == null || (x.Birth.Country != null && x.Birth.Country.Trim().ToLower() == string.Empty))); Assert.That(people, Is.EquivalentTo(solution)); }
private void ParseTune(string line) { const int kDefaultTuneLength = 1024; Tune tune = tunes[tunes.Count - 1]; if (tune.RawCode == null) { tune.RawCode = new StringBuilder(kDefaultTuneLength); } if (!IsNullOrWhiteSpace.String(line)) { char c = line.Trim()[0]; // add custom tokens for inlined stuff if (c == 'K' || c == 'L' || c == 'Q') { tune.RawCode.Append("[").Append(line.Trim()).Append("]"); } else if (!(c == 'I' || c == 'M' || c == 'm' || c == 'N' || c == 'O' || c == 'P' || c == 'R' || c == 'r' || c == 's' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'w')) { tune.RawCode.Append(line); } } else { // strip code of all stuff we don't care about StringBuilder newCode = new StringBuilder(kDefaultTuneLength); List <char> filteredChars = new List <char>() { '\\', '\n', '\r', '\t' }; if (tune.RawCode.Length == 0) { tune.Tokens = new List <string>(); return; } for (int i = 0; i < tune.RawCode.Length; ++i) { if (!filteredChars.Contains(tune.RawCode[i])) { newCode.Append(tune.RawCode[i]); } } tune.Tokens = Tokenize(newCode); } }
/// <summary> /// Takes an ABC 'K' key field and returns three out values corresponding to the key+mode, /// the custom defined accidentals, and a value indicating whether the accidentals are explicit. /// </summary> public static void Parse(string s, out string key, out Dictionary <char, int> accidentals, out bool exp) { key = null; accidentals = null; exp = false; s = s.Trim(); // shortcut if (Accidentals.ContainsKey(s)) { key = s; return; } if (KeyAliases.ContainsKey(s)) { key = KeyAliases[s]; return; } if (!IsNullOrWhiteSpace.String(s)) { try { // this will capture: // group 1: tonic (E, C#, Bb) // group 2: mode argument OR explicit accidentals argument (only first 3 letters of word are considered in matching) // group 3: rest of string containing accidental tokens var argsMatch = Regex.Match(s, @"^(?:\s*)([a-g][#b]?)(?:(?:\s*)(maj|min|ion|aeo|mix|dor|phr|lyd|loc|m|exp))?(?:\S*(.*))?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (argsMatch.Success) { var tonicMatch = argsMatch.Groups[1]; var modeMatch = argsMatch.Groups[2]; var restMatch = argsMatch.Groups[3]; var keyBuilder = new StringBuilder(5); // append tonic keyBuilder.Append(tonicMatch.Value.Substring(0, 1).ToUpperInvariant()); keyBuilder.Append(tonicMatch.Value.Substring(1).ToLowerInvariant()); // append mode if (modeMatch.Success) { if (modeMatch.Value.ToLowerInvariant().StartsWith("exp")) { // if the exp keyword is found, we explicitly define all accidentals exp = true; } else { // otherwise we're defining the mode if (modeMatch.Length > 2) { // get first three characters of mode var type = modeMatch.Value.Substring(0, 1).ToUpperInvariant() + modeMatch.Value.Substring(1, 2).ToLowerInvariant(); // convert from aliased modes to main mode switch (type) { default: keyBuilder.Append(modeMatch.Value.Substring(0, 1).ToUpperInvariant()); keyBuilder.Append(modeMatch.Value.Substring(1, 2).ToLowerInvariant()); break; case "Maj": case "Ion": break; case "Min": case "Aeo": keyBuilder.Append('m'); break; } } else { keyBuilder.Append(modeMatch.Value.ToLowerInvariant()); } } } // parse defined accidentals if (restMatch.Success && !IsNullOrWhiteSpace.String(restMatch.Value)) { accidentals = new Dictionary <char, int>(); // get all accidentals matches, accidentals in group 1, note in group 2 var matches = Regex.Matches(restMatch.Value, @"(__|_|=|\^\^|\^)([A-Ga-g])", RegexOptions.CultureInvariant); for (int i = 0; i < matches.Count; ++i) { var noteMatch = matches[i]; var note = noteMatch.Groups[2].Value.ToUpperInvariant()[0]; int accValue; switch (noteMatch.Groups[1].Value) { case "__": accValue = -2; break; case "_": accValue = -1; break; case "^^": accValue = 2; break; case "^": accValue = 1; break; case "=": default: accValue = 0; break; } accidentals[note] = accValue; } } key = keyBuilder.ToString(); } else { key = null; } } catch { key = null; } } else { key = null; } if (key != null) { string alias; if (Keys.KeyAliases.TryGetValue(key, out alias)) { key = alias; } if (!Keys.Accidentals.ContainsKey(key)) { key = null; } } }
private double ModifyNoteLength(string s) { bool div = false; string num = ""; double l = 1; for (int i = 0; i < s.Length; i++) { if ((int)s[i] >= 48 && (int)s[i] <= 57) { num += s[i]; } else if (s[i] == '/') { if (!div && !IsNullOrWhiteSpace.String(num)) { l = Convert.ToDouble(num); } else if (div && !IsNullOrWhiteSpace.String(num)) { l /= Convert.ToDouble(num); } else if (div) { l /= 2; } num = ""; div = true; } } if (l == 0) { l = 1; } if (num == "" && div) { num = "2"; } if (num != "") { double n = Convert.ToDouble(num); if (n > 0) { if (div) { l /= n; } else { l *= n; } } else { l = 1; } } return(noteLength * l); }