Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

icio_linewrap ( Text; Size; Originalsize)

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.5  (27 votes)
  Discuss this Custom Function

Chris Jones, Inter-CIO Limited
http://www.inter-cio.com

A recursive line formatter/breaker and word wrapper that implements Knuth's algorithm

Sample Input:
icio_linewrap ("01234¶56789";3;3)
Sample Output:
012
34
567
89


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

function icio_linewrap (Text, Size, Originalsize)

This function breaks lines of text passed to it in param Text
and intelligently does so to the character count passed in param Size.
Param Originalsize is utilterian and only used to pass on whatever value is given to it. It is not intrinsically used in this function.
The function implements Knuth's algorithm.
The function calls several other functions (icio_striptrailingspaces, icio_stripleadingspaces
and icio_finddelimiter).
icio_striptrailingspaces is used to strip out any spaces that occur contiguously before a CR at the end
of a string. It is provided below.
icio_stripleadingspaces is used to strip out any spaces that occur contiguously before a passed Character at the beginning
of a string. It is also provided below.
icio_finddelimiter is used to find a delimiter that does not appear in the string passed to it. The function
is also provoded below.
All of the above fuctions MUST be installed for this function to operate correctly.

The icio_linewrap function will preserve existing line breaks, break correctly at word boundaries, and split text strings
passed to it that are longer than the Size specified. It recurses to fully process the entire Text passed to it.

I have not yet managed to return a ? from this function after exhausting testing!

Param Text - the text string to be processed
Param Size - the maximum length of each line in characters
Param Originalsize - utiliterian to allow a value to be passed on during recursion (not specifically used in this function). Defaults to the value of Size if passed as ""
---------------------------------------------------------------
The function icio_striptrailingspaces is documented here if required:
---------------------------------------------------------------
//function icio_striptrailingspaces (Text; LastChar)

//This function reverse scans a passed string (param Text) and replaces " " & LastChar with LastChar at the end of Text
//LastChar can be "" to strip off any trailing spaces
//Param Text - the string to scan
//Param LastChar - the Last character to use (if any)
//if passed as "", "⅋" or a non-appearing character will be used
//Requires custom function icio_finddelimiter(Text;Delimiter);

Let
(
[
//Store the length of the passed Text
LengthText = Length(Text);

//Find a usable delimiter
Delimiter = icio_finddelimiter(Text;"");

//Store a copy of the original text
OriginalText = Text;

//Deal with Delimiter being a " " - use the delimiter to replace all refs to LastChar being a space
Text = Case (
LastChar=" " and Right(Text;1) = " "; Left(Text;LengthText-1) & Delimiter;
Text
);
LastChar = Case (
LastChar=" "; Delimiter;
LastChar
);
//End dealing with Delimiter being a " "

//Check whether anything to process
End = If(LengthText = 0 or (LastChar ≠ "" and LastChar ≠ Right(Text;1));
1;
0
);

//Strip last char off Text if LastChar is something
Text = If(LastChar ≠ "" and End =0;
Left(Text;LengthText-1);
Text
);

//Store the passed Text with all spaces removed
nospaces=If(End = 0;
Substitute(Text; " "; "");
Text
);

//Strip all the trailing spaces off Text if any are found
Text = If(IsEmpty(nospaces) or End = 1;
"";
Left(Text; Position(Text; Right(nospaces; 1); Length(Text);-1 ) )
);

//Add the Delimiter to the end of Text if there is a delimiter
Text = If(End = 0 and LastChar ≠ "";
Text & LastChar;
Text
);

//Re-store the length of Text
LengthText = Length(Text);

//Replace the delimiter at the end of Text with a space if there is a trailing delimiter
Text = Case (
LastChar = Delimiter and End =0; Left(Text;LengthText-1) & " ";
Text
);

//Return the Original Text if it was not processed - otherwise return the processed text
Text = Case(
End = 1; OriginalText;
Text
)
];
Text
)
---------------------------------------------------------------
The function icio_stripleadingspaces is documented here if required:
---------------------------------------------------------------
//function icio_stripleadingspaces (Text; LastChar)

//This functions scans a passed string (param Text) and recursively removes all contiguous " " up to LastChar
//LastChar can be "" to strip off any contiguous leading spaces up to the first non-space character
//Param Text - the string to scan
//Param LastChar - the Last character to use or ""


Let
(
[
//Store the length of Text
LengthText = Length(Text);

//Set a flag if we have nothing to process
End = If(LengthText = 0 or (LengthText=1 and LastChar = Left(Text;1));
1;
0
);

//LastChar is either "", " " or another char

//Store Text with all spaces removed
Substance = If(End = 0;
Substitute(Text; " "; "");
""
);

//Store the length of the stripped Text
LengthSubstance = Length(Substance);

//Grab the first character in the stripped Text, if there is one - otherwise return null string
FirstInSubstance = If(End=0;
If(LengthSubstance>0;
Left(Substance;1);
""
);
""
);

//Process Text and return it
Text = If(End = 1;
"";
Case (
LastChar = "" and LengthSubstance = 0; "";
LastChar = "" and LengthSubstance > 0; Right(Text;LengthText-Position(Text;FirstInSubstance;1;1)+1);
LastChar = " " and LengthSubstance = 0 and LengthText > 0; Right(Text;1);
LastChar = " " and LengthSubstance > 0 and LengthText > 0; Right(Text;LengthText-Position(Text;FirstInSubstance;1;1)+2);
LengthSubstance = 0 and LengthText > 0; Text;
LengthSubstance > 0 and LengthText > 0; Right(Text;LengthText-Position(Text;FirstInSubstance;1;1)+1);
Text
)
)
];
Text
)
---------------------------------------------------------------
The function icio_finddelimiter is documented here if required:
---------------------------------------------------------------
//icio_finddelimiter (Text;Delimiter)

//Finds a 3 character delimiter that does not appear in Text
//Uses standard ASCII characters
//If Delimiter is passed as "", starts by testing "|^-"
//Param Text = the string to be examined
//Param Delimiter = the 3 character string to be tested
//Exits with a unique 3 character Delimiter that does not appear in Text

Let(
[
//Set Flag
End = 0;

//Store the Length of Text
LengthText = Length(Text);

//Set Delimiter to |^- if none was provided
Delimiter = If(Delimiter = "";
"|^-";
Delimiter
);

//Set Flag if nothing to process
End = If(PatternCount(Text;Delimiter) = 0 or LengthText = 0;
1;
0
);

//Set Delimiter to a special character string that does not appear in Text
Delimiter = If(End = 1;
Delimiter;
Case (
Delimiter = "|^-"; "^-|";
Delimiter = "^-|"; "-|^";
Delimiter = "-|^"; "|-^";
Delimiter = "|-^"; "-^|";
Delimiter = "-^|"; "^|-";
Delimiter
)
)
];

//Recurse until we have a valid Delimiter and return it
If(End = 1;
Delimiter;
icio_finddelimiter(Text;Delimiter)
)
)
---------------------------------------------------------------

Chris Jones
ICIO Limited, United Kingdom
chris.jones@inter-cio.com

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

Your cf breaks at icio_findpos

Lee Smith, Woodland
June 21, 2012 8:00am

@Lee Smith

You need to ensure you have the function icio_findpos installed as per the documentation!

Chris Jones, Oxford, UK
June 21, 2012 8:45am

Revised to allow for special delimiters to deal with Space characters

Chris Jones, Oxford, UK
July 03, 2012 4:18am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 8 + 2 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions