class TextBuilder {
public static function ShowText(mc:MovieClip, direction:Boolean, wdt:Number, s:String,myColor:String, myFont:String, mySize:Number, myEmbed:Boolean, speed:Number, method:Function, alphaTrans:Boolean, myExtra:Object, callBack:Function, validity:MovieClip, param:Array){
if(!mc.TextBuilderEnterClip) mc.clipEnter=mc.createEmptyMovieClip("TextBuilderEnterClip",mc.getNextHighestDepth());
mc.myText=mc.createTextField("dynText", 1, 0, 0, wdt, 1);
wdt ? (mc.myText.multiline = true, mc.myText.wordWrap = true) : (mc.myText.multiline = false,mc.myText.wordWrap = false);
mc.myAlign = myExtra.myAlign ? myExtra.myAlign : "left";
mc.myLeading = myExtra.myLeading ? myExtra.myLeading : 0;
myExtra.myBackground ? ( mc.myText.background = true, mc.myText.backgroundColor = myExtra.myBackground ) : mc.myText.background = false;
myExtra.mySelectable ? mc.myText.selectable = true : mc.myText.selectable = false;
myExtra.myBorder ? mc.myText.border = true : mc.myText.border = false;
mc.myText.html = true;
mc.myText.antiAliasType="advanced"
mc.myText.embedFonts = myEmbed;
mc.myText.autoSize = "left";
mc.clipEnter.t=0;
mc.clipEnter.d=speed;
mc.clipEnter.s=0;
mc.clipEnter.e=s.length;
mc.clipEnter.st=s;
mc.clipEnter.myDirection=direction;
mc.clipEnter.transAlpha=alphaTrans;
mc.clipEnter.sa=mc._alpha;
mc.clipEnter.ea=100;
mc.firstHalfString="<TEXTFORMAT LEADING=""+mc.myLeading+""><P ALIGN=""+mc.myAlign+""><FONT FACE=""+myFont+"" SIZE=""+mySize+"" COLOR=""+myColor+"">"
mc.secondHalfString="</FONT></P></TEXTFORMAT>";
mc.clipEnter.onEnterFrame=function(){
if (this.t++<this.d){
if(this.transAlpha)mc._alpha=Math.round(method(this.t,this.sa,this.ea,this.d));
if(this.myDirection){
mc.myText.htmlText=mc.firstHalfString+this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
this.tempString=this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)));
} else {
mc.myText.htmlText=mc.firstHalfString+this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
this.tempString=this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)));
}
} else {
this.onEnterFrame=undefined;
callBack.apply(validity,param);
}
}
}
public static function HideText(mc:MovieClip, direction:Boolean, speed:Number, method:Function, alphaTrans:Boolean, callBack:Function, validity:MovieClip, param:Array){
mc.clipEnter.t=0;
mc.clipEnter.d=speed;
mc.clipEnter.s=mc.clipEnter.tempString.length;
mc.clipEnter.e=-mc.clipEnter.tempString.length;
mc.clipEnter.myDirection=direction;
mc.clipEnter.transAlpha=alphaTrans;
mc.clipEnter.sa=mc._alpha;
mc.clipEnter.ea=-mc._alpha;
mc.clipEnter.onEnterFrame=function(){
if (this.t++<this.d){
if(this.transAlpha)mc._alpha=Math.round(method(this.t,this.sa,this.ea,this.d));
if(this.myDirection){
mc.myText.htmlText=mc.firstHalfString+this.tempString.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
this.tempString=this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)));
} else {
mc.myText.htmlText=mc.firstHalfString+this.tempString.substr(0,Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
this.tempString=this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)));
}
} else {
this.onEnterFrame=undefined;
callBack.apply(validity, param);
}
}
}
public static function MadeText(mc:MovieClip, wdt:Number, s:String, myColor:String, myFont:String, mySize:Number, myEmbed:Boolean , myExtra:Object){
mc.myAlign = myExtra.myAlign ? myExtra.myAlign : "left";
mc.myLeading = myExtra.tLeading ? myExtra.myLeading : 0;
mc.myText=mc.createTextField("dynText", 1, 0, 0, wdt, 1);
wdt ? (mc.myText.multiline = true, mc.myText.wordWrap = true) : (mc.myText.multiline = false,mc.myText.wordWrap = false);
myExtra.myBackground ? ( mc.myText.background = true, mc.myText.backgroundColor = myExtra.myBackground ) : mc.myText.background = false;
myExtra.mySelectable ? mc.myText.selectable = true : mc.myText.selectable = false;
myExtra.myBorder ? mc.myText.border = true : mc.myText.border = false;
mc.myText.html = true;
mc.myText.antiAliasType="advanced";
mc.myText.embedFonts = myEmbed;
mc.myText.autoSize = "left";
mc.firstHalfString="<TEXTFORMAT LEADING=""+mc.myLeading+""><P ALIGN=""+mc.myAlign+""><FONT FACE=""+myFont+"" SIZE=""+mySize+"" COLOR=""+myColor+"">"
mc.secondHalfString="</FONT></P></TEXTFORMAT>";
mc.myText.htmlText=mc.firstHalfString+s+mc.secondHalfString;
}
}
Tag Archive for text
TextBuilder
html2text
function html2text($html)
{
$tags = array (
0 => '~<h[123][^>]+>~si',
1 => '~<h[456][^>]+>~si',
2 => '~<table[^>]+>~si',
3 => '~<tr[^>]+>~si',
4 => '~<li[^>]+>~si',
5 => '~<br[^>]+>~si',
6 => '~<p[^>]+>~si',
7 => '~<div[^>]+>~si',
);
$html = preg_replace($tags,"
",$html);
$html = preg_replace('~</t(d|h)>s*<t(d|h)[^>]+>~si',' - ',$html);
$html = preg_replace('~<[^>]+>~s','',$html);
// reducing spaces
$html = preg_replace('~ +~s',' ',$html);
$html = preg_replace('~^s+~m','',$html);
$html = preg_replace('~s+$~m','',$html);
// reducing newlines
$html = preg_replace('~
+~s',"
",$html);
return $html;
}
Deleting Blank Lines Using AWK
cat /tmp/test | awk 'NF > 0' > /tmp/test1
MySQL Mass Text/String Replace
UPDATE table_name SET column = REPLACE(column, 'old_text', 'new_text');
Toggles instructional and default copy text and styles
/**
* Add instructional copy support for text fields and text area.
* The method will clear the copy, and swap styles.
*
* @param textField the text element that will be enhanced.
* @param copyClass class used for instructional copy
* @param noCopyClass class used for plain text
*/
function sl_addClearCopyListeners (textField, copyClass, noCopyClass){
// set default value in the object itself
textField.originalCopy = textField.value;
textField.copyClass = copyClass;
textField.noCopyClass = noCopyClass;
// add listiners
textField.onfocus = function(){
if (this.value == this.originalCopy){
this.value = '';
sl_replaceClass(this, this.copyClass, this.noCopyClass);
return false;
}
return true;
};
textField.onblur = function(){
if (this.value == ''){
sl_replaceClass(this, this.noCopyClass, this.copyClass);
this.value = this.originalCopy;
return false;
}
return true;
};
};
/**
* Replace a class with another, leaving other classes untouched.
* If the class does not exist, nothing will happen.
*
* @param domElement the text element that will be enhanced.
* @param oldClass class to replace
* @param newClass the replacement class
*/
function sl_replaceClass(domElement, oldClass, newClass){
var elementClass = '' + domElement.className;
// save some work, avoid flashing
if (elementClass.indexOf(oldClass) > -1){
elementClass = elementClass.replace(oldClass , newClass);
domElement.className = elementClass;
}
}
Category: Uncategorized |
Tags: area, copy, field, input, instructional, javascript, text, textarea, TextField
Format strings like PRINT USING
require 'strscan'
class String
# Returns the string formatted according to a pattern.
#
# The pattern consists of placeholders and literals. The string is placed in
# the placeholders, leaving the literals as they are. The result may be
# truncated or padded if there are more placeholders than strings.
#
# Placeholders are '#' or '&'. Each '#' is replaced by one character from
# the string, or the filler character if the string has no characters left.
# The '&' is replaced by any remaining characters, or left out of the result
# if there are no remaining characters. There can only be one '&' in the
# pattern. If there is no '&' and more characters than placeholders, the
# remaining characters are discarded.
#
# '#' or '&' may be replaced by other characters if they are needed as
# literals.
#
# Examples:
# "123456789".using('###-##-####')
# => "123-45-6789"
# "12345".using('###-##-####')
# => "123-45"
# "12345".using('###-##-####', nil)
# => "12345"
# "12345".using('###-##-####', ' ')
# => "123-45- "
# "873555121276668".using ('(###) ###-#### ext &', '', true)
# => "(873) 555-1212 ext 76668"
# "8735551212".using ('(###) ###-#### ext &', '', true)
# => "(873) 555-1212"
# "5551212".using ('(###) ###-#### ext &', '', true)
# => "555-1212"
# "KB5774X".using ('##-&-#')
# => "KB-5774-X"
#
# Parameters:
# pattern -- The format string, see above.
# fill -- A string for padding. If the empty string, then the pattern is
# filled as much as possible, and the rest of the pattern is
# truncated. If nil, and the pattern cannot be filled exactly,
# the string is returned unchanged. If some other string, the
# pattern is filled as much as possible and the remainder is
# padded with the string. Defaults to the empty string.
# right -- If true, the pattern is filled from right-to-left instead of
# from left-to-right, and truncated on the left instead of the
# right if needed. Default is false.
# fixchar -- The single-character placeholder. Default is '#'.
# remchar -- The remaining-character placeholder. Default is '&'.
#
def using(pattern, fill='', right=false, fixchar='#', remchar='&')
remCount = pattern.count(remchar)
raise ArgumentError.new("Too many #{remchar}") if remCount > 1
raise ArgumentError.new("#{fixchar} too long") if fixchar.length > 1
raise ArgumentError.new("#{remchar} too long") if remchar.length > 1
raise ArgumentError.new("#{fill} too long") if fill.length > 1
remaining = remCount != 0
slots = pattern.count(fixchar)
# Return the string if it doesn't fit and we shouldn't even try,
if fill.nil?
return self if self.length < slots
return self if self.length > slots and !remaining
end
# Pad and clone the string if necessary.
source = if fill.nil? || fill.empty? then
self
elsif right then
self.rjust(slots, fill)
else
self.ljust(slots, fill)
end
# Truncate the string if necessary.
if source.length > slots && !remaining then
source = right ? source[-source.length, source.length] :
source[0, source.length]
end
# Truncate pattern if needed.
if !fill.nil? && fill.empty? then
if source.length < slots # implies '&' can be ignored
keepCount = source.length # Number of placeholders we are keeping
leftmost, rightmost = 0, pattern.length - 1
if right then
# Look right-to-left until we find the last '#' to keep.
# Loop starts at 1 because 0th placeholder is in the inject param.
leftmost = (1...keepCount).inject(pattern.rindex(fixchar)) {
|leftmost, n| pattern.rindex(fixchar, leftmost - 1) }
else
# Look left-to-right until we find the last '#' to keep.
rightmost = (1...keepCount).inject(pattern.index(fixchar)) {
|rightmost, n| pattern.index(fixchar, rightmost + 1) }
end
pattern = pattern[leftmost..rightmost]
slots = pattern.count(fixchar)
end
# Trim empty '&' up to nearest placeholder. If a '&' at the end goes
# empty, the literals between it and the nearest '#' are probably also
# unnecessary.
if source.length == slots then
if pattern.match("^#{Regexp.escape(remchar)}") then
pattern = pattern[pattern.index(fixchar) || 0 ... pattern.length]
elsif pattern.match("#{Regexp.escape(remchar)}$") then
pattern = pattern[0 ... (pattern.rindex(fixchar) + fixchar.length) || pattern.length]
end
end
end
# Figure out how long the remainder will be when we get to it.
remSize = source.length - slots
if remSize < 0 then remSize = 0; end
# Make the result.
scanner = ::StringScanner.new(pattern)
sourceIndex = 0
result = ''
fixRegexp = Regexp.new(Regexp.escape(fixchar))
remRegexp = Regexp.new(Regexp.escape(remchar))
while not scanner.eos?
if scanner.scan(fixRegexp) then
result += source[sourceIndex].chr
sourceIndex += 1
elsif scanner.scan(remRegexp) then
result += source[sourceIndex, remSize]
sourceIndex += remSize
else
result += scanner.getch
end
end
result
end
end
tabs text
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<style type="text/css">
#tabContainer {width:600px;height:300px;position:relative;border:2px solid gray;}
.pane h2 {float:left;border:2px solid blue;margin:0;padding:0;font-size:20px;cursor:pointer;}
.contents {position:absolute;top:25px;left:0;display:none;}
#tabContainer.about #about .contents,
#tabContainer.contact #contact .contents,
#tabContainer.help #help .contents,
#tabContainer.practice #practice .contents
{display:block;}
#tabContainer.about #about h2,
#tabContainer.contact #contact h2,
#tabContainer.help #help h2,
#tabContainer.practice #practice h2
{border:1px solid red;border-width:2px 2px 0;}
</style>
<script type="text/javascript">
function setactive()
{
var el = this;
var className = el.parentNode.id;
el.parentNode.parentNode.className = className;
}
window.onload = function()
{
var titles = document.getElementsByTagName('h2');
for(var i=0;i<titles.length;i++)
{
titles[i].onclick = setactive;
}
}
</script>
</head>
<body>
<div id="tabContainer">
<div id="about" class="pane">
<h2>Pre Season</h2>
<div class="contents">This is pane 1</div>
</div>
<div id="contact" class="pane">
<h2>Regular Season</h2>
<div class="contents">This is pane 2</div>
</div>
<div id="help" class="pane">
<h2>Post Season</h2>
<div class="contents">This is pane 3</div>
</div>
<div id="practice" class="pane">
<h2>Practice</h2>
<div class="contents">This is pane 4</div>
</div>
</div>
</body>
</html>
Search and replace text in a string
var newText:String = "The rain in Spain falls mainly on the plain";
var splitText:Array = newText.split("Spain");
newText = splitText.join("Barcelona");
// outputs "The rain in Barcelona falls mainly on the plain"
search and replace across multiple files with Perl
#print the result of search-and-replace to the terminal
perl -pe 's/bart/milhouse/g' test.html
#search-and-replace, with backup
#leave the suffix off of -i to overwrite
perl -i.bak -pe 's/bart/milhouse/g' test.html
#echo the number of lines in a file
perl -lne 'END { print $t } @w = /(w+)/g; $t += @w' test.html
#cat file with line numbers
# -p prints $_ each iteration
perl -pe '$_ = "$. = $_"' test.html
# recursive search-and-replace, only on shells that support file globs
perl -i.bak -pe 's{bart}{milhouse}' **/*html
Category: Uncategorized |
Tags: Bash, batch, code, commandline, diamond, edit, editing, files, FileSystem, hacking, one-liners, perl, productivity, regex, replace, search, text, tips, tricks, wrapper
capitalize words
sub wordcaps {
my $line = shift;
$line =~ s/(w)/U$1/g;
return $line;
}