src/pyams_utils/text.py
changeset 445 98b00191ce4f
parent 419 05ff71a02b2d
child 451 c54f05d00f63
equal deleted inserted replaced
444:72ceed22e639 445:98b00191ce4f
    51     'This is a…'
    51     'This is a…'
    52     >>> get_text_start('This is a long string', 20)
    52     >>> get_text_start('This is a long string', 20)
    53     'This is a long…'
    53     'This is a long…'
    54     >>> get_text_start('This is a long string', 20, 7)
    54     >>> get_text_start('This is a long string', 20, 7)
    55     'This is a long string'
    55     'This is a long string'
       
    56     >>> get_text_start('This is a long string', -1)
       
    57     'This is a long string'
    56     """
    58     """
    57     result = text or ''
    59     result = text or ''
    58     if length > len(result):
    60     if (length < 0) or (length > len(result)):
    59         return result
    61         return result
    60     index = length - 1
    62     index = length - 1
    61     text_length = len(result)
    63     text_length = len(result)
    62     while (index > 0) and (result[index] != ' '):
    64     while (index > 0) and (result[index] != ' '):
    63         index -= 1
    65         index -= 1