Skip to content

Commit

Permalink
Added txttrim, txtupper, txtlower
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed May 9, 2011
1 parent 77fce73 commit 3de4b5f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion string.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ This software can be used free of charge and the source code is available under
http://creativecommons.org/licenses/by/3.0/
*/

var krpanoplugin=function(){var c=this,f=null,d=null;c.registerplugin=function(i,h,j){f=i;d=j;if(f.version<"1.0.8.14"||f.build<"2011-03-30"){f.trace(3,"string plugin - too old krpano version (min. 1.0.8.14)");return}d.txtlength=a;d.txtchunk=g;d.txtfind=b;d.txtreplace=e};c.unloadplugin=function(){d=null;f=null};function a(i,h){f.set(i,h.length)}function g(k,h,j,i){f.set(k,h.substr(j,i))}function b(j,h,i){f.set(j,h.indexOf(i))}function e(m,j,l,i,h){var k=new RegExp(l,h);f.set(m,j.replace(k,i))}};
var krpanoplugin=function(){var h=this,g=null,e=null;h.registerplugin=function(l,k,m){g=l;e=m;if(g.version<"1.0.8.14"||g.build<"2011-03-30"){g.trace(3,"string plugin - too old krpano version (min. 1.0.8.14)");return}e.txtlength=i;e.txtchunk=f;e.txtfind=d;e.txtreplace=a;e.txttrim=j;e.txtlower=b;e.txtupper=c};h.unloadplugin=function(){e=null;g=null};function i(l,k){g.set(l,k.length)}function f(n,k,m,l){g.set(n,k.substr(m,l))}function d(m,k,l){g.set(m,k.indexOf(l))}function a(p,m,o,l,k){var n=new RegExp(o,k);g.set(p,m.replace(n,l))}function j(m,k){var l=new RegExp(find,flags);g.set(m,((k!=undefined)?k:g.get(m)).replace(l,""))}function b(l,k){g.set(l,((k!=undefined)?k:g.get(l)).toLowerCase())}function c(l,k){g.set(l,((k!=undefined)?k:g.get(l)).toUpperCase())}};
Binary file modified string.swf
Binary file not shown.
6 changes: 6 additions & 0 deletions string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ A krpano plugin that provides a number of string manipulation methods:
Sets destVar to the position of 'find' in 'text', or -1 if the text is not found
* `txtreplace(destVar, text, find, replace, flags)`
Sets destVar to a copy of 'text', replacing 'find' with 'replace'. The optional 'flags' argument can be used to set flags for the internal regular expression pattern (and defaults to ''gi' for a global, case-insensitive replace).
* `txttrim(destVar, text)`
Sets destVar to 'text' without leading and trailing whitespace. If the second argument is omitted, the method alters the current contents of destVar instead.
* `txtupper(destVar, text)`
Sets destVar to an uppercase version of 'text'. If the second argument is omitted, the method alters the current contents of destVar instead.
* `txtlower(destVar, text)`
Sets destVar to a lowercase version of 'text'. If the second argument is omitted, the method alters the current contents of destVar instead.

These methods are meant to complement the builtin txtadd method to concatenate strings. Note that all parameters except destVar are taken as literals. If you want to pass the value of a variable or property, you have to use the get() function.

Expand Down
6 changes: 6 additions & 0 deletions string/plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ <h2><a name="attributes" href="#attributes" class="selflink">Plugin Methods</a><
<dd>Sets destVar to the position of 'find' in 'text', or -1 if the text is not found.</dd>
<dt><a name="txtreplace" href="#txtreplace" class="selflink">txtreplace</a>(destVar, text, find, replace, flags)</dt>
<dd>Sets destVar to a copy of 'text', replacing 'find' with 'replace'. The optional 'flags' argument can be used to set flags for the internal regular expression pattern (and defaults to ''gi' for a global, case-insensitive replace).</dd>
<dt><a name="txttrim" href="#txttrim" class="selflink">txttrim</a>(destVar, text)</dt>
<dd>Sets destVar to 'text' without leading and trailing whitespace. If the second argument is omitted, the method alters the current contents of destVar instead.</dd>
<dt><a name="txtupper" href="#txtupper" class="selflink">txtupper</a>(destVar, text)</dt>
<dd>Sets destVar to a uppercase version of 'text'. If the second argument is omitted, the method alters the current contents of destVar instead.</dd>
<dt><a name="txtlower" href="#txtlower" class="selflink">txtlower</a>(destVar, text)</dt>
<dd>Sets destVar to a lowercase version of 'text'. If the second argument is omitted, the method alters the current contents of destVar instead.</dd>
</dl>
</div>
<div class="paragraph">
Expand Down
17 changes: 16 additions & 1 deletion string/source/string.as
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ package {
this.plugin_object.registerattribute("txtchunk", this.interface_substr);
this.plugin_object.registerattribute("txtfind", this.interface_indexof);
this.plugin_object.registerattribute("txtreplace", this.interface_replace);

this.plugin_object.registerattribute("txttrim", this.interface_trim);
this.plugin_object.registerattribute("txtlower", this.interface_lowercase);
this.plugin_object.registerattribute("txtupper", this.interface_uppercase);

return;
}

Expand All @@ -100,5 +103,17 @@ package {
var pattern:RegExp = new RegExp(find, flags);
this.krpano.set(varname, subject.replace(pattern, replace) );
}

public function interface_trim(varname:String = "", subject:String = null) : void {
var pattern:RegExp = /^[\s|\t|\n]+|[\s|\t|\n]+$/g;
this.krpano.set(varname, ((subject!=null)?subject:this.krpano.get(varname)).replace(pattern, "") );
}

public function interface_lowercase(varname:String = "", subject:String = null) : void {
this.krpano.set(varname, ((subject!=null)?subject:this.krpano.get(varname)).toLowerCase() );
}
public function interface_uppercase(varname:String = "", subject:String = null) : void {
this.krpano.set(varname, ((subject!=null)?subject:this.krpano.get(varname)).toUpperCase() );
}
}
}
21 changes: 21 additions & 0 deletions string/source/string.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var krpanoplugin = function()
plugin.txtchunk = txtchunk;
plugin.txtfind = txtfind;
plugin.txtreplace = txtreplace;
plugin.txttrim = txttrim;
plugin.txtlower = txtlowercase;
plugin.txtupper = txtuppercase;
}


Expand Down Expand Up @@ -69,4 +72,22 @@ var krpanoplugin = function()
krpano.set(varName, subject.replace(pattern, replace) );
}

function txttrim(varName, subject)
{
// trim leading and trailing whitespace
var pattern = new RegExp(find, flags);
krpano.set(varName, ((subject!=undefined)?subject:krpano.get(varName)).replace(pattern, "") );
}

function txtlowercase(varName, subject)
{
// make subject lowercase
krpano.set(varName, ((subject!=undefined)?subject:krpano.get(varName)).toLowerCase() );
}

function txtuppercase(varName, subject)
{
// make subject lowercase
krpano.set(varName, ((subject!=undefined)?subject:krpano.get(varName)).toUpperCase() );
}
}

0 comments on commit 3de4b5f

Please sign in to comment.