Why not just strip out tags ya don't need?  Using regex strip out
all "<font*>" and "</font>" and/or the "<b></b>" and "<i></i>"
stuff..  When I first started reading this thread I was thinking along
the lines of real optomizing..  Say ya got:
"<font face='verdana'><b><i>some <font face='verdana'><b>text</b></font>
</i></b></font>"

which should be optomized to:
"<font face='verdana'><b><i>some text</i></b></font>"

This could be a chore, but just ripping out tags..  that would be easy..

Something you could do is look into XMLToObject..  Run that on the
html string and then pull out all the data it spits out..  If ya look into a
"traceObject" you can get an idea on how to traverse what xmlToObject
spits out.

For an example, your "<font face='verdana'><b>hello world</b></font>
<br><i>abc123<br>hi again world<br></i>" after ran through xmlToObject
spits out this...

br: [object Object]
  i: [object Object]
     br: [object Object]
        br: [object Object]
           data: undefined
           attributes: undefined
        data: hi again world        <--
        attributes: undefined
     data: abc123                     <--
     attributes: undefined
  data: null
  attributes: undefined
font: [object Object]
  b: [object Object]
     data: hello world               <--
     attributes: undefined
  data: null
  attributes: undefined
     face: verdana

You could traverse this object to get what ya want..
Using just the data's and br's you'd get:

"hello world<br>abc123<br>hi again world<br>"

We could call this your 10% call...  But let's not..
Let's call this "level 1", or max reduction cuz I'd assume
you'd at least want the <br>'s   but you could replace
<br>'s with spaces and call that the max reduction or
"level 1"..   Now we can build a "level 2" model..  if it's
in a "b" or "i" object, wrap the text with the appropreate
tags..  "level 3" could be to allow levels 1 and 2, and
font tags..  ect..  Also, with this method you could strip
attributes..  like allowing font color changes, but not
the font family..

This is prolly how I'd go about doing what your asking..
All I used was "xmlToObject" and "traceObject" to get
to this point..  You could also rework the xmlToObject
to spit out what you want..  Hope this helps :)







----- Original Message ----- From: "Jayson K Hanes" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Tuesday, January 17, 2006 2:32 PM
Subject: RE: [Flashcoders] efficient htmltext.reduce() function? orsimilaridea?


Say I have this htmltext

"<font face='verdana'><b>hello world</b></font><br><i>abc123<br>hi again
world<br></i>"

And it is being appended with other html lines over time, but no two
lines are the same, nor is there a pattern of <br>'s being a common
separator per 'line'.

I want to be able to execute something like
myHtmlText=myHtmlText.reduce(10);

And have it become something like:

"<i>abc123<br>hi again world<br></i>"

Seeing as that's the lowest amount closest to 10% reduction it could be
trimmed to without breaking the html output when displayed...

If it was:

"hi again world<br></i>"

It wouldn't work as needed.. and would paralyze an htmltext box from
showing anymore text from that point forward.

Even if just a 50% reduction could be worked out easily.. that'd at
least be functional..

Do you see now the dilemma?

-Jayson

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:flashcoders-
[EMAIL PROTECTED] On Behalf Of elibol
Sent: Tuesday, January 17, 2006 2:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] efficient htmltext.reduce() function?
orsimilaridea?

I hate to impose, but my curiousity is forcing me to question: what is
the
reason for html reduction? How does a regular html tag look compared
to a
reduced one? What exactly does the algorithm do?

I apologize for side tracking, I hope you find the answer you're
looking
for
Jayson.

H

On 1/17/06, Jayson K Hanes <[EMAIL PROTECTED]> wrote:
>
> Thanks gunnar.. I've used regex stuff for simple string
manipulation..
> but I can't see how it could be applied to arbitrarily reduce the
length
> of an html string??.. at least.. not without a lot of work?
>
> -Jayson
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
[mailto:flashcoders-
> > [EMAIL PROTECTED] On Behalf Of Gunnar Reinseth
> > Sent: Tuesday, January 17, 2006 4:19 AM
> > To: Flashcoders mailing list
> > Subject: RE: [Flashcoders] efficient htmltext.reduce() function?
or
> > similaridea?
> >
> > You should definetly be looking into regular expressions. The
> following
> > could be wrapped up in a utility class and help build your method:
> >
> > var regex:RegExp = /<.*?>.*?<\/.*?>/g;
> > var str:String = myHtmlTextBox.text; // or wherever you get your
> source
> > text
> > var result:Object = regexp.exec(str);
> > while(result != null) {
> >       trace(result.index + ", " + result);
> >       // Place the result in a new string or array and do whatever
> >       // processing you'd like
> >       result = regex.exec(str);
> > }
> >
> > Useful info:
> > http://www.regular-expressions.info
> > http://livedocs.macromedia.com/labs/1/flex/langref/RegExp.html
> >
> > cheers,
> > gunnar
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
Jayson
> K
> > Hanes
> > Sent: 17. januar 2006 01:54
> > To: Flashcoders mailing list
> > Subject: [Flashcoders] efficient htmltext.reduce() function? or
> similar
> > idea?
> >
> > Does anyone have any divine wisdom for safely and efficiently
> "reducing"
> > an htmltext string down in size?
> >
> > I've been using old code for a while that simply loops looking for
> html
> > tags.. and if it's a known "paired" tag set (like font), looks for
the
> > closing tag, and then, substring's from that point onward (thus
> removing
> > everything ahead of the last complete tag set), and effectively
> reducing
> > the overall size of the htmltext so that it doesn't forever build
in
> > size, and in turn bring flash to its knees if the string gets too
> long.
> >
> > The problem with this is its slow... and risky..
> >
> > sometimes.. it fails to match a paired set.. and the output into
the
> > flash textbox breaks -- that is -- no more appended text will be
seen
> > from that point onward.. and the box appears "Dead" because of
broken
> > tags.
> >
> > Ideally for me at least.. a function could be called such as:
> >
> > myHtmlTextBox=myHtmlTextBox.reduce(10);
> >
> > whereby 10 is used such that the result has about 90% remaining
(which
> > is obviously a challenge because of the variable lengths of tag
> > groupings among formatted html..)
> >
> > Any ideas? This is a hard topic to google and search the archives
> with..
> >
> >
> > Thanks!
> >
> > -Jayson
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to