Skip to content

Commit d17b5fd

Browse files
committed
v1.0.6
1 parent 87dc39d commit d17b5fd

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ pip install tssplit
1414
### Syntax
1515

1616
```Python3
17-
def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim=''):
17+
def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim='', remark='#'):
1818
"""Split a string by delimiters with quotes and escaped characters, optionally trimming results
19+
1920
:param s: A string to split into chunks
2021
:param quote: Quote chars to protect a part of s from parsing
2122
:param quote_keep: Preserve quote characters in the output or not
2223
:param delimiter: A chunk separator character
2324
:param escape: An escape character
2425
:param trim: Trim characters from chunks
26+
:param remark: Ignore all characters after remark sign
2527
:return: A list of chunks
2628
"""
2729
```
@@ -31,12 +33,17 @@ def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim
3133
```Python3
3234
from tssplit import tssplit
3335

34-
tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--', quote='"\'', delimiter=':;,', escape='/^', trim='')
36+
tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
37+
quote='"\'', delimiter=':;,', escape='/^', trim='')
3538
['--', '--', '--', '----/------:----"----']
3639

37-
tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--', quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True)
40+
tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
41+
quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True)
3842
['--', '--', '--', '--"--/--"--\'--:--\'--"----']
3943

44+
tssplit('--:--;--,--"--/--"--\'--:--\'--# Ignore this',
45+
quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True, remark='#')
46+
['--', '--', '--', '--"--/--"--\'--:--\'--']
4047
```
4148

4249
## Changelog
@@ -47,3 +54,4 @@ tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--', quote='"\'', delimiter=':;,',
4754
* 2020.03.29 v1.0.3 Trim option to strip() characters from chunks
4855
* 2020.03.29 v1.0.4 Multiple characters for quotes, delimiters and escapes
4956
* 2022.02.04 v1.0.5 Added `quote_keep` option to preserve quote marks in the output or not
57+
* 2023.01.12 v1.0.6 Remark characters interrupt string parsing

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='tssplit',
8-
version='1.0.5',
8+
version='1.0.6',
99
py_modules=['tssplit.tssplit'],
1010
url='https://github.com/mezantrop/tssplit',
1111
license='bsd-2-clause',

tssplit/tssplit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim=''):
1+
def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim='', remark='#'):
22
"""Split a string by delimiters with quotes and escaped characters, optionally trimming results
33
44
:param s: A string to split into chunks
@@ -7,6 +7,7 @@ def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim
77
:param delimiter: A chunk separator character
88
:param escape: An escape character
99
:param trim: Trim characters from chunks
10+
:param remark: Ignore all characters after remark sign
1011
:return: A list of chunks
1112
"""
1213

@@ -31,6 +32,8 @@ def tssplit(s, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim
3132
token = token.strip(trim)
3233
result.append(token)
3334
token = ''
35+
elif c in remark:
36+
break
3437
else:
3538
token += c
3639

0 commit comments

Comments
 (0)