public string To1337(string input, L337ness l337ness = L337ness.L337) { if (input == string.Empty) { return(input); } var words = _wordTokenizer.TokenizeString(input).ToArray(); var returnString = new StringBuilder(); for (var i = 0; i < words.Length; i++) { if (words[i].StartsWith("<")) { returnString.Append(" " + words[i]); continue; } foreach (var rule in _rulez) { words[i] = rule.Apply(words[i], l337ness); } returnString.Append(" " + words[i]); } return(returnString.ToString().TrimStart()); }
public Translation(string value = null, L337ness l337ness = L337ness.N00b, int weight = 0) { Value = value; IsEmpty = string.IsNullOrEmpty(Value); L337ness = l337ness; Weight = weight; }
public void Ctor_Create_HasValues(string value, L337ness l337ness, int weight) { var translation = new Translation(value, l337ness, weight); translation.Value.Should().Be(value); translation.L337ness.Should().Be(l337ness); translation.Weight.Should().Be(weight); translation.IsEmpty.Should().BeFalse(); }
public override int GetHashCode() { unchecked { int result = (Value != null ? Value.GetHashCode() : 0); result = (result * 397) ^ L337ness.GetHashCode(); result = (result * 397) ^ Weight; return(result); } }
public string Apply(string input, L337ness l337ness) { var translation = GetTranslation(l337ness); if (translation.IsEmpty) { return(input); } input += " "; return(translation.Translate(input, Trigger).TrimEnd()); }
public void Equals_Equality_AreEqual() { const string value = "value"; const L337ness l337ness = L337ness.N00b; const int weight = 10; var translation1 = new Translation(value, l337ness, weight); var translation2 = new Translation(value, l337ness, weight); translation1.Should().Be(translation2); }
/// <summary> /// Gets the translation. /// </summary> /// <param name="l337ness">The l337ness.</param> /// <returns></returns> private Translation GetTranslation(L337ness l337ness) { //if no translations are found, no translation is made if (Translationz.Any() == false) { return(new Translation()); } //find translations where 1337nes is within boundaries var resolvedTranslationz = Translationz.Where(t => t.L337ness <= l337ness).ToList(); //if no translations where 1337nes is within boundaries is found, no translation is made if (resolvedTranslationz.Any() == false) { return(new Translation()); } //calculate randomize sum var weigthSum = resolvedTranslationz.Sum(t => t.Weight); return(RandomizeTranslationByWeight(resolvedTranslationz, 0, weigthSum, _rand.Next(weigthSum))); }
public static string To1337(this string input, L337ness l337ness = L337ness.L337) { return(_translator.To1337(input, l337ness)); }