public override string Next() { Collection.List<Element> result; bool hasDigit; bool hasUppercase; do { result = new Collection.List<Element>(); hasDigit = false; hasUppercase = false; Element last = null; Element secondLast = null; int length = 0; while (length < this.Length) { Element next; do next = Element.Phonemes[this.Generate(Element.Phonemes.Length)]; while (last.IsNull() ? next.NotFirst : last.Digit || (next.Vowel ? last.Vowel && (last.Dipthong || next.Dipthong || secondLast.NotNull() && secondLast.Vowel || this.Generate(10) > 7) : !last.Vowel) || length + next.Length > this.Length); if (this.WithUppercase && this.Generate(10) < 2) { next = next.ToUpper(); hasUppercase = true; } secondLast = last; result.Add(last = next); length += next.Length; if (length < this.Length) { if (this.WithDigits && this.Generate(10) < 3) { next = Element.CreateDigit(this.Generate(10)); result.Add(next); length += next.Length; hasDigit = true; } } } } while (this.WithDigits != hasDigit || this.WithUppercase != hasUppercase); return result.Map(element => element.Symbol).Join(); }
bool ParseHelper() { this.reader.Next(); while (!this.reader.Empty) { IO.Text.Mark mark = this.Mark(); switch (this.reader.Last) { case '<': if (!this.reader.Next()) return false; switch (this.reader.Last) { case '/': // end element this.OnElementEnd(this.AccumulateUntil('>').Trim(), mark); this.reader.Next(); break; case '?': // proccessing instruction string target = this.AccumulateUntilWhiteSpace().Trim(); if (target == "xml") { if (this.AccumulateUntil('=').Trim() != "version") return false; this.AccumulateUntil('"'); float version = float.Parse(this.AccumulateUntil('"'), System.Globalization.CultureInfo.InvariantCulture); if (this.AccumulateUntil('=').Trim() != "encoding") return false; this.AccumulateUntil('"'); string encoding = this.AccumulateUntil('"'); this.AccumulateUntil("?>").Trim(); this.OnDeclaration.Call(version, encoding, null, mark); } else this.OnProccessingInstruction.Call(target, this.AccumulateUntil("?>").Trim(), mark); this.reader.Next(); break; case '!': // CDATA section or comment if (!this.reader.Next()) return false; switch (this.reader.Last) { case '[': // CDATA section if (!this.Verify("CDATA[")) return false; this.OnData.Call(this.AccumulateUntil("]]>"), mark); this.reader.Next(); break; case '-': // comment if (!this.Verify("-")) return false; this.OnComment.Call(this.AccumulateUntil("-->"), mark); this.reader.Next(); break; } break; default: // element name string name = this.reader.Last + this.AccumulateUntilWhiteSpaceOr('/', '>').Trim(); Collection.IList<Tuple<string, string, Uri.Region>> attributes = new Collection.List<Tuple<string, string, Uri.Region>>(); if (this.reader.Last != '/' && this.reader.Last != '>') do { IO.Text.Mark attributeMark = this.Mark(); string key = (this.reader.Last + this.AccumulateUntil('=')).Trim(); this.AccumulateUntil('"'); attributes.Add(Tuple.Create(key, this.AccumulateUntil('"'), (Uri.Region)attributeMark)); while (this.reader.Next() && this.reader.Last == ' ') ; } while (this.reader.Last != '/' && this.reader.Last != '>' && !this.reader.Empty); this.OnElementStart.Call(name, attributes, mark); if (this.reader.Last == '/' && this.Verify(">")) { this.OnElementEnd(name, mark); this.reader.Next(); // Might have been the last element in fragment, eol acceptable. } else if (this.reader.Last != '>' || !this.reader.Next()) return false; break; } break; default: string text = (this.reader.Last + this.AccumulateUntil('<')).Trim(); if (text.NotEmpty()) this.OnText.Call(text, mark); break; } } return true; // returns false on errors within the function body }