Link | string_wrap |
Author | Jason Huck |
Category | String |
Version | 8.x |
License | Public Domain |
Posted | 29 Nov 2005 |
Updated | 29 Mar 2007 |
More by this author... |
Wraps a string to the specified length. An optional -trim parameter determines whether or not to trim whitespace from each line. Defaults to a length of 80 characters with trimming on, using unix style line breaks.
string_wrap( $longstring, -length=60, -linebreak='\r\n', -trim=false );
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag( 'wrap', -namespace='string_', -req='text', -copy, -opt='length', -copy, -type='integer', -opt='linebreak', -type='string', -opt='trim', -type='boolean', -priority='replace', -description='Wraps the given string to the specified length.' ); local( 'in' = string(#text), 'out' = string ); !local_defined('length') ? local('length' = 80); #length -= 1; !local_defined('linebreak') ? local('linebreak' = '\n'); !local_defined('trim') ? local('trim' = true); #in->trim; #in->replace('\r\n','\n')&replace('\r','\n'); iterate(#in->split('\n'), local('i')); local('line' = #i); #trim ? #line->trim; if(#line->size < #length); #out += #line + #linebreak; else; local( 'lineIn' = #line, 'lineOut' = string ); while(#lineIn->size > #length); local('offset' = #length); while(#lineIn->size > #offset && #offset > 0 && !#lineIn->isspace(#offset)); #offset -= 1; /while; #offset == 0 ? #offset = #length; local('chunk') = #lineIn->substring(1, #offset); #lineOut += #chunk + #linebreak; #lineIn->removeleading(#chunk); /while; #lineIn->size ? #lineOut += #lineIn + #linebreak; #out += #lineOut; /if; /iterate; return(#out); /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft