Lasso Soft Inc. > Home

[lp_string_wordwrap]

Linklp_string_wordwrap
AuthorBil Corry
CategoryString
Version8.x
LicensePublic Domain
Posted03 Dec 2005
Updated21 Jan 2006
More by this author...

Description

Word-wraps a string at a given line length.

Note: Requires [lp_string_firstwords], [lp_string_linefeedGet] and [lp_string_linefeedSet]

Sample Usage

var:'length' = 5;
'
';
'+' * $length; '\r\n';
(lp_string_wordwrap: 'This is a test. It\'s only a test.', $length, '\r\n');
'\r\n'; '+' * $length; '\r\n';
'
'; Returns: +++++ This is a test. It's only a test. +++++

Source Code

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:'lp_string_wordwrap',
	-description='Word-wraps a string at a given line length.',
	-priority='replace',
	-required='string', -copy,
	-required='linelength',
	-optional='linefeed';
	
	#string = string: #string;
	
	if: !(local_defined:'linefeed');
		local:'linefeed' = (lp_string_linefeedGet: #string);
		if: #linefeed == '';
			#linefeed = '\r\n';
		/if;
	else;
		#linefeed = string: #linefeed;
	/if;

	if: params->(find:'-striplf')->size > 0;
		// strip out the linefeeds
		#string = (lp_string_linefeedSet: #string, ' ');
	/if;

	
	if: #linefeed == 'array';
		local:'return' = array;
		local:'temp' = string;
		local:'notrunaway' = 1000;
		while: #string->size && #notrunaway;
			#notrunaway -= 1;
			#temp = (lp_string_firstwords: #string, (integer:#linelength));
			#string->(removeleading: #temp);
			#temp->trim;
			if: #temp->size;
				#return->(insert: #temp);
			/if;
		/while;
	else;
		local:'return' = string;
		local:'temp' = string;
		local:'notrunaway' = 100000;
		while: #string->size && #notrunaway;
			#notrunaway -= 1;
			#temp = (lp_string_firstwords: #string, (integer:#linelength));
			#string->(removeleading: #temp);
			#temp->trim;
			if: #temp->size;
				#return += #temp #linefeed;
			/if;
		/while;
		#return->trim;
	/if;
	
	return: #return;

/define_tag;

]

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft