Page 2 of 2

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Fri Jul 08, 2016 12:15 pm
by [-hh]
The "fast LC 6"-version (from above) works of course also with LC 7/8.
[But LC 7/8 needs up to 50% more time than LC 6.]

I hope that you will show us your artwork when finished.

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Fri Jul 08, 2016 6:26 pm
by FourthWorld
With both methods here taking only microseconds the speed difference hardly matters much, but FWIW exploring other ways to solve this lends itself to a very lazy option:

Code: Select all

on mouseUp
  put fld 1 into tHtml
  put 1000 into n
  --
  put the millisecs into t
  repeat n
    put ReformatHtml1(tHtml) into r1
  end repeat
  put the millisecs - t into t1
  --
  put the millisecs into t
  repeat n
    put ReformatHtml2(tHtml) into r2
  end repeat
  put the millisecs - t into t2
  --
  put "Method 1: "& (t1/n)&" ms" &cr \
        & "Method 2: "& (t2/n) &" ms" &cr \
        & "Same result?: "& (r1=r2)
end mouseUp

function ReformatHtml1 pHtml
  put the num of lines of pHtml into n1
  put numToChar(1) into c1
  put numToChar(2) into c2
  replace "<p>" with c1 in pHTml
  replace "</p>" with c2 in pHtml
  set linedel to c1; set itemdel to c2
  put line 1 of pHtml into txt2 --> we start AFTER first "<p>"
  repeat for each line L in (line 2 to -1 of pHtml)
    replace cr with space in item 1 of L
    replace c2 with "</p>" in L
    put "<p>" & L after txt2
  end repeat
  if last char of txt2 = cr then delete last char of txt2
  return txt2
end ReformatHtml1

function ReformatHtml2 pHtml
  replace cr with space in pHtml
  replace "> <" with ">"&cr&"<" in pHtml
  if last char of pHtml = space then delete last char of pHtml
  return pHTml
end ReformatHtml2

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Fri Jul 08, 2016 6:48 pm
by [-hh]
Your code does the same for MariaSole's very special sample input.
But you overlooked the more general objective:

Replace cr by space between each opening "<p>" and closing "</p>".
Nowhere else, everything else should remain the same no matter the chars.


So simply insert a single return around the midth of the first line and/or the last line of her sample input to see your code fail. You don't know where the return you replaced by space was located ...

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Fri Jul 08, 2016 7:07 pm
by FourthWorld
Thanks. Seems I missed a later post; my understand of the desired output was based on her "What I'd like to see" block here:
http://forums.livecode.com/viewtopic.ph ... 79#p144411

Either way, at a few microseconds per run just about any working method discussed in this thread seems quite good.

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Mon Jul 18, 2016 3:07 pm
by Thierry
Mariasole wrote:Grazie [-hh]! :D
Hi Mariasole,

Coming a bit late to the party, being busy on another planet...

Concerning your regex, you jumped into 2 holes:

1) copy/paste a regex from a website to LC won't work all the time.
There are few things to consider doing this...

2) Considering 1) is resolved, then you hit a LC bug.

Anyway, you had your hero ( Hermann) who came to the rescue.

Good luck with your porject,

Thierry

Re: <p>All work and no play makes Jack a dull boy</p> !(=^..

Posted: Mon Jul 18, 2016 6:20 pm
by Mariasole
Hi Thierry!
Merci pour ton épiphanie, je pense que le X sur la fenêtre avec la lumière ne fonctionne plus!
While you were on the road for some kind of planets, fortunately the brave Hermann came to save me!
How would I do without you, my knights! :D
Thank you for signing remembered and ... if you revise the X on the window, you think I'm calling you (if you want, instead of X, I will write the string (?:^((?:X)))) 8)

Un bacio!

Mariasole
(=^..^=)