Skip to content

Commit

Permalink
feat: add _get_delimiter_locations function
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed May 20, 2024
1 parent bb744f9 commit 75b67ab
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/md_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from itertools import repeat
from typing import Callable, Iterable, Iterator, TypeVar
from typing import Callable, Iterable, Iterator, Sequence, TypeVar

T = TypeVar("T")
S = TypeVar("S")
Expand Down Expand Up @@ -59,6 +59,28 @@ def _get_column_widths(
return output[:-1]


def _get_delimiter_locations(rows: Sequence[str], delimiter: str = "|") -> Iterator[int]:
remaining_rows = len(rows)
location_number = [0 for _ in range(remaining_rows)]
column = 1
for pos in range(len(max(rows, key=len))):
for index, row in enumerate(rows):
if pos == len(row):
remaining_rows -= 1
continue
if pos > len(row):
continue
if row[pos] == delimiter:
location_number[index] += 1
if all(num >= column for num in location_number):
column += 1
yield pos


def _get_max_column_widths():
raise NotImplementedError()


def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|") -> str:
"""
Pad each column (determined by `delimiter`), to a given width.
Expand Down

0 comments on commit 75b67ab

Please sign in to comment.