Exemple #1
0
func isAcronym(mb *util.MarkupBuilder, start int, length int) bool {
	cnt := 0

	for i := 0; i < length; i++ {
		if unicode.IsUpper(mb.RuneAt(start + i)) {
			cnt++

			if cnt > 1 {
				return true
			}
		}
	}

	return false
}
Exemple #2
0
func (ru *russianLanguage) isShyAllowed1(mb *util.MarkupBuilder, start int, i int, limit int) bool {
	if i == start || i+2 >= limit {
		return false
	}

	ru.buf.Reset()

	for j := start; j <= i; j++ {
		ru.buf.WriteRune(mb.RuneAt(j))
	}

	return IsVowel(mb.RuneAt(i+1)) || IsVowel(mb.RuneAt(i+2)) ||
		(IsSoftModifier(mb.RuneAt(i+2)) && i+3 < limit && IsVowel(mb.RuneAt(i+3))) ||
		IsPrefix(ru.buf.String())
}
Exemple #3
0
func (ru *russianLanguage) Hyphenate(mb *util.MarkupBuilder, start int, length int, shy string) {
	if isAcronym(mb, start, length) {
		return
	}

	limit := start + length

	for i := 0; i < length; i++ {
		at := start + i

		if IsVowel(mb.RuneAt(at)) {
			if ru.isShyAllowed1(mb, start, at, limit) {
				mb.AppendStringAt(at, shy)
			} else if ru.isShyAllowed2(mb, start, at, limit) {
				mb.AppendStringAt(at+1, shy)
			} else if ru.isShyAllowed3(mb, start, at, limit) {
				mb.AppendStringAt(at+2, shy)
			}
		}
	}
}
Exemple #4
0
func ProcessPunctuation(mb *util.MarkupBuilder, dash string, quotes map[int]string, qp QuotesProvider, removeSpacesAroundDash bool) {
	qAlt := false

	for i := 0; i <= mb.LastCharIndex(); i++ {
		r := mb.RuneAt(i)

		switch r {
		case '"':
			var qType int

			if i < mb.LastCharIndex() && unicode.IsLetter(mb.RuneAt(i+1)) {
				if qAlt {
					qType = qp.OpenAlt()
				} else {
					qType = qp.Open()
				}
			} else {
				if !qAlt {
					qType = qp.CloseAlt()
				} else {
					qType = qp.Close()
				}
			}

			qAlt = !qAlt

			if qStr, ok := quotes[qType]; ok {
				mb.SubstituteStringAt(i, 1, qStr)
			}

			break
		case '-':
			if i < mb.LastCharIndex() && unicode.IsSpace(mb.RuneAt(i+1)) {
				if removeSpacesAroundDash {
					var left int

					if i > 0 {
						left = i - 1
					} else {
						left = i
					}

					mb.SubstituteStringAt(left, 3, dash)

				} else {
					mb.SubstituteStringAt(i, 1, dash)
				}
			}

			break
		}
	}
}
Exemple #5
0
func (ru *russianLanguage) isShyAllowed3(mb *util.MarkupBuilder, start int, i int, limit int) bool {
	return i+4 < limit &&
		!IsModifier(mb.RuneAt(i+3)) &&
		(IsVowel(mb.RuneAt(i+3)) || IsVowel(mb.RuneAt(i+4)))
}
Exemple #6
0
func (ru *russianLanguage) isShyAllowed2(mb *util.MarkupBuilder, start int, i int, limit int) bool {
	return i+3 < limit &&
		!(IsSibilant(mb.RuneAt(i+1)) && !IsVowel(mb.RuneAt(i+2)) && !IsVowel(mb.RuneAt(i+3))) &&
		!IsModifier(mb.RuneAt(i+2))
}