private static LazyList <UChar> ParseAnnotation(IEnumerator <UChar> inputStream) { var content = new UStringBuilder(64); while (inputStream.MoveNext()) { var c = inputStream.Current; if (c == SpecialCharacters.AnnotationCloseBracket) { string replaced; if (ExternalCharacterDictionary.DoesMatch(content.ToString(), out replaced)) { content.Clear(); return(Seq(new UString(replaced).ToArray(), () => ParseNormal(inputStream))); } else { content.Clear(); return(Seq(new UChar[] { UnreplacedPlaceholder }, () => ParseNormal(inputStream))); } } else { content.Append(c); } } content.Clear(); return(Seq(content.ToUString().ToArray())); }
private static LazyList<UChar> ParseAnnotation(IEnumerator<UChar> inputStream) { var content = new UStringBuilder(64); while (inputStream.MoveNext()) { var c = inputStream.Current; if (c == SpecialCharacters.AnnotationCloseBracket) { string replaced; if (ExternalCharacterDictionary.DoesMatch(content.ToString(), out replaced)) { content.Clear(); return Seq(new UString(replaced).ToArray(), () => ParseNormal(inputStream)); } else { content.Clear(); return Seq(new UChar[] { UnreplacedPlaceholder }, () => ParseNormal(inputStream)); } } else { content.Append(c); } } content.Clear(); return Seq(content.ToUString().ToArray()); }
private static LazyList <Token> ParseNormal(IEnumerator <UChar> inputStream) { UStringBuilder _textFragment = new UStringBuilder(1024); UStringBuilder _tentativeParent = new UStringBuilder(16); ParentType type = _none; while (inputStream.MoveNext()) { var c = inputStream.Current; if (c == SpecialCharacters.BeforeRubyInitiater) { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); var token = new NormalToken(_textFragment.ToUString()); _textFragment.Clear(); _textFragment = null; _tentativeParent = null; return(LazyList <Token> .New(token, () => ParseRubyParent(inputStream))); } else if (c == SpecialCharacters.RubyOpen) { var token = new NormalToken(_textFragment.ToUString()); _textFragment.Clear(); _textFragment = null; UString parent = _tentativeParent.ToUString(); _tentativeParent.Clear(); _tentativeParent = null; return(LazyList <Token> .New(token, () => ParseRubyText(inputStream, parent))); } else { //暫定親字の継続検証 if (type.IsContinuous(c)) { _tentativeParent.Append(c); } else { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); _tentativeParent.Append(c); type = RubyParser.ClassifyParentType(c); } } } { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); var token = new NormalToken(_textFragment.ToUString()); return(LazyList <Token> .New(token)); } }
void IExchangableTextVisitor.RubyStart(UString rubyText) { if (_inRuby) { throw new Exception("Already in ruby text"); } _rubyBaseText.Clear(); _rubyText = rubyText; _inRuby = true; }
private static LazyList<Token> ParseNormal(IEnumerator<UChar> inputStream) { UStringBuilder _textFragment = new UStringBuilder(1024); UStringBuilder _tentativeParent = new UStringBuilder(16); ParentType type = _none; while (inputStream.MoveNext()) { var c = inputStream.Current; if (c == SpecialCharacters.BeforeRubyInitiater) { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); var token = new NormalToken(_textFragment.ToUString()); _textFragment.Clear(); _textFragment = null; _tentativeParent = null; return LazyList<Token>.New(token, () => ParseRubyParent(inputStream)); } else if (c == SpecialCharacters.RubyOpen) { var token = new NormalToken(_textFragment.ToUString()); _textFragment.Clear(); _textFragment = null; UString parent = _tentativeParent.ToUString(); _tentativeParent.Clear(); _tentativeParent = null; return LazyList<Token>.New(token, () => ParseRubyText(inputStream, parent)); } else { //暫定親字の継続検証 if (type.IsContinuous(c)) { _tentativeParent.Append(c); } else { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); _tentativeParent.Append(c); type = RubyParser.ClassifyParentType(c); } } } { _textFragment.Append(_tentativeParent.ToUString()); _tentativeParent.Clear(); var token = new NormalToken(_textFragment.ToUString()); return LazyList<Token>.New(token); } }
private void FlushLatinWord(UStringBuilder wordBuffer) { if (wordBuffer.Length > 0) { var word = wordBuffer.ToUString(); var length = _latinMetric.MeasureText(word.String); this.AppendObject(new LatinWord(word, length)); wordBuffer.Clear(); } }