Close htmlText tag function - usefull if you tween htmlText


/ Published in: ActionScript 3
Save to your folder(s)

Sometimes you need to tween htmlText with Tweener and Text Shortcuts :)


Copy this code and paste it in your HTML
  1. public static function close_dangling_tags(str:String):String {
  2. var open_tags:Array = str.match(/<[a-z]+( .*)?(?!\/)>/img).map(function(e:*,i:int,arr:Array):String{return e.substr(1,e.length-2) });
  3. var closed_tags:Array = str.match(/<\/[a-z]+>/img).map(function(e:*,i:int,arr:Array):String{return e.substr(1,e.length-2) });
  4. if (open_tags.length == closed_tags.length){
  5. return str;
  6. }
  7. var tag_heap:Array = new Array();
  8. for each(var tag:String in open_tags) {
  9. tag_heap.push(tag);
  10. while (tag_heap.length && closed_tags.length && ArrayTools.last(tag_heap) == ArrayTools.first(closed_tags)) {
  11. tag_heap.pop();
  12. closed_tags.shift();
  13. }
  14. }
  15. return str+tag_heap.reverse().map(function(e:*,i:int,arr:Array):String{return '</'+e+'>'}).join('');
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.