How to use the pyphen.__init__.AlternativeParser function in pyphen

To help you get started, we’ve selected a few pyphen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kozea / Pyphen / pyphen / __init__.py View on Github external
charset = 'cp1251'
            for pattern in stream:
                pattern = pattern.decode(charset).strip()
                if not pattern or pattern.startswith((
                        '%', '#', 'LEFTHYPHENMIN', 'RIGHTHYPHENMIN',
                        'COMPOUNDLEFTHYPHENMIN', 'COMPOUNDRIGHTHYPHENMIN')):
                    continue

                # replace ^^hh with the real character
                pattern = parse_hex(
                    lambda match: chr(int(match.group(1), 16)), pattern)

                # read nonstandard hyphen alternatives
                if '/' in pattern:
                    pattern, alternative = pattern.split('/', 1)
                    factory = AlternativeParser(pattern, alternative)
                else:
                    factory = int

                tags, values = zip(*[
                    (string, factory(i or '0'))
                    for i, string in parse(pattern)])

                # if only zeros, skip this pattern
                if max(values) == 0:
                    continue

                # chop zeros from beginning and end, and store start offset
                start, end = 0, len(values)
                while not values[start]:
                    start += 1
                while not values[end - 1]:

pyphen

Pure Python module to hyphenate text

(GPL-2.0 OR LGPL-2.0 OR MPL-1…
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis