Skip to content

Commit

Permalink
Use reversed approach for splitting references
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Oct 29, 2023
1 parent 78d3d0c commit dd6f505
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions kikit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ def splitOn(input: str, predicate: Callable[[str], bool]) \
break
return left, input[i:]

def splitOnReverse(input: str, predicate: Callable[[str], bool]) \
-> Tuple[str, str]:
"""
Split a string into a tail fullfilling predicate and the remaning head
"""
tail, head = splitOn(input[::-1], predicate)
return head[::-1], tail[::-1]

def indexOf(list, predicate):
"""
Return the index of the first element that satisfies predicate. If no
Expand Down
2 changes: 1 addition & 1 deletion kikit/fab/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,5 @@ def expandNameTemplate(template: str, filetype: str, board: pcbnew.BOARD) -> str
raise RuntimeError(f"Unknown variable {e} in --nametemplate: {template}")

def naturalComponentKey(reference: str) -> Tuple[str, int]:
text, num = splitOn(reference, lambda x: not x.isdigit())
text, num = splitOnReverse(reference, lambda x: x.isdigit())
return str(text), int(num)

0 comments on commit dd6f505

Please sign in to comment.