16 from __future__
import division
18 from operator
import add, sub
20 from .platform
import PY2
21 from .robottypes
import is_integer
22 from .unic
import unic
34 def roundup(number, ndigits=0, return_type=None):
37 return_type = float
if ndigits > 0
else int
38 return return_type(result)
51 precision = 10 ** (-1 * ndigits)
52 if number % (0.5 * precision) == 0
and number % precision != 0:
53 operator = add
if number > 0
else sub
54 number = operator(number, 0.1 * precision)
55 return round(number, ndigits)
77 if code_style
and '_' in string:
78 string = string.replace(
'_',
' ')
79 parts = string.split()
80 if code_style
and len(parts) == 1 \
81 and not (string.isalpha()
and string.islower()):
83 return ' '.join(part[0].upper() + part[1:]
for part
in parts)
89 for prev, char, next
in zip(
' ' + string, string, string[1:] +
' '):
92 tokens.append(
''.join(token))
97 tokens.append(
''.join(token))
103 return not char.isdigit()
105 return next.islower()
or prev.isalpha()
and not prev.isupper()
106 return char.isdigit()
110 count = item
if is_integer(item)
else len(item)
111 return '' if count == 1
else 's'
115 def seq2str(sequence, quote="'", sep=', ', lastsep=' and '):
116 sequence = [quote +
unic(item) + quote
for item
in sequence]
119 if len(sequence) == 1:
121 last_two = lastsep.join(sequence[-2:])
122 return sep.join(sequence[:-2] + [last_two])
129 return '[ %s ]' %
' | '.join(
unic(item)
for item
in sequence)
def printable_name(string, code_style=False)
Generates and returns printable name from the given string.
def _is_camel_case_boundary(prev, char, next)
def seq2str2(sequence)
Returns sequence in format [ item 1 | item 2 | ...
def roundup(number, ndigits=0, return_type=None)
Rounds number to the given number of digits.
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
def _split_camel_case(string)