#NEWLINE# def crop( text , width = _DEFAULT_WIDTH , suffix = '[...]' ) : #NEWLINE# #INDENT# '\n    Crop text to a certain width, throwing away text from too-long\n    lines.\n\n    Args:\n        text (str): Text to crop.\n        width (int, optional): Width of line to crop, in characters.\n        suffix (str, optional): This is appended to the end of cropped\n            lines to show that the line actually continues. Cropping\n            will be done so that the suffix will also fit within the\n            given width. If width is too small to fit both crop and\n            suffix, the suffix will be dropped.\n\n    Returns:\n        text (str): The cropped text.\n\n    ' #NEWLINE# utext = to_unicode ( text ) #NEWLINE# ltext = len ( utext ) #NEWLINE# if ( ltext <= width ) : #NEWLINE# #INDENT# return text #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lsuffix = len ( suffix ) #NEWLINE# utext = ( text [ : width ] if ( lsuffix >= width ) else ( '%s%s' % ( utext [ : ( width - lsuffix ) ] , suffix ) ) ) #NEWLINE# return to_str ( utext )