class TextTools
package texter.general
TextTools
is a class containing static methods for manipulating text.
you can use it by doing
using texter.general.TextTools;
and enjoy not having to write more text manipulation functions ever again :D
Static variables
staticread onlyloremIpsumText:String = "\n\t\tLorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque finibus condimentum magna, eget porttitor libero aliquam non. Praesent commodo, augue nec hendrerit tincidunt, urna felis lobortis mi, non cursus libero tellus quis tellus. Vivamus ornare convallis tristique. Integer nec ornare libero. Phasellus feugiat facilisis faucibus. Vivamus porta id neque id placerat. Proin convallis vel felis et pharetra. Quisque magna justo, ullamcorper quis scelerisque eu, tincidunt vitae lectus. Nunc sed turpis justo. Aliquam porttitor, purus sit amet faucibus bibendum, ligula elit molestie purus, eu volutpat turpis sapien ac tellus. Fusce mauris arcu, volutpat ut aliquam ut, ultrices id ante. Morbi quis consectetur turpis. Integer semper lacinia urna id laoreet.\n\n\t\tUt mollis eget eros eu tempor. Phasellus nulla velit, sollicitudin eget massa a, tristique rutrum turpis. Vestibulum in dolor at elit pellentesque finibus. Nulla pharetra felis a varius molestie. Nam magna lectus, eleifend ac sagittis id, ornare id nibh. Praesent congue est non iaculis consectetur. Nullam dictum augue sit amet dignissim fringilla. Aenean semper justo velit. Sed nec lectus facilisis, sodales diam eget, imperdiet nunc. Quisque elementum nulla non orci interdum pharetra id quis arcu. Phasellus eu nunc lectus. Nam tellus tortor, pellentesque eget faucibus eu, laoreet quis odio. Pellentesque posuere in enim a blandit.\n\n\t\tDuis dignissim neque et ex iaculis, ac consequat diam gravida. In mi ex, blandit eget velit non, euismod feugiat arcu. Nulla nec fermentum neque, eget elementum mauris. Vivamus urna ligula, faucibus at facilisis sed, commodo sit amet urna. Sed porttitor feugiat purus ac tincidunt. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam sollicitudin lacinia turpis quis placerat. Donec eget velit nibh. Duis vehicula orci lectus, eget rutrum arcu tincidunt et. Vestibulum ut pharetra lectus. Quisque lacinia nunc rhoncus neque venenatis consequat. Nulla rutrum ultricies sapien, sed semper lectus accumsan nec. Phasellus commodo faucibus lacinia. Donec auctor condimentum ligula. Sed quis viverra mauris.\n\n\t\tQuisque maximus justo dui, eget pretium lorem accumsan ac. Praesent eleifend faucibus orci et varius. Ut et molestie turpis, eu porta neque. Quisque vehicula, libero in tincidunt facilisis, purus eros pulvinar leo, sit amet eleifend justo ligula tempor lectus. Donec ac tortor sed ipsum tincidunt pulvinar id nec eros. In luctus purus cursus est dictum, ac sollicitudin turpis maximus. Maecenas a nisl velit. Nulla gravida lectus vel ultricies gravida. Proin vel bibendum magna. Donec aliquam ultricies quam, quis tempor nunc pharetra ut.\n\n\t\tPellentesque sit amet dui est. Aliquam erat volutpat. Integer vitae ullamcorper est, ut eleifend augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Quisque congue velit felis, vitae elementum nulla faucibus id. Donec lectus nibh, commodo eget nunc id, feugiat sagittis massa. In hac habitasse platea dictumst. Pellentesque volutpat molestie ultrices.\n\t"
Static methods
staticfilter(text:String, filter:Dynamic):String
filters a string according to the contents of filter
:
-
if
filter
is a string, it can be use as one of 2 things- if the string contains a regex filter it will re-call the function with the string passed as an EReg
-
if the string does not contain the filter it can be one of 3 3 things:
- if the string is empty, nothing will be filtered
- if the string is "alpha", it will filter out all non-alphabetic characters
- if the string is "numeric", it will filter out all non-numeric characters
- if the string is "alphanumeric", it will filter out all non-alphanumeric characters
-
if
filter
is an EReg, it will be used to filter the string
Parameters:
text | the text to filter |
---|---|
filter | the actual filter; can be a string or an EReg |
Returns:
the filtered string
staticindexesFromArray(string:String, subs:Array<String>):Array<{startIndex:Int, endIndex:Int}>
repoort all occurences of the elements inside sub
in string
Parameters:
string | the string to search in |
---|---|
subs | an array of substrings to search for |
Returns:
an array of all positions of the substrings, from startIndex, up to but not including endIndex
staticindexesFromEReg(string:String, ereg:EReg):Array<{startIndex:Int, endIndex:Int}>
reports all occurences of the findings of ereg
in string
.
NOTICE: avoid using eregs with the global flag, as they will only report the first substring found.
Parameters:
string | the string to search in |
---|---|
ereg | the EReg to use as the searching engine |
Returns:
an array of all positions of the substrings, from startIndex, up to but not including endIndex
staticindexesOf(string:String, sub:String):Array<{startIndex:Int, endIndex:Int}>
Returns an array containing the start & end indexes of all occurences of sub
.
the reported indxes are from startIndex
, up to but not including endIndex
.
Parameters:
string | The string containing the |
---|---|
sub | The |
Returns:
An Array f all indexes
staticinlineloremIpsum(paragraphs:Int = 1, ?length:Int):String
Creates a lorem ipsum text the following modifiers.
Parameters:
linesPerParagraph | the amount of lines per paragraph |
---|---|
paragraphs | the amount of paragraphs |
length | Optional - the total length of the text. |
staticmultiply(string:String, times:Int):String
Multiplies string
by times
.
When multiplied by a number equal/less than 0, it returns an empty string.
example:
var foo = "foo";
var bar = TextTools.multiply(foo, 3);
trace(bar); // foofoofoo
bar = foo.multiply(0);
trace(bar); // ""
Parameters:
string | the string to multiply |
---|---|
by | the number of times to multiply |
Returns:
the multiplied string
staticreplaceLast(string:String, replace:String, by:String):String
replaces the last occurrence of replace
in string
with by
Parameters:
string | the string to replace in |
---|---|
replace | the string to replace |
by | the replacement string |
Returns:
the string with the last occurrence of replace
replaced by by
staticreplacefirst(string:String, replace:String, by:String):String
replaces the first occurrence of replace
in string
with by
Parameters:
string | the string to replace in |
---|---|
replace | the string to replace |
by | the replacement string |
Returns:
the string with the first occurrence of replace
replaced by by
staticinlinesplitOnParagraph(text:String):Array<String>
Splits a text into paragraphs, determined by HTML/Markdown markup (double newline or
)Parameters:
text | the text to split |
---|
Returns:
an array containing the paragraphs