1
1
from .defs import *
2
2
3
+ # Count the number of repeated characters of char `match` in sequence `seq`.
4
+ # If no match is given, the first character found is used as the match char.
3
5
def count_seq (seq , match = '' ):
4
6
if not seq :
5
7
return 0
@@ -15,15 +17,22 @@ def count_seq(seq, match=''):
15
17
r += 1
16
18
return r
17
19
20
+ # Peel an unsigned int from the front of the string `s` and return both
21
+ # the integer and its count. If nothing can be processed, return default `d`.
18
22
def peel_uint (s , d = None ):
19
23
a ,b = peel_uint_s (s ,str (d ) if d != None else None )
20
24
return (int (a ) if a != None and a != '' else None ,b )
21
25
26
+ # Peel an integer from the front of the string `s` and return both
27
+ # the integer and its count. If nothing can be processed, return default `d`.
22
28
def peel_int (s , d = None ):
23
29
a ,b = peel_uint_s (s ,str (d ) if d != None else None )
24
30
return (int (a ) if a != None and a != '' else None ,b )
25
31
26
- # don't cast
32
+ # Peel an unsigned int from the front of the string `s` and return both
33
+ # the integer (as a string) and its count. If nothing can be processed, return default `d`.
34
+ # This is the `string` version of this function which returns the peeled integer
35
+ # as a string.
27
36
def peel_uint_s (s , d = None ):
28
37
r = ''
29
38
for ch in s :
@@ -34,6 +43,9 @@ def peel_uint_s(s, d=None):
34
43
if not r : return (d ,0 ) if d != None else ('' ,0 )
35
44
return (r ,len (r ))
36
45
46
+ # Peel a roman numeral from the front of the string `s` and return both
47
+ # the roman numeral (as a string) and its count.
48
+ # If nothing can be processed, return default `d`.
37
49
def peel_roman_s (s , d = None ):
38
50
nums = 'ivx'
39
51
r = ''
@@ -51,6 +63,9 @@ def peel_roman_s(s, d=None):
51
63
if not r : return (d ,0 ) if d != None else ('' ,0 )
52
64
return (r ,len (r ))
53
65
66
+ # Peel an integer from the front of the string `s` and return both
67
+ # the integer (as a string) and its count.
68
+ # If nothing can be processed, return default `d`.
54
69
def peel_int_s (s , d = None ):
55
70
r = ''
56
71
for ch in s :
@@ -64,6 +79,9 @@ def peel_int_s(s, d=None):
64
79
if not r : return (d ,'' ) if d != None else (0 ,'' )
65
80
return (int (r ),len (r ))
66
81
82
+ # Peel a float from the front of the string `s` and return both
83
+ # the float and its count.
84
+ # If nothing can be processed, return default `d`.
67
85
def peel_float (s , d = None ):
68
86
r = ''
69
87
decimals = 0
@@ -84,6 +102,9 @@ def peel_float(s, d=None):
84
102
if not r : return (d ,0 ) if d != None else (0 ,0 )
85
103
return (float (r ),len (r ))
86
104
105
+ # Peel any number of characters matching char `match`.
106
+ # Return the peeled string and its length.
107
+ # If no match, return default `d`.
87
108
def peel_any (s , match , d = '' ):
88
109
r = ''
89
110
ct = 0
@@ -95,7 +116,9 @@ def peel_any(s, match, d=''):
95
116
break
96
117
return (orr (r ,d ),ct )
97
118
98
- def note_value (s ): # turns dot note values (. and *) into frac
119
+ # Turns dot note values (. and *) into a decimal.
120
+ # Returns its floating point value and the number of repeated chars found.
121
+ def note_value (s ):
99
122
if not s :
100
123
return (0.0 , 0 )
101
124
r = 1.0
0 commit comments